[英]How can I reliably check for Google Analytics?
It used to be so simple - this was all that was needed to ensure you could go ahead and track a user's click or whatever: 它曾经是如此简单-这就是确保您可以继续跟踪用户点击或其他任何操作所需的全部操作:
if ('ga' in window && window.ga !== undefined && typeof window.ga === 'function') {
...
Now, Firefox's 'tracking protection' is here, and that doesn't work. 现在,Firefox的“跟踪保护”就在这里,这是行不通的。 Why?
为什么? Well, even though the Firefox JS console claims
好吧,即使Firefox JS控制台声称
The resource at " https://www.google-analytics.com/analytics.js " was blocked because tracking protection is enabled.
由于启用了跟踪保护,因此“ https://www.google-analytics.com/analytics.js ”上的资源已被阻止。
The 'if' test above still returns true. 上面的'if'测试仍然返回true。 So, I ask you, how can I reliably check if Google Analytics is available?
因此,请问您如何可靠地检查Google Analytics(分析)是否可用?
One option would be to check that the GA tracker has been created: 一种选择是检查是否已创建GA跟踪器:
ga(function() {
// Logs an array of all tracker objects.
console.log(ga.getAll());
});
(cf. getAll() method ) (参见getAll()方法 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.