I'm trying to log an event in MixPanel when users click a certain type of link. I'm using JQuery to do it unobtrusively and as far as I understand I need to add a callback function to take the user to URL after the event has been logged.
This is the code I'm using:
<script type="text/javascript">
$("#more-posts").click(function() {
event.preventDefault();
mpq.track("More Posts", function(){
window.location = $(this).attr("href");
});
});
</script>
Unfortunately this neither takes the user to the page nor logs the event, but I see no errors in the Javascript console in Chrome.
Any ideas what the problem may be?
Update: Also tried this code based on suggestions in the comments:
<script type="text/javascript">
function go_to_link(link) {
window.location = link;
}
$("#more-posts").on("click", function(event) {
event.preventDefault();
mpq.track("More Posts");
setTimeout("go_to_link($("#more-posts").attr("href"))", 2000);
});
</script>
It now redirects to the correct link, but still doesn't log an event.
It would look something like this: mixpanel. track_links("#MyLink","Clicked Link"); The first argument is a css-style selector for the link you want to track, the second argument is the name of the event.
mixpanel. track(“Sign-up Page View”, { page: “email screen” }); Essentially you will only be sending in one event named “Sign-up Page View” but you can then expand the event by the event property “page”, where you can see what page your users where looking at while they signed up. Hope this helps!
Checking events To view more events, you can click on the "Load More" button at the bottom of the page. "Load More" will fetch the next 100 most recent events timestamped in the 30 days prior to the previously fetched events. Once the new events show up on "Events", they will be queryable in other Mixpanel reports.
Mixpanel has recently added a method mixpanel.track_links that does the job.
The third argument of the mpq.track function is a callback. This code gets executed once the tracking has completed, and would be a reliable way to send the user to the other page.
$("#more-posts").on("click", function(event) {
event.preventDefault();
mpq.track("More Posts", null, function() {
go_to_link($("#more-posts").attr("href"))
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With