在 Vue.JS 中使用 matomo 启用选择退出 cookie 跟踪

问题描述

我有一个用 Vue.JS 编写的网站,我使用 matomo 进行跟踪,使用 cookie。由于我在欧洲,因此必须允许用户明确选择退出被跟踪。为此,我有一个可以允许或禁止跟踪的复选框。我也使用了 vue-matomo npm 包。

这里的问题是 matomo 是异步加载的。因此,网站初始加载时 matomo 不可用,因此我无法获得用户的状态(是否被跟踪)。我需要一种方法来获得用户对网站初始加载的同意,设置复选框(跟踪或不跟踪),然后允许用户相应地更改状态。

<template>
  <b-field>
    <b-checkBox
      v-model="consentStatus"
      true-value="Opt-out"
      false-value="Opt-In">
      {{ consentStatus }}
    </b-checkBox>
  </b-field>
</template>

<script>
export default {
  data() {
    return {
      consentStatus: '',};
  },created() {
    // This is asynchronous. Using await hasn't worked.
    if (this.$matomo.hasRememberedConsent()) {
      this.consentStatus = 'Opt-Out';
    } else {
      this.consentStatus = 'Opt-In';
    }
  },};
</script>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)