Skip to content

Instantly share code, notes, and snippets.

@valentinzberea
Last active December 19, 2015 22:48
Show Gist options
  • Save valentinzberea/6029724 to your computer and use it in GitHub Desktop.
Save valentinzberea/6029724 to your computer and use it in GitHub Desktop.
# 1. Initialization code:
logged_user = window.user
# Properties for each event
mixpanel.register(
'User Account': logged_user.getUserAccount()
'Whitelabel': logged_user.getUserType()
)
# People settings
mixpanel.name_tag(logged_user.getNameTag())
mixpanel.people.set(
'$email': logged_user.get('email')
'User Name': logged_user.getUserName()
'User Id': logged_user.get('id')
'Whitelabel': logged_user.getUserType()
)
# This increment with 0 will ensure that the Actions counter
# will always exist and prevents the problems with filtering in
# mixpanel which does not allow expressions by missing values
mixpanel.people.increment('Lifetime Actions Count', 0)
# After every set/increment the user must be identified again:
mixpanel.identify(logged_user.get('id'))
# Notify mixpanel about disabled events
mixpanel.disable App.mixpanel_disabled_events
# Notify mixpanel about disabled super properties
for property in App.mixpanel_disabled_properties
mixpanel.unregister property
# 2. Tracking code:
switch event.track_type
when Constants.MIXPANEL_TRACK_TYPE.event
mixpanel.track(event.name, event.properties)
when Constants.MIXPANEL_TRACK_TYPE.people
mixpanel.people.increment(event.name)
# For each incremented action also increment the
# 'Lifetime Actions Count' index
mixpanel.people.increment('Lifetime Actions Count')
mixpanel.identify(logged_user.get('id'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment