{"id":753,"date":"2022-06-21T13:30:00","date_gmt":"2022-06-21T17:30:00","guid":{"rendered":"https:\/\/www.digitaldatatactics.com\/?p=753"},"modified":"2023-04-04T17:14:39","modified_gmt":"2023-04-04T21:14:39","slug":"tmsbp-dedupe","status":"publish","type":"post","link":"https:\/\/www.digitaldatatactics.com\/index.php\/2022\/06\/21\/tmsbp-dedupe\/","title":{"rendered":"TMS Best Practices: Deduplicate scripts and events"},"content":{"rendered":"\n<p><strong>UPDATE, April 2023: To my dismay, I&#8217;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&#8230; for every &#8220;config&#8221; you pass, Google will load a new GTAG library for you, adding weight to your site. So, thanks for that, Google. <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2023\/04\/image.png\"><img loading=\"lazy\" decoding=\"async\" width=\"515\" height=\"196\" src=\"https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2023\/04\/image.png\" alt=\"\" class=\"wp-image-918\" srcset=\"https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2023\/04\/image.png 515w, https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2023\/04\/image-300x114.png 300w\" sizes=\"(max-width: 515px) 100vw, 515px\" \/><\/a><\/figure>\n\n\n\n<p>This is a &#8220;low hanging fruit&#8221; best practice, but one that most companies could gain from: consolidate tags from the same vendor. <strong>Especially<\/strong> if they load an external JavaScript file. For instance, if I&#8217;m deploying both an Adwords GTAG and a Doubleclick GTAG, I might paste them both as custom code:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2022\/06\/image-37.png\"><img loading=\"lazy\" decoding=\"async\" width=\"631\" height=\"362\" src=\"https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2022\/06\/image-37.png\" alt=\"\" class=\"wp-image-800\" srcset=\"https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2022\/06\/image-37.png 631w, https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2022\/06\/image-37-300x172.png 300w\" sizes=\"(max-width: 631px) 100vw, 631px\" \/><\/a><\/figure>\n\n\n\n<p>This means that &#8220;https:\/\/www.googletagmanager.com\/gtag\/js&#8221; file loads twice. It&#8217;s a 40 KB file, with no benefit for loading multiple times. <\/p>\n\n\n\n<p>This code accomplishes the same thing, minus 40 KB of dead weight:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2022\/06\/image-35.png\"><img loading=\"lazy\" decoding=\"async\" width=\"639\" height=\"200\" src=\"https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2022\/06\/image-35.png\" alt=\"\" class=\"wp-image-798\" srcset=\"https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2022\/06\/image-35.png 639w, https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2022\/06\/image-35-300x94.png 300w\" sizes=\"(max-width: 639px) 100vw, 639px\" \/><\/a><\/figure>\n\n\n\n<p>You can take it a step further and consolidate events, too- I don&#8217;t need to fire a conversion event twice, I can just add multiple destinations to my <em>send_to<\/em> variable:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2022\/06\/image-38.png\"><img loading=\"lazy\" decoding=\"async\" width=\"631\" height=\"314\" src=\"https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2022\/06\/image-38.png\" alt=\"\" class=\"wp-image-801\" srcset=\"https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2022\/06\/image-38.png 631w, https:\/\/www.digitaldatatactics.com\/wp\/wp-content\/uploads\/2022\/06\/image-38-300x149.png 300w\" sizes=\"(max-width: 631px) 100vw, 631px\" \/><\/a><\/figure>\n\n\n\n<p>This tip isn&#8217;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&#8217;t need to be repeated. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>UPDATE, April 2023: To my dismay, I&#8217;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&#8230; for every &#8220;config&#8221; you pass, Google will load a &#8230; <a title=\"TMS Best Practices: Deduplicate scripts and events\" class=\"read-more\" href=\"https:\/\/www.digitaldatatactics.com\/index.php\/2022\/06\/21\/tmsbp-dedupe\/\" aria-label=\"Read more about TMS Best Practices: Deduplicate scripts and events\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"_links":{"self":[{"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/posts\/753"}],"collection":[{"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/comments?post=753"}],"version-history":[{"count":6,"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/posts\/753\/revisions"}],"predecessor-version":[{"id":919,"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/posts\/753\/revisions\/919"}],"wp:attachment":[{"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/media?parent=753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/categories?post=753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.digitaldatatactics.com\/index.php\/wp-json\/wp\/v2\/tags?post=753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}