Disable Snippet Injection by branch?

I just migrated some of my code over to snippet injection to help prevent my local builds a hugo site sending bad data through Google Anayltics. I did this as one would expect, by adding my Google tag manager code to the appropriate snippet injection.

I am, however, still seeing the tags being fired on my staging branch subdomain.

Is there a way via the toml file to disable this? Or can I edit the toml file on the production branch to only add this code on the productions branch?

Hey @_Rob,

Appreciate you taking the time to write in. Unfortunately, it’s not something that I can recall being able to do. However, you may wish to chime in on this feature request!

Thanks for the reply.

I couldn’t find anything either on a feature like this. I’ll have to figure out some other way to keep this only on the production site.

I’ll be sure to drop this in feature requests too.


Hey Rob,

You could make use of snippet injection to… sort of accomplish this! It’s the closest we’re gonna get at present. Hope it helps!

(While what Scott linked is “about” split testing - the pattern should work for you in doing branch-specific things via snippet)

1 Like

Hmm, didn’t think of that approach… I’ll poke around with this a bit , thanks