检查Google Analytics或Universal Analytics是否已安装? [英] Check if Google Analytics or Universal Analytics is installed?
问题描述
我试图通过javascript来确定Google Analytics或Universal Analytics是否已加载。
有些客户仍然使用旧的Google Analytics,我们想要推出一个收集数据的JavaScript。因此,我需要为这两个版本编写代码,以确保它能够被跟踪,无论它是正常的还是通用版本的分析。
Classic GA使用_gaq对象,而UA使用ga对象,因此您可以检查是否存在这些
if(_gaq){
//使用经典GA;做任何
}
或
if(ga){
// using UA;做任何
}
希望这会有所帮助。
I am trying, through javascript, to identify if Google Analytics or Universal Analytics is loaded.
Some clients still use the old Google Analytics and we want to roll out a javascript that collects data. So i then need to write code for both versions to make sure it gets tracked regardless if its the normal or universal version of analytics.
Classic GA uses the "_gaq" object, and UA uses the "ga" object, so you could check for the existence of either of those
if (_gaq) {
// using classic GA; do whatever
}
or
if (ga) {
// using UA; do whatever
}
Hope this helps.
这篇关于检查Google Analytics或Universal Analytics是否已安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!