From 774260769d8863662100c2ada9df3ee2d2a81014 Mon Sep 17 00:00:00 2001 From: Matt Lott Date: Tue, 2 Dec 2014 13:25:12 -0800 Subject: [PATCH] Update pageview tracking Based on more feedback from segment.io support. Still trying to get Google Analytics virtual pageviews to work correctly. --- app/core/Tracker.coffee | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/app/core/Tracker.coffee b/app/core/Tracker.coffee index f8a00467b..c0db96c69 100644 --- a/app/core/Tracker.coffee +++ b/app/core/Tracker.coffee @@ -19,21 +19,37 @@ module.exports = class Tracker traits[userTrait] ?= me.get(userTrait) analytics.identify me.id, traits - trackPageView: (name=null, includeIntegrations=null) -> + trackPageView: (virtualName=null, includeIntegrations=null) -> + # console.log 'trackPageView', virtualName, includeIntegrations # 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() - if includeIntegrations + name = virtualName ? Backbone.history.getFragment() + + properties = {} + if virtualName? + # Override title and path properties for virtual page view + # https://segment.com/docs/libraries/analytics.js/#page + properties = + title: name + path: "/#{name}" + + options = {} + if includeIntegrations? options = integrations: {'All': false} for integration in includeIntegrations options.integrations[integration] = true - analytics.page "/#{name}", {}, options - else + + console.log "Would track analytics pageview: '/#{name}'", properties, options if debugAnalytics + return unless @isProduction and analytics? and not me.isAdmin() + + # Ok to pass empty properties, but maybe not options + # TODO: What happens when we pass empty options? + if _.isEmpty options + # console.log "trackPageView without options '/#{name}'", properties, options analytics.page "/#{name}" + else + # console.log "trackPageView with options '/#{name}'", properties, options + analytics.page "/#{name}", properties, options trackEvent: (action, properties, includeIntegrations=null) => # 'action' is a string