gwtgoogle-analyticsgwt-history

Google Analytics - Tracking pages using history token


I would like to know if Google Analytics automatically keeps track of the pages that have their state retained using the ajax history token ('#'), developed for example with GWT. My app has a single html page and different modules (pages) have the same URL, except that part that comes after # (ex. www.mysite.com?test=true#page=Contacts/id=1).

Also, if this mentioned behavior is not by default, is there a way to set up the Google Analyics to have this functionality ?

EDIT:

I found this article which explains how #hashtag can be tracked: http://www.searchenginepeople.com/blog/how-to-track-clicks-on-anchors-in-google-analytics.html

But, if i use this solution, will the page access be recorded when a user presses an Anchor with href'#hastag' or only when a a page is accessed directly with that hashtag (in that case, I should register a function that calls trackPageview when history changes)?


Solution

  • I added the following lines to the initial analytics script:

    _gaq.push(['_trackPageview', location.pathname + location.search + location.hash]);
    

    and

    window.onhashchange =  function(){            
                    _gaq.push(['_trackPageview',location.pathname + location.search  + location.hash]);             
                }
    

    which tracks the history change.