ga(' set',' userId',' 1234')没有发送任何内容

时间:2017-11-06 15:07:58

标签: javascript google-analytics

我尝试使用Google Analytics'用户身份验证以异步方式。我跟着this doc,所以我有这两个代码:

在我的HTML代码中,在

部分中



<script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-36705395-2', 'auto', {'allowLinker': true});
    ga('require', 'linker');
    ga('linker:autoLink', ['my.website.com'] );

    ga('send', 'pageview');
</script>
&#13;
&#13;
&#13;

在我的外部JS中,在pageload之后执行

&#13;
&#13;
$.ajax({
    url: 'https://my.website.com/api/check_key?cid=' + cid,
    type: 'GET',
    accepts: {
        json: 'application/json'
    },
    success: function (data) {
        console.log('send userID to GA ('+ cid +')');
        ga('set', 'userId', cid);
    }
});
&#13;
&#13;
&#13;

问题: ga(&#39;设置&#39;,&#39; userId&#39;,cid); 不向GA发送任何内容,即使我有在我的控制台中跟踪。没有XHR呼叫GA。

当我将GA切换到调试模式时,我有这样的痕迹:

  

运行命令:ga(&#34;设置&#34;,&#34; userId&#34;,&#34; 123&#34;)

我错过了什么吗? ga(&#39;设置&#39; ...)需要其他东西来发送数据吗?

感谢。

1 个答案:

答案 0 :(得分:1)

当您使用“发送”命令时,数据仅发送到分析,因此您需要在设置用户ID后记录网页浏览,事件或社交互动。谷歌在页面加载后处理身份验证的文档具有误导性,因为它没有提到这一点。

在这种情况下,录制登录事件可能有意义。

ga('send', 'event', 'account', 'login');