Skip to content

Instantly share code, notes, and snippets.

@thyngster
Last active May 2, 2024 12:39
Show Gist options
  • Save thyngster/02b1f0ebce7ba86f1cf3ce2d423febb5 to your computer and use it in GitHub Desktop.
Save thyngster/02b1f0ebce7ba86f1cf3ce2d423febb5 to your computer and use it in GitHub Desktop.
Small function to check if any GA4 Container has been currently been loaded.
// DV - 2022 - ES5
// Check if GA4 has been loaded
var getLoadedGA4Containers = function() {
return Object.keys(
window.google_tag_data &&
window.google_tag_data.tidr &&
window.google_tag_data.tidr.container || {}
).filter(function(e){ return e.startsWith('G-') })
}
//ES6 Version
const getLoadedGA4Containers = () => {
return Object.keys(
window.google_tag_data?.tidr?.container || {}).filter(e => e.startsWith('G-')
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment