Ensure GA is recorded for each page change

This commit is contained in:
Andrew Miner
2015-01-15 11:14:04 -08:00
parent d2b9720e72
commit f0c6c055ff
3 changed files with 20 additions and 4 deletions
@@ -13,5 +13,4 @@ script.
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-5871323-4', 'crafting-guide.com');
ga('send', 'pageview');
}
+9
View File
@@ -19,6 +19,8 @@ module.exports = class CraftingGuideRouter extends Backbone.Router
@_pageControllers = {}
super options
@on Event.route, => @_recordPageView()
# Backbone.Router Overrides ####################################################################
routes:
@@ -38,6 +40,13 @@ module.exports = class CraftingGuideRouter extends Backbone.Router
# Private Methods ##############################################################################
_recordPageView: ->
if global.env is 'production'
logger.info "Recording GA page view: #{window.location.href}"
ga('send', 'pageview')
else
logger.info "Suppressing GA page view: #{window.location.href}"
_setPage: (controllerName)->
controller = @_pageControllers[controllerName]
if not controller? then throw new Error "cannot find controller named: #{controllerName}"
+10 -2
View File
@@ -15,13 +15,21 @@ CraftingGuideRouter = require './crafting_guide_router'
if typeof(global) is 'undefined'
window.global = window
global.logger = new Logger level:Logger.WARNING
global.logger = new Logger
global.router = new CraftingGuideRouter
global.util = require 'util'
global.views = views
if window.location.hostname is 'localhost'
switch window.location.hostname
when 'localhost'
global.env = 'development'
logger.level = Logger.TRACE
when 'new.crafting-guide.com'
global.env = 'staging'
logger.level = Logger.VERBOSE
when 'crafting-guide.com'
global.env = 'production'
logger.level = Logger.WARNING
feedbackController = new FeedbackController el:'.view__feedback'
feedbackController.render()