Last active
May 2, 2024 12:39
-
-
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.
This file contains hidden or 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
// 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