Snippet injection wishlist

It would be great to be able to specify on which environments the snippet injection should take place.
I for example don’t want/need analytics on my test deploys.

1 Like

I’m using Cloudflare as DNS right now, and I have managed to set up TLSA, and extend DS and DNSKEY nicely for both my domain and my www subdomain. It would be nice if Netlify DNS had these options, and maybe PGP too. To make our websites safer.
Also, a more intuitive and editable snippet injection feature, like editing already existing snippets, rearranging them, so it’s not just one big snippet for the head and the body if needed. Maybe not just adding it before the end of the section, but also right affter the beginning.


On the topic of snippet injection: I’d really love to be able to edit my snippets too, instead of having to delete existing ones and adding new ones!


Also, snippets should keep “formatting”, like how you use tabs/spaces to maintain a pretty code. The first line always ignores the tabs/spaces, and there is no break after the last line, closing of head and body just goes right after, which can be very unpleasant when you browse the source code in the browser, especially if it’s a long link to a CSS or JS.
It’s not a big deal, but it triggers my faux ocd. :smiley:

You can conditionally set identifiers to help keep your data clean, as demonstrated in this article: .

Not a perfect solution but maybe a useful workaround, to key off of contexts to change config :slight_smile:

I don’t use split testing, can I still use this? And this is in addition to the normal analytics script? Won’t the normal analytics script also set a pageview then?

Also not sure what this Branch syntax does.

The docs could definitely be improved here.

Snippet Injection(s) at the start of the <body> Tag

As indicated in the “Google Tag Manager container snippet” section of Google’s Verify site ownership page, the <noscript> portion of the Tag Manager code is to be placed “immediately after the opening <body> tag.”

(I realize that Netlify offers a paid service for Analytics, however, we are using in Google’s solution across the entire University. Therefore, we are unable to use Netlify’s Analytics as a replacement.)

One of the stated objectives of the Snippet Injection feature is to prevent “[pollution of] the source code”, which is fantastic. However, the only options currently offered are “before the closing </head> tag [and] before the closing </body> tag.” This limitation prevents proper use of the Google Tag Manager code.

FR: Please offer the ability to inject code immediately after the opening <body> tag.

It would be marvelous if you could control Snippets from the netlify.toml file. For me, this would be much more convenient, and it would all editing instead of the current delete-and-replace.

The above are great and would be hugely helpful. Unfortunately, I’m stuck in Google Analytics world too as we also use Google Ads and such. For the same reason, I’d love to be able to control snippet injection by branch. I have a branch we use as a staging branch to check things out before making public. I’d really like to not have Google Tag Manager on these branches.

Hi, @_Rob, this is only a workaround (not a solution) but you might try linking the staging branches to a different site. You can link the same repo to multiple sites.

The production branch could be its own site and the other branches can exist on a different site (a different subdomain of Then only use the snippet injection on the production site.

You could still have a staging/test branches and without snippet injection there.

Again, it’s not a solution but this might be a better workflow until something else becomes available.