Skip to content

Instantly share code, notes, and snippets.

@davestewart
Created July 8, 2018 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davestewart/f88e5e0d57882179bc19724a0e2c1718 to your computer and use it in GitHub Desktop.
Save davestewart/f88e5e0d57882179bc19724a0e2c1718 to your computer and use it in GitHub Desktop.
Google Analytics - single file include
(function track (id) {
// prepare data
window.dataLayer = window.dataLayer || []
function gtag () { dataLayer.push(arguments) }
gtag('js', new Date())
gtag('config', id)
// load analytics
var script = document.createElement('script')
script.src = 'https://www.googletagmanager.com/gtag/js?id=' + id
script.type = 'text/javascript'
script.async = true
document.head.appendChild(script)
}('UA-XXXXXX-YY'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment