How to add Facebook domain verification file or meta tag in Sanity?

31 replies
Last updated: Jun 10, 2022
hello everyone, i need to verify my domain to use the facebook graph api as the doc says https://www.facebook.com/business/help/321167023127050 . I need to either add a file at the root of my projet to be publicly visible or add a meta tag or add a txt record.I didnt use the sanity ui i have no idea what i can customize other than the schemas and some small stuff.
How can i achieve this ? thank you
AI Update

The solution depends on where your Sanity Studio is hosted. There are two main scenarios:

If You're Self-Hosting Your Studio

If you've deployed your Studio to your own domain (using sanity build to create static files and hosting on Vercel, Netlify, or another platform), you have full control over the domain and can use any of Facebook's verification methods:

Option 1: Add HTML file - Place the verification HTML file in your Studio's static folder before building. Files in this folder get copied to the root of your build output.

Option 2: Add meta tag - You can customize the HTML document by creating a custom index.html template in your Studio project, though this requires ejecting from the default build process.

Option 3: DNS TXT record (easiest) - Since you control the domain, just add the TXT record through your DNS provider. This doesn't require any changes to your Studio code.

If You're Using Sanity-Hosted Studio (*.sanity.studio)

If your Studio is hosted on Sanity's infrastructure at a yourproject.sanity.studio subdomain, you don't have direct control to add verification files or meta tags to that domain.

Best solution: Verify a different domain that you control (like your Next.js frontend) and make Facebook API calls from there instead. You can:

  1. Verify your frontend domain with Facebook
  2. Create an API route in your frontend (e.g., /api/facebook-publish)
  3. Have your Studio custom action POST to your API route
  4. Your API route forwards the request to Facebook's Graph API

This keeps Facebook credentials secure on your server and gives you a verified domain for the Graph API.

Which Hosting Are You Using?

If you're unsure, check your Studio URL:

  • yourproject.sanity.studio = Sanity-hosted (limited customization)
  • Your own domain = Self-hosted (full control)

For self-hosted Studios, the sanity build command creates static files you can deploy anywhere, giving you full control over the hosting environment and the ability to add verification files, meta tags, or DNS records as needed.

Show original thread
31 replies
Do you want to do that for your website or your self-hosted studio?
i need it for the self hosted studio since i use a custom publishing action button to publish from the sanity studio to a facebook page
What is the URL of your Studio? Is it on *.sanity.studio or on your own domain?
its on sanity.studio
Alright. So a TXT record is not going to be possible, that’s for sure, since you don’t host the studio yourself. Same for the file, same reason.
Your only chance is a meta tag. If it can be added dynamically with JavaScript — which I doubt — then you could inject it yourself, but I’m pretty sure it needs to be there on the server response.
What does your custom action does exactly?
it’s an http post method with a token and a payload
wich use sanity fields to populate the payload
And this request goes to Facebook servers?
I don’t think you’ll be able to verify your Studio since it’s not your domain. I guess you could self-host the Studio wherever you want, but that’s a pain. Is there a way around it? Can’t you pass a specific header to your request or something?
it says i need to set ownership_permissions: { can_customize_link_posts: true,
},
but it doesnt work and as i went further for informations i saw that the new requirement isa veryfied domain
Another option is to do a POST request to an API route on your own site (which you host and can verify), and then do the Facebook request from there.
sure
but i lose the the ability to use sanity to use the action button
How so?
oh yeah
i misunderstood
yeah i think i can do that
Alright. 😊
Do you use Next.js or something for your site?
I use nextjs
Pretty convenient then! Make your action ping a specific API route on your Next.js site, and have that server-side API handler ping Facebook.
Yeah !
I guess the request will take longer but It should work
If it’s done only on publication, it should be marginal. It’s also not a critical request as far as I understand.
Ok I'll try this implementation and get back to you
Thank you very much anyway 😃
Cheers!

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?