Created
May 1, 2012 16:15
-
-
Save teejayvanslyke/2569284 to your computer and use it in GitHub Desktop.
Using data attributes to elegantly create Mixpanel trackers. http://tjvanslyke.com/using-data-attributes-to-elegantly-create-mixpanel-trackers/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('a[data-mixpanel-tracker]').click -> | |
setTimeout (=> window.location.href = $(@).attr('href')), 300 | |
tracker = $(@).attr('data-mixpanel-tracker') | |
properties = JSON.parse($(@).attr('data-mixpanel-properties') || '{}') | |
mixpanel.track tracker, properties | |
return false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can improve on this a bit more still by turning the function that jumps to the href location into a var and passing it as the callback of mixpanel.track as well.
That way you jump as soon as the event is received by MixPanel in case it's faster than 300ms.