Skip to content

Instantly share code, notes, and snippets.

@albertpak
Forked from teejayvanslyke/gist:2569284
Last active August 29, 2015 13:56
Show Gist options
  • Save albertpak/8894205 to your computer and use it in GitHub Desktop.
Save albertpak/8894205 to your computer and use it in GitHub Desktop.
Simply paste this snippet into your document ready block to get started, then on any links you'd like to track, simply provide the data-mixpanel-tracker attribute: Specify custom properties in JSON using the data-mixpanel-properties attribute: <a href="/moon" data-mixpanel-tracker="he chose to go to the moon" data-mixpanel-properties="{agency: '…
$('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
$('a[data-mixpanel-tracker]').click(function() {
var properties, tracker;
setTimeout(((function(_this) {
return function() {
return window.location.href = $(_this).attr('href');
};
})(this)), 300);
tracker = $(this).attr('data-mixpanel-tracker');
properties = JSON.parse($(this).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