【问题标题】:Smartlook doesn't save User consent properlySmartlook 未正确保存用户同意
【发布时间】:2019-01-23 11:57:54
【问题描述】:

我正在尝试在我们的网站中实施 Smartlook。我们正在使用 React,所以我不能直接执行文档建议的操作: https://smartlook.github.io/docs/web/gdpr/

我们通过 index.html 中的脚本标签初始化 Smartlook

 <script type="text/javascript">
      window.smartlook ||
        (function(d) {
          var o = (smartlook = function() {
              o.api.push(arguments);
            }),
            h = d.getElementsByTagName("head")[0];
          var c = d.createElement("script");
          o.api = new Array();
          c.async = true;
          c.type = "text/javascript";
          c.charset = "utf-8";
          c.src = "https://rec.smartlook.com/recorder.js";
          h.appendChild(c);
        })(document);
      smartlook("init", "somerandomstring");
    </script>

我向用户展示了一个可以选择加入的模式,当他选择加入时,这个功能就会被触发:

setCookie = accept => {
    const consentText = "Blabalbal";

    this.setState({ showModal: false });
    const date = new Date();
    date.setTime(date.getTime() + 360 * 24 * 60 * 60 * 1000);
    const expires = `expires=${date.toUTCString()}`;
    document.cookie = `acceptTracking=${accept};${expires};path=/`;
    window.smartlook("consentIP", accept ? consentText : false);
    window.smartlook("consentAPI", accept ? consentText : false);
    console.log(window.smartlook);
    if (accept) {
      ReactPiwik.push(["rememberConsentGiven"]);
    }
  };

根据文档,this.should 创建一个名为同意的属性。最初,记录的对象如下所示: 不幸的是,该财产存在,但未经同意。执行我的函数后,整个 smartlook 对象如下所示: 所以它保存了数据,只是不在正确的位置,这对我来说几乎毫无价值。有人知道如何解决这个问题吗?

【问题讨论】:

    标签: javascript reactjs tracker


    【解决方案1】:

    似乎尚未开始录制。 在开始录制之前,所有的api调用都保存在数组中待处理。

    一旦服务器成功响应初始化请求,您的代码应该可以正常工作。

    【讨论】:

    • 我们在 index.html 中初始化。我将编辑我的原始帖子以澄清这一点。
    • 是的。有脚本初始化,然后有对服务器的请求。对服务器的请求成功后,同意被保存。您的录制似乎尚未开始,因此未保存同意。
    • 脚本页面上本地存储的内容是什么?正如我之前所说,如果录制没有开始(来自服务器的错误响应、并行限制等),smartlook 对象不会被初始化。根据截图,录制没有开始。尝试在匿名窗口中打开页面并查看 /check 和 /init 请求的结果。
    猜你喜欢
    • 2013-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 1970-01-01
    • 2021-06-09
    相关资源
    最近更新 更多