登录页面上的 Mixpanel 集成不起作用

Mixpanel integration on landing page not working

我刚刚在我的着陆页上集成了混合面板来跟踪用户行为。我把 mixpanel 给我的代码放在这里:

 <!-- start Mixpanel --><script type="text/javascript">(function(f,b){if(!b.__SV){var a,e,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=f.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";e=f.getElementsByTagName("script")[0];e.parentNode.insertBefore(a,e)}})(document,window.mixpanel||[]);
mixpanel.init("******");</script><!-- end Mixpanel -->
</head>

然后我想通过跟踪我页面上的点击事件来测试我的设置(有人用 id="google_play" 点击 link,所以我在我的 script 标签中写道:

$(document).ready(function() {
          mixpanel.track("google_play_click", {
            "id": "google_play"
          });
       });

1) 这是跟踪事件的正确方法吗? 2) 当我进入我的页面时,我在 chrome 控制台中遇到了一个关于 mixpanel 的错误:

Remote Address:23.214.151.115:80
Request URL:http://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js
Request Method:GET
Status Code:403 Forbidden

我做错了什么?

关于你的第一个问题,Mixpanel track函数的第一个参数是事件名称。第二个参数是您要附加到该事件的属性。请参阅文档 here

您的代码应如下所示:

$(document).ready(function() {
    $('#google_play').on('click', function () {
        mixpanel.track("button clicked", {
            "id": "google_play"
        });
    });
});

或者如果你想要更通用的东西,你可以用特定的 class:

跟踪每个元素
$(document).ready(function() {
    $('.track-me').on('click', function () {
        var id = $(this).attr('id');
        mixpanel.track("button clicked", {
            "id": id
        });
    });
});

关于第二个问题,请确保代码与 shown here 相同,并仔细检查您在调用 mixpanel.init("YOUR MIXPANEL YOKEN");

时使用的令牌