I have just integrated mixpanel on my landing page to track user behavior. I put the code mixpanel gave me here :
<!-- 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>
then I wanted to test my set up by tracking a click event on my page (someone clicking on the link with id="google_play"
, so I wrotte in my script
tag :
$(document).ready(function() {
mixpanel.track("google_play_click", {
"id": "google_play"
});
});
1) Is that the right way to track an event ? 2)when I am going on my page I ve got an error in the chrome console concerning 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
What am I doing wrong ?
Regarding your first question, the first argument of Mixpanel track function is the event name. Second argument is the properties you want to attach to that event. See documentation here.
Your code should look like the following:
$(document).ready(function() {
$('#google_play').on('click', function () {
mixpanel.track("button clicked", {
"id": "google_play"
});
});
});
Or if you want something more general, you can track every element with a certain class:
$(document).ready(function() {
$('.track-me').on('click', function () {
var id = $(this).attr('id');
mixpanel.track("button clicked", {
"id": id
});
});
});
Regarding second question, make sure the code is the same as shown here and also double check the token you are using when calling mixpanel.init("YOUR MIXPANEL YOKEN");