Google Analytics : Intro To Virtual Pageviews

> basis and guidelines for the _trackPageview function

The _trackPageview function can be considered as the Google Analytics Workhorse as it sets up all the required cookies for a visit session and submits the data to GA servers – that is it is the main function for tracking a page within Google Analytics.
In the standard GATC, _trackPageview is called without any additional values. Therefore you can customize that function in order to get more accurate reporting as show below with the 3 mains uses of what is called “virtual pageviews” :
  • Tracking files download
  • Rewriting unreadable URLs
  • Tracking partially completed forms
Tracking files download
By default GA doesn’t track files downloads since these files in question cannot be tagged with the GATC. It is quite easy to rectify this by modifying the download link on your pages. That is, the link itself is modified, not the GATC, as show in example below :
Original link that cannot be tracked :
<a href="whitebook.pdf">Download our White Book</a>
New link tracked within the virtual /downloads directory :
<a href="whitebook.pdf" onclick="_gaq.push(['_trackPageview',
'/downloads/whitebook.pdf']);">Download our White Book</a>
Rewriting unreadable URLs
The default GATC records the URI directly from your browser address bar and display it in the reports as the pageview. That is, complex or dynamic URLs can look totally meaningless to human readers. You can prevent these unfriendly URL structures by using virtual pageviews.
A complex URL with query parameters :
So your GA reports will show this URL as shown below :
To correct this for the page in question, simply edit the _trackPageview call in the GATC section of your source-code by adding quoted strings that contain the virtual pageview and path, as show below :
_gaq.push(['_trackPageview', '/products/books/french/novels']);
By doing so you’re bringing clarity and ease of use to your reports, making them much easier to read and interpret ! The URL we modified above will for sure look much clearer in your analytics insights :
NB : use this technique to rewrite only URLs that are necessary to you ! Also, using virtual pageviews will break the In-Page reports – indeed these pages don’t really “exist” on your website. But to me the greater readability brought by virtual pageviews clearly outweighs the loss of this feature…
Tracking partially completed forms
This option can be particularly useful if you have long or multipage forms. Using virtual pageviews allows you to see where visitors bail out before getting to the Submit button. This will be tracked via creating a Funnel, and using the onBlur event handler in you HTML form fields as shown below :
<form action="" method="post" name="SignUp">

<input type="text" name="firstname"
onBlur="if(document.SignUp.firstname.value !='');
_gaq.push(['_trackPageview', '/forms/signup/firstname'])">

<input type="text" name="lastname"
onBlur="if(document.SignUp.lastname.value !='');
_gaq.push(['_trackPageview', '/forms/signup/lastname'])">

<input type="text" name="email"
onBlur="if( !='');
_gaq.push(['_trackPageview', '/forms/signup/email'])">

The if() !=” statement aims at confirming that each form field has content before the virtual pageview is created. Since not all fields will be compulsory in your form for the users, use this if statement appropriately.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s