How Do I Log A Mixpanel Event When A User Clicks A Link?
Solution 1:
Mixpanel has recently added a method mixpanel.track_links that does the job.
Solution 2:
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"))
});
});
Solution 3:
I believe this is a candidate for MixPanel support: support@mixpanel.com. The bug does not lie with your jQuery code. Here's a working jsFiddle that demonstrates the basic functionality.
As I mentioned, I've seen similar issues with a _kmq.push
with Kissmetrics. Their JS simply might not have time to register the event. If you try a longer timeout, it might work, but this is bad UX.
Update here if/when you reach out to MixPanel.
Solution 4:
Instead of using setTimeout, consider using the callback param of mpq.track.
Alternatively, track the page load at the location that the link would have gone to.
Solution 5:
The easiest way is to use the function callback in mixpanel.track which fires after the event is successfully logged.
Code would look like this.
mixpanel.track("Great Success!", {}, function(){
window.location.href = "www.whatever.com";
});
Post a Comment for "How Do I Log A Mixpanel Event When A User Clicks A Link?"