Skip to content

Instantly share code, notes, and snippets.

@tracend
Forked from daveaugustine/Inside_your_router.coffee
Created July 3, 2012 23:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracend/3044124 to your computer and use it in GitHub Desktop.
Save tracend/3044124 to your computer and use it in GitHub Desktop.
[DEPRECATED]: Super simple Google Analytics page tracking with backbone.js
Router = Backbone.Router.extend({
initialize: function() {
this.bind('all', this._trackPageview);
},
_trackPageview: function(){
var url = Backbone.history.getFragment();
_gaq.push(['_trackPageview', "/#"+url]);
}
});
<script type="text/javascript">
var _gaq=[["_setAccount","{ANALYTICS_ID}"],["_trackPageview"]];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=("https:"==location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";
s.parentNode.insertBefore(g,s)}(document,"script"));
</script>
@tracend
Copy link
Author

tracend commented Feb 20, 2013

This tipbit has now become a feature for Backbone APP() at:
http://github.com/makesites/backbone-app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment