diff --git a/app/core/Tracker.coffee b/app/core/Tracker.coffee index 1a754417e..0c4d6d0a7 100644 --- a/app/core/Tracker.coffee +++ b/app/core/Tracker.coffee @@ -19,11 +19,21 @@ module.exports = class Tracker traits[userTrait] ?= me.get(userTrait) analytics.identify me.id, traits - trackPageView: -> + trackPageView: (name=null, includeIntegrations=null) -> + # Google Analytics does not support event-based funnels, so we have to use virtual pageviews instead + # https://support.google.com/analytics/answer/1032720?hl=en + # https://segment.com/docs/libraries/analytics.js/#page + unless name? + name = Backbone.history.getFragment() + console.log "Would track analytics pageview: /#{name}" if debugAnalytics return unless @isProduction and analytics? and not me.isAdmin() - url = Backbone.history.getFragment() - console.log 'Going to track visit for', "/#{url}" if debugAnalytics - analytics.pageview "/#{url}" + if includeIntegrations + options.integrations = {'All': false} + for integration in includeIntegrations + options.integrations[integration] = true + analytics.page null, "/#{name}", null, options + else + analytics.page "/#{name}" trackEvent: (action, properties, includeIntegrations=null) => # 'action' is a string @@ -34,7 +44,6 @@ module.exports = class Tracker # https://segment.com/docs/integrations/mixpanel/ console.log 'Would track analytics event:', action, properties if debugAnalytics return unless me and @isProduction and analytics? and not me.isAdmin() - console.log 'Going to track analytics event:', action, properties if debugAnalytics properties = properties or {} context = {} if includeIntegrations diff --git a/app/views/play/level/PlayLevelView.coffee b/app/views/play/level/PlayLevelView.coffee index f96e5392a..06d744abf 100644 --- a/app/views/play/level/PlayLevelView.coffee +++ b/app/views/play/level/PlayLevelView.coffee @@ -136,6 +136,7 @@ module.exports = class PlayLevelView extends RootView loadDuration = @loadEndTime - @loadStartTime console.debug "Level unveiled after #{(loadDuration / 1000).toFixed(2)}s" application.tracker?.trackEvent 'Finished Level Load', category: 'Play Level', label: @levelID, level: @levelID, loadDuration: loadDuration, ['Google Analytics'] + application.tracker?.trackPageView "level-loaded/#{@levelID}", ['Google Analytics'] application.tracker?.trackTiming loadDuration, 'Level Load Time', @levelID, @levelID # CocoView overridden methods ############################################### @@ -425,6 +426,7 @@ module.exports = class PlayLevelView extends RootView category: 'Play Level' level: @level.get('name') label: @level.get('name') + application.tracker?.trackPageView "level-completed/#{@levelID}", ['Google Analytics'] application.tracker?.trackTiming victoryTime, 'Level Victory Time', @levelID, @levelID, 100 showVictory: ->