Enable Mixpanel

Closes 
This commit is contained in:
Matt Lott 2016-01-21 10:42:56 -08:00
parent 2546694b06
commit 1825d0e2dd
4 changed files with 26 additions and 7 deletions

View file

@ -47,6 +47,10 @@
(window,document,"script","51a79585ee207206390002a2");
</script>
<!-- start Mixpanel --><script type="text/javascript">(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f)}})(document,window.mixpanel||[]);
mixpanel.init("e71a4e60db7e1dc5e685be96776280f9");</script><!-- end Mixpanel -->
<script src="https://checkout.stripe.com/checkout.js"></script>
<!-- IE9 doesn't support defer attribute: https://github.com/h5bp/lazyweb-requests/issues/42 -->

View file

@ -64,7 +64,7 @@ module.exports = class Tracker
for userTrait in ['email', 'anonymous', 'dateCreated', 'name', 'testGroupNumber', 'gender', 'lastLevel', 'siteref', 'ageRange']
traits[userTrait] ?= me.get(userTrait)
console.log 'Would identify', traits if debugAnalytics
console.log 'Would identify', me.id, traits if debugAnalytics
return unless @isProduction and not me.isAdmin()
# Errorception
@ -76,19 +76,29 @@ module.exports = class Tracker
__insp?.push ['identify', me.id]
__insp?.push ['tagSession', traits]
# Mixpanel
# https://mixpanel.com/help/reference/javascript
mixpanel.identify(me.id)
mixpanel.register(traits)
trackPageView: ->
name = Backbone.history.getFragment()
console.log "Would track analytics pageview: '/#{name}'" if debugAnalytics
url = "/#{name}"
console.log "Would track analytics pageview: #{url}" if debugAnalytics
@trackEventInternal 'Pageview', url: name unless me?.isAdmin() and @isProduction
return unless @isProduction and not me.isAdmin()
# Google Analytics
# https://developers.google.com/analytics/devguides/collection/analyticsjs/pages
ga? 'send', 'pageview', "/#{name}"
ga? 'send', 'pageview', url
trackEvent: (action, properties={}) =>
# Mixpanel
mixpanelIncludes = ['courses', 'courses/purchase', 'courses/teachers', 'courses/students', 'schools', 'teachers', 'teachers/freetrial']
mixpanel.track('page viewed', 'page name' : name, url : url) if name in mixpanelIncludes
trackEvent: (action, properties={}, includeIntegrations=[]) =>
@trackEventInternal action, _.cloneDeep properties unless me?.isAdmin() and @isProduction
console.log 'Tracking external analytics event:', action, properties if debugAnalytics
console.log 'Tracking external analytics event:', action, properties, includeIntegrations if debugAnalytics
return unless me and @isProduction and not me.isAdmin()
# Google Analytics
@ -105,6 +115,10 @@ module.exports = class Tracker
# http://www.inspectlet.com/docs#tagging
__insp?.push ['tagSession', action: action, properies: properties]
# Mixpanel
# Only log explicit events for now
mixpanel.track(action, properties) if 'Mixpanel' in includeIntegrations
trackEventInternal: (event, properties) =>
# Skipping heavily logged actions we don't use internally
unless event in ['Simulator Result', 'Started Level Load', 'Finished Level Load']

View file

@ -21,11 +21,11 @@ module.exports = class SalesView extends RootView
onClickLogin: (e) ->
@openModalView new AuthModal(mode: 'login') if me.get('anonymous')
window.tracker?.trackEvent 'Started Login', category: 'Sales', label: 'Sales Login'
window.tracker?.trackEvent 'Started Login', category: 'Sales', label: 'Sales Login', ['Mixpanel']
onClickSignup: (e) ->
@openModalView new AuthModal() if me.get('anonymous')
window.tracker?.trackEvent 'Started Signup', category: 'Sales', label: 'Sales Create'
window.tracker?.trackEvent 'Started Signup', category: 'Sales', label: 'Sales Create', ['Mixpanel']
logoutRedirectURL: false

View file

@ -82,3 +82,4 @@ module.exports = class TeachersFreeTrialView extends RootView
console.error 'Error saving trial request', response
success: (model, response, options) =>
@refreshData()
window.tracker?.trackEvent 'Submit Trial Request', category: 'Teachers', label: 'Trial Request', ['Mixpanel']