Don't duplicate reports of page visits

This commit is contained in:
Andrew Miner
2015-01-15 11:30:47 -08:00
parent f0c6c055ff
commit 03eacc243c
2 changed files with 12 additions and 4 deletions
+1
View File
@@ -33,6 +33,7 @@ Event.load.succeeded = 'load:succeeded' # controller, book
Event.load.failed = 'load:failed' # controller, error message Event.load.failed = 'load:failed' # controller, error message
Event.load.finished = 'load:finished' # controller Event.load.finished = 'load:finished' # controller
Event.remove = 'remove' # collection, item... Event.remove = 'remove' # collection, item...
Event.route = 'route'
exports.Url = Url = {} exports.Url = Url = {}
Url.itemIcon = _.template "/data/<%= modSlug %>/images/<%= itemSlug %>.png" Url.itemIcon = _.template "/data/<%= modSlug %>/images/<%= itemSlug %>.png"
+9 -2
View File
@@ -6,6 +6,7 @@ All rights reserved.
### ###
{Duration} = require './constants' {Duration} = require './constants'
{Event} = require './constants'
ItemPageController = require './controllers/item_page_controller' ItemPageController = require './controllers/item_page_controller'
{Opacity} = require './constants' {Opacity} = require './constants'
UrlParams = require './url_params' UrlParams = require './url_params'
@@ -17,12 +18,15 @@ module.exports = class CraftingGuideRouter extends Backbone.Router
constructor: (options={})-> constructor: (options={})->
@_page = null @_page = null
@_pageControllers = {} @_pageControllers = {}
@_lastReportedHref = null
super options super options
@on Event.route, => @_recordPageView()
# Backbone.Router Overrides #################################################################### # Backbone.Router Overrides ####################################################################
navigate: ->
super
@_recordPageView()
routes: routes:
'': 'root' '': 'root'
'item(/:name)': 'item' 'item(/:name)': 'item'
@@ -41,6 +45,9 @@ module.exports = class CraftingGuideRouter extends Backbone.Router
# Private Methods ############################################################################## # Private Methods ##############################################################################
_recordPageView: -> _recordPageView: ->
return if @_lastReportedHref is window.location.href
@_lastReportedHref = window.location.href
if global.env is 'production' if global.env is 'production'
logger.info "Recording GA page view: #{window.location.href}" logger.info "Recording GA page view: #{window.location.href}"
ga('send', 'pageview') ga('send', 'pageview')