I am trying to register an event in MixPanel when users click on a specific type of link. I use jQuery to do this unobtrusively, and as far as I understand, I need to add a callback function to bring the user to the 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 does not lead the user to the page and does not register the event, but I do not see errors in the Javascript console in Chrome.
Any ideas what might be the problem?
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($("
Now it is redirected to the correct link, but does not register the event.
source share