bitandblack/matomooptout

Matomo (Piwik) 中的 AJAX 自定义 OptOut。无需 iframe。

安装: 100

依赖项: 0

建议者: 0

安全: 0

类型:组件

2.0.1 2020-12-15 09:59 UTC

This package is auto-updated.

Last update: 2024-09-15 17:46:34 UTC


README

Codacy Badge License PHP version npm version

MatomoOptOut

Matomo (Piwik) 中的 AJAX 自定义 OptOut。无需 iframe。

MatomoOptOut 利用 Matomo (Piwik) 插件 Ajax Opt Out 从 »Lipperts Web«。您也需要安装和激活它。

安装

此软件包适用于 Composer,也适用于 Node

Composer

通过运行 $ composer require bitandblack/matomo-optout 安装 MatomoOptOut

NPM

通过运行 $ npm install bitandblack-matomo-optout 安装 MatomoOptOut

Yarn

通过运行 $ yarn add bitandblack-matomo-optout 安装 MatomoOptOut

入门

如下初始化 MatomoOptOut

import { MatomoOptOut } from "bitandblack-matomooptout";

const matomoOptOut = new MatomoOptOut(
    "https://yoursite.com/matomo",
    document.querySelector("#tracking-enabled"),
    document.querySelector("#tracking-disabled")
);

第一个参数是您 Matomo 实例的 URL。

第二个参数是包含跟踪启用时文本的 HTML 元素。它还应包含一个复选框来禁用跟踪。

第三个参数是包含跟踪禁用时文本的 HTML 元素。它还应包含一个复选框来启用跟踪。

HTML 应该如何?继续阅读

HTML

跟踪启用时的 HTML 可能看起来像这样

<div id="tracking-enabled">
    <p>You may choose to prevent this website from aggregating and analyzing the actions you take here. Doing so will protect your privacy, but will also prevent the owner from learning from your actions and creating a better experience for you and other users.</p>
    <p>
        <input id="disable-tracking" type="checkbox" checked="checked">
        <label for="disable-tracking">You are not opted out. Uncheck this box to opt-out.</label>
    </p>
</div>

跟踪禁用时的 HTML 可能看起来像这样

<div id="tracking-disabled">
    <p>Opt-out complete; your visits to this website will not be recorded by the Web Analytics tool. Note that if you clear your cookies, delete the opt-out cookie, or if you change computers or Web browsers, you will need to perform the opt-out procedure again.</p>
    <p>
        <input id="enable-tracking" type="checkbox">
        <label for="enable-tracking">You are currently opted out. Check this box to opt-in.</label>
    </p>
</div>

选项

错误信息

您可以为更改跟踪状态失败的情况定义一个错误信息。这可能发生在浏览器阻止第三方 Cookie 的情况下。

错误信息可能看起来像这样

<div id="tracking-error">
    <p>Unfortunately the status cannot be changed. This can be caused by the data protection setting of your browser. Please change the status under <a href="https://yoursite.com/matomo/index.php?module=CoreAdminHome&action=optOut&language=en" target="_blank" rel="noopener nofollow">https://yoursite.com/matomo</a>.</p>
</div>

通过调用添加

matomoOptOut.setErrorMessage(
    document.querySelector("#tracking-error")
);

错误回调

而不是通过显示 HTML 片段来显示错误,您可以直接获取该信息

matomoOptOut.setErrorCallback(() => {
    console.error("Could not change tracking status.");
});

持续跟踪状态检查

您可以允许库持续检查跟踪状态

matomoOptOut.watchStatusChange(10);

第一个参数是间隔时间的秒数。

帮助

您可以通过 hello@bitandblack.com 联系我们。