Skip to content

Instantly share code, notes, and snippets.

@cbfranklin
Last active August 29, 2015 14:18
Show Gist options
  • Save cbfranklin/da1ac18999b15994948f to your computer and use it in GitHub Desktop.
Save cbfranklin/da1ac18999b15994948f to your computer and use it in GitHub Desktop.
Hashchanges as Pageviews in UA
//adds verified JS route to gaCrumb for initial pageview report
if(window.location.hash.indexOf('#/') !== -1){
gaCrumb = gaCrumb + '/' + window.location.hash;
}
//fires verified JS route as additional "virtual pageview"
$(window).hashchange(function(){
if(window.location.hash.indexOf('#/') > -1){
if(gaCrumb.indexOf('#') > -1){
gaCrumb = gaCrumb.split('#')[0];
}
ga('send', 'pageview', gaCrumb + '/' + window.location.hash);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment