登陆页面上的Mixpanel集成无法正常工作

时间:2015-07-13 10:29:10

标签: javascript mixpanel

我刚在登录页面上集成了mixpanel来跟踪用户行为。我把代码mixpanel给了我这里:

RewriteEngine On    # Turn on the rewriting engine
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://localhost:8080/$1 [L,R]

然后我想通过在我的网页上跟踪点击事件来测试我的设置(有人点击了 <!-- 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"标签:

script

1)这是跟踪活动的正确方法吗? 2)当我进入我的页面时,我在Chrome控制台中遇到有关mixpanel的错误:

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

我做错了什么?

1 个答案:

答案 0 :(得分:1)

关于第一个问题,Mixpanel跟踪功能的第一个参数是事件名称。第二个参数是要附加到该事件的属性。请参阅文档here

您的代码应如下所示:

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

或者如果你想要更通用的东西,你可以跟踪某个类的每个元素:

$(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");时仔细检查您使用的令牌