【问题标题】:How to check if Matomo was loaded or possibly blocked?如何检查 Matomo 是否已加载或可能被阻止?
【发布时间】:2020-09-05 06:54:12
【问题描述】:

我正在寻找一个 JavaScript 变量、函数或要检查的东西, 如果 Matomo 跟踪脚本未成功加载或可能被阻止(被 Tracker 或 Ad-blocker 浏览器扩展、Pi-hole 等)。

我已经有类似的谷歌分析,我想扩展:

const ehi_ga = window[window['GoogleAnalyticsObject'] || 'ga'];
if (typeof ehi_ga !== 'function' || ehi_ga.loaded !== true || !ehi_ga.create) {
    return false;
}

如何扩展它,以检查 Matomo 脚本的存在/状态?

【问题讨论】:

    标签: javascript matomo


    【解决方案1】:

    我现在使用的是以下内容:

    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;
    }
    

    我只是把它留在这里以备将来参考。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-14
      • 2012-03-04
      • 1970-01-01
      • 1970-01-01
      • 2021-07-20
      • 2012-07-03
      • 1970-01-01
      • 2013-07-17
      相关资源
      最近更新 更多