mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Update pageview tracking
Based on more feedback from segment.io support. Still trying to get Google Analytics virtual pageviews to work correctly.
This commit is contained in:
parent
3675c79b26
commit
774260769d
1 changed files with 25 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue