Published: July 29, 2021
Tags are snippets of third-party code that are inserted into a site, typically with a tag manager. Tags are most commonly used for marketing and analytics.
The performance impact of tags and tag managers varies wildly across sites. Tag managers can be compared to an envelope: the tag manager provides a vessel, but what you fill it with and how you use it is mostly up to you.
Here, we discuss techniques for optimizing tags and tag managers for performance and Core Web Vitals. Although this document references Google Tag Manager, many of the ideas discussed are applicable to other tag managers.
Impact on Core Web Vitals
Tag Managers can often impact your Core Web Vitals indirectly by using up resources needed to load your page quickly and keep it responsive. Bandwidth can be spent downloading the tag manager JavaScript for your sites, or the subsequent calls this makes. CPU time on the main thread can be spent evaluating and executing JavaScript contained within the tag manager and the tags.
Largest Contentful Paint (LCP) is vulnerable to bandwidth contention during the critical page load time. Additionally, blocking the main thread can delay the LCP render time.
Cumulative Layout Shift (CLS) can be impacted, either by delaying loading critical resources before the first render, or by tag managers injecting content into the page.
Interaction to Next Paint (INP) is susceptible to CPU contention on the main thread, and we have seen a correlation between the size of tag managers and poorer INP scores.
Choose the right tag type
The impact of tags on performance varies by tag type. Generally speaking, image tags ("pixels") are the most performant, followed by custom templates, and lastly, custom HTML tags. Vendor tags vary depending on the functionality they allow.
Keep in mind that how you use a tag greatly influences its performance impact. "Pixels" are highly performant largely because the nature of this tag type imposes tight restrictions on how they can be used; custom HTML tags aren't necessarily always bad for performance, but due to the level of freedom they offer users, they can be easy to misuse in a way that is bad for performance.
When thinking about tags, keep scale in mind: the performance impact of any single tag may be negligible—but can become significant when tens or hundreds of tags are used on the same page.
Not all scripts should be loaded with a tag manager
Tag managers aren't typically the best way to load resources that implement immediate visual or functional aspects of the user experience, such as cookie notices, hero images, or site features. Using a tag manager to load these resources typically delays their delivery. This is bad for the user experience and can also increase metrics, such as LCP and CLS.
In addition, some users block tag managers. Using a tag manager to implement UX features may result in a broken website for some of your users.
Be careful with Custom HTML tags
Custom HTML
tags
have been around for many years and are heavily used on most sites. Custom HTML
tags allow you to enter your own code with few restrictions as, despite the name,
the main use of this tag is to add custom <script> elements to a page.
Custom HTML tags can be used in a wide variety of ways and their performance impact varies significantly. When measuring the performance of your site, be aware that most tools attribute the performance impact of a Custom HTML tag to the tag manager that injected it—rather than the tag itself.