Created
February 8, 2012 18:33
-
-
Save daveaugustine/1771986 to your computer and use it in GitHub Desktop.
Super simple Google Analytics page tracking with backbone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
initialize: -> | |
@bind 'all', @_trackPageview | |
_trackPageview: -> | |
url = Backbone.history.getFragment() | |
_gaq.push(['_trackPageview', "/#{url}"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Three things:
_gaq
is a method from ga.js. As of right now, google is trying to get everyone to switch from using ga.js + "google analytics classic" to using analytics.js + "Universal Analytics". If you're using analytics.js the line_gaq.push(['_trackPageview', "/#{url}"])
should read
ga('send', 'pageview', "/#{url}");
Backbone.history.on("route", sendPageview)
Also, if you want to test on localhost, make sure in that you specify
'auto'
in your call toga('create', ...)
. e.g.ga('create', 'auto')
as opposed toga('create', 'mysite.com')