Hi all super google analytics rockstars,
How can I get the google analytics global function name, when it's renamed from the install script.
E.g.:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','__gaTracker');
I want to get the "__gaTracker" function name that was renamed (or something else).
Just setting the context, we have a script that runs on client's websites and sends events to google analytics. Sometimes they have the "ga" function and we call ga('send'...)
but if they rename it, we need to call (e.g.) __gaTracker('send'...)
.
Is there any way to get the global function that was renamed.
Thanks in advance !!!!
Google recommends to use both "GoogleAnalyticsObject" and "ga" variables for GA tracker lookup:
// © Google Inc.
// This function works even if the site
// has customized the ga global identifier.
var ga = window[window['GoogleAnalyticsObject'] || 'ga'];
Full example on developers.google.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With