Skip to content

Load Google Tag Manager script as asynchronous#121

Open
aduth wants to merge 1 commit intodigital-analytics-program:masterfrom
aduth:aduth-async-tag-manager-script
Open

Load Google Tag Manager script as asynchronous#121
aduth wants to merge 1 commit intodigital-analytics-program:masterfrom
aduth:aduth-async-tag-manager-script

Conversation

@aduth
Copy link

@aduth aduth commented Aug 16, 2024

This pull request proposes to create the Google Tag Manager script using the async attribute on the script element` (see MDN reference).

The DAP script appends a Google Tag Manager script to the page, but it does so without marking the script as asynchronous. This causes the script to block the main thread, impacting user-facing performance.

This reflects in performance audits of our site, which flag Google Tag Manager as blocking main thread for upward of 300ms.

Related resource: https://web.dev/articles/optimizing-content-efficiency-loading-third-party-javascript#async-defer

Google's documentation for Google Tag Manager also uses async in its own default script snippet examples:

Screenshot 2024-08-16 at 9 31 58 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant