How do I get the global name of a Google Analytics function?
Hello to all Google Analytics Rockstars superstars,
How do I get the global Google Analytics function name when renamed from an install script.
For example:
(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 function name "__gaTracker" that has been renamed (or whatever).
By simply setting the context, we have a script that runs on client websites and sends events to Google Analytics. Sometimes they have a "ga" function and we call ga('send'...)
, but if they rename it we need to call (for example) __gaTracker('send'...)
.
Is there a way to get the global function that has been renamed.
Thanks in advance!!!!
source to share
It can be accessed via window['GoogleAnalyticsObject'];
, it will give you the name of the variable GLOBAL
. Hope this is what you asked for.
just execute F12and paste your code here in the console, you will see the global SO function name,
console.log(window['GoogleAnalyticsObject'];) // ouputs ga
source to share