TMS Best Practices: Deduplicate scripts and events

UPDATE, April 2023: To my dismay, I’ve learned that my understanding of GTAG was wrong, therefore much of this post is wrong. I still stand by the statement that you should try to remove duplicate code and libraries where possible, but in the case of GTAG… for every “config” you pass, Google will load a new GTAG library for you, adding weight to your site. So, thanks for that, Google.

This is a “low hanging fruit” best practice, but one that most companies could gain from: consolidate tags from the same vendor. Especially if they load an external JavaScript file. For instance, if I’m deploying both an Adwords GTAG and a Doubleclick GTAG, I might paste them both as custom code:

This means that “” file loads twice. It’s a 40 KB file, with no benefit for loading multiple times.

This code accomplishes the same thing, minus 40 KB of dead weight:

You can take it a step further and consolidate events, too- I don’t need to fire a conversion event twice, I can just add multiple destinations to my send_to variable:

This tip isn’t specific to gtag, though that is one of the tags that I see duplicated the most. Anytime you are deploying two tags from the same vendor on a page, odds are there is some part of that code that doesn’t need to be repeated.

Leave a Reply

Your email address will not be published. Required fields are marked *