Skip to content

Instantly share code, notes, and snippets.

@walkergv
Last active August 29, 2015 14:01
Show Gist options
  • Save walkergv/a6a60c0e181b24b55423 to your computer and use it in GitHub Desktop.
Save walkergv/a6a60c0e181b24b55423 to your computer and use it in GitHub Desktop.
google tag manager (gtm) userscript for tampermokey
// ==UserScript==
// @name Google Tag Manager Test Script
// @namespace http://www.tikodigital.com/
// @version 0.1
// @description Code to Run Google Tag Manager Client Side
// @include *domain.com*
// @copyright 2014 Tiko Digital
// ==/UserScript==
var actualCode = '(' + function() {
// All code is executed in a local scope.
// To overwrite a global variable, prefix `window`:
(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.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');
} + ')();';
var script = document.createElement('script');
script.textContent = actualCode;
(document.head||document.documentElement).appendChild(script);
script.parentNode.removeChild(script);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment