Recently I have been working with a customer who has seen a large increase in the number of sessions from users of the Google Chrome browser. After some testing we have been able to attribute this to the prefetching or prerendering feature of Chrome, the purpose of which is to speed up the loading of web pages by requesting resources before you have actually selected to view them. A potentially unwelcome side effect of this is causing web analytics page tags to fire even though the user has not actually viewed the page itself; it has simply been prefetched by Chrome in the background.

Take the following scenario: in google.co.uk I enter ‘scl.com’ as my search criteria and Google returns a list of results. At the top of the list if is the search result for www.scl.com.

If you use an http recorder you can see that in the background Chrome has requested the home page for www.scl.com and caused the page tag to fire, in this case we are using IBM Digital Analytics (Coremetrics).

GoogleChromeBlog picture

 

Google Analytics does check the visibilityState of the page and if it is ‘prerender’ then the GA page tag does not fire. However, it appears that Adobe Site Catalyst, WebTrends and IBM Digital Analytics (Coremetrics) all exhibit the issue described above.

Users of Chrome are able to disable the prefetch feature by de-selecting the ‘Prefetch resources to load pages more quickly’ option available in Settings -> Advanced Settings -> Privacy.

Fixing the problem

The solution to this problem is clearly to suppress the page tag when this situation arises. To do this we can make use of the page visibility API in order to detect the visibility state of the page. The document has a property called visibilityState which will be set to ‘prerender’ when it has been prefetched by Chrome. You can write some simple JavaScript to interrogate this value and suppress the page tag from firing, e.g.

     if (typeof document.visibilityState != 'undefined') {
         if (document.visibilityState == 'prerender') {
            //set a flag to disable the page from firing here
      } else {
            //allow the page tag to fire
      }

I hope you found this blog post useful and would be interested to hear comments.