Unknown Kadath

Monitoring the impact of Google/Webkit Prerendering of Pages with Piwik Analytics

Posted on June 21st, 2011 by admin

Google has announced that their search engine will begin prerendering pages. http://googlewebmastercentral.blogspot.com/2011/06/announcing-instant-pages.html

The potential problem with Google’s prerendering…
It’s done with Javascript.

That means that it happens on the client and not on Google’s server. There is no way to tell if my page was actually viewed by the user or if the page was prefetched and cached by the user’s browser because the search page they were viewing told it to prerender the page. Well, no way to tell by just looking at my normal stats. There is a way to detect whether or not the user actually views the page using some javascript.

I use Piwik on many websites in parallel with Google Analytics. Piwik gives me the ability to monitor performance and trends in real time.

I use Google Analytics for monitoring trends over greater periods of time like weeks, months or years.

Google Analytics will likely give me the ability to filter out and monitor prerendered pages in the near future. Piwik will probably add an option for this eventually also but right now, I want to begin monitoring it to see how often it happens and how important it is to my infrastructure.

1. How much bandwidth is used by pages that are prerendered but never viewed?

2. What pages does Google rank highly enough that they feel the need to prerender them and what keywords are they resulting from?

3. Who else is causing my pages to prerender besides Google.com?

Using some javascript we can check on the webkitVisibilityState of the page as it is viewed or cached by the client based on the W3C Page Visibility spec http://www.w3.org/TR/2011/WD-page-visibility-20110602/

Google Chrome Labs has a page on this http://code.google.com/chrome/whitepapers/pagevisibility.html

We’ll use their technique to log our Piwik stats differently if the page is prerendered and then properly log the visit if the prerendered page is subsequently viewed.

A simple Piwik tracking image will be sufficient for our tests. We can add full javascript based tracking once we know that it works. If it is prerendered then we will track it to a different website account on Piwik using the querystring variable idsite and then monitor it with an event listener so that if it is subsequently viewed then it will track it as normal.

var isPrerendering = false;

function handleVisibilityChange(evt) {
if (!isPrerendering) return;
isPrerendering = false;

function countView(){
document.write('<img src="http://PIWIK WEBHOST/piwik/
   piwik.php?idsite=[ID OF NORMAL SITE]&rec=1" />');

* We can count the view right now if the document isn't being prerendered.
* Browsers that don't support the API will return undefined for
* webkitVisibilityState.
if (document.webkitVisibilityState != "prerender") {
} else {
//We'll need to count the pageview later
isPrerendering = true;
document.write('<img src="http://PIWIK WEBHOST/piwik/
   piwik.php?idsite=[ID OF PRERENDER TRACKING SITE]&rec=1" />');
   handleVisibilityChange, false);

Trying it out
Using Chrome 13 http://tools.google.com/dlpage/chromesxs enable prerendering by starting Chrome like this…
chrome.exe –prerender=enabled

To test this I go to http://prerender-test.appspot.com/ and enter the address of a page that I am tracking like this one and it will show a prerendered hit in the Piwik website I set up for tracking them.

I like it.
It’s fast and enhances the users experience. Using javascript puts all of the cost (processing and bandwidth) on my webserver and user’s browser so we’ll see if this causes problems for its adoption. I’ll keep playing with it and when it does become mainstream, I hope to be ready to embrace it and not allow it to adversely affect my servers, visitors or analytics.

This entry was posted on Tuesday, June 21st, 2011 at 12:38 am and is filed under HTML5. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

2 Responses to “Monitoring the impact of Google/Webkit Prerendering of Pages with Piwik Analytics”

JamesJune 26th, 2011 at 3:46 am

I would like to add that I use Piwik on some busy sites (1,000,000+ pv per month) and as such I archive the database and delete the data once or twice a week for performance and disk space issues.
I have found nothing as customizable and accurate as Piwik for collecting this data so it is worth the extra effort (which is mostly automated).
If you have an average sized website, this should not be an issue.

Leave a Response