Last active
February 21, 2023 07:55
-
-
Save walkergv/1ba5021572964197f395 to your computer and use it in GitHub Desktop.
Adding GTM (Google Tag Manager) Container Code using Tampermonkey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
//@name Name of your script | |
//@namespace http://use.i.E.your.homepage/ | |
//@version 0.1 | |
//@description Inject GTM bootstrap on my website | |
//@include http://www.domain.com/* [wildcard url where GTM should inject the code] | |
// ==/UserScript== | |
// Google Tag Manager | |
setTimeout("(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':"+ | |
"new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],"+ | |
"j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.src="+ | |
"'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);"+ | |
"})(window,document,'script','dataLayer','YOUR_CONATINER_ID_GOES_HERE');"+ | |
"console.info('GTM injected');",500); | |
// End Google Tag Manager |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works extremely well, I have contemplated forking it for other tag managers (Adobe DTM , Tealium IQ and Adobe Launch eventually) if anyone would like to assist me.
Alternative approaches: