Created
July 24, 2016 18:39
-
-
Save Richtermeister/91dd190f6b37190ab1e3fd876297ca55 to your computer and use it in GitHub Desktop.
mixpanel helper
This file contains 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
$(function() { | |
if (window.mixpanel == undefined) { | |
return; | |
} | |
var mixpanelRegex = /\((.*)\)/; | |
function handleMixpanelTag(tag, $el) { | |
var bits = tag.split(':'); | |
var parametersJson = mixpanelRegex.exec(tag); | |
var parameters = []; | |
if (parametersJson) { | |
parameters = JSON.parse(parametersJson[1]); | |
tag = tag.substr(0, parametersJson.index); | |
} | |
if (bits[0] == 'view') { | |
mixpanel.track(tag, parameters); | |
} else if (bits[0] == 'click') { | |
$el.click(function(){ | |
mixpanel.track(tag, parameters); | |
}) | |
} | |
} | |
$('[data-mixpanel]').each(function(){ | |
handleMixpanelTag($(this).data('mixpanel'), $(this)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment