Skip to content

Instantly share code, notes, and snippets.

@ricealexander
Last active February 14, 2020 20:07
Show Gist options
  • Save ricealexander/91c4d235dfb6e8c36fda83d8f7a74cfd to your computer and use it in GitHub Desktop.
Save ricealexander/91c4d235dfb6e8c36fda83d8f7a74cfd to your computer and use it in GitHub Desktop.
Bundle Analytics
(function(){
var scriptOrder = 0
function loadScript (src) {
// create script
var script = document.createElement("script")
script.async = true
script.src = src
// insert script into the top of the document
document.querySelectorAll("script")[scriptOrder]
.insertAdjacentElement("beforebegin", script)
// increment scriptOrder so scripts are located in the order they are run
scriptOrder += 1
}
// Google Analytics
window.dataLayer = window.dataLayer || []
function gtag () {
dataLayer.push(arguments)
}
gtag("js", new Date())
gtag("config", "UA-2139719-1")
loadScript("https://www.googletagmanager.com/gtag/js?id=UA-2139719-1")
// Google Tag Manager
// same dataLayer is used as in Google Analytics
window.dataLayer.push({
"gtm.start": Date.now(),
event: "gtm.js",
})
loadScript("https://www.googletagmanager.com/gtm.js?id=GTM-KLPKLWL&l=dataLayer")
// Chartbeat Analytics
var _sf_async_config = {
uid: 33583,
domain: window.location.hostname,
useCanonical: true,
}
loadScript("https://static.chartbeat.com/js/chartbeat.js")
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment