如何检查Matomo是否已加载或可能被阻止?

问题描述 投票:0回答:1

我正在寻找JavaScript变量,函数或要检查的东西,如果Matomo跟踪脚本未成功加载或可能被阻止(被Tracker-或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脚本的存在/状态?

matomo
1个回答
0
投票

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

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

我只是在这里留待以后参考。

© www.soinside.com 2019 - 2024. All rights reserved.