我正在寻找一个JavaScript变量、函数或其他要检查的东西,如果Matomo跟踪脚本没有成功加载或可能被阻止(通过Tracker- or Ad-blocker浏览器扩展,Pi-hole等)。
我已经有了类似的Google Analytics,我想扩展一下:
const ehi_ga = window[window['GoogleAnalyticsObject'] || 'ga'];
if (typeof ehi_ga !== 'function' || ehi_ga.loaded !== true || !ehi_ga.create) {
return false;
}我如何扩展它,以检查Matomo脚本的存在/状态?
发布于 2020-05-20 14:22:04
我现在使用的是以下内容:
const ehi_ga = window[window['GoogleAnalyticsObject'] || 'ga'];
const gaProbablyNotLoaded = typeof ehi_ga !== 'function' || ehi_ga.loaded !== true || !ehi_ga.create;
const matomo = window['Matomo'];
const matomoProbablyNotLoaded = typeof matomo !== 'object' || matomo.initialized !== true || !matomo.trigger;
if (gaProbablyNotLoaded && matomoProbablyNotLoaded) {
return false;
}我只是把这个留在这里,以备将来参考。
https://stackoverflow.com/questions/61887146
复制相似问题