Creating Virtual Pageviews with Google Analytics Asynchronous Tracking

Posted on December 9th, 2009 in Expert Tips, Featured, How To, Web analytics by Lorrin

Last week Google announced their asynchronous tracking for Google Analytics. This tracking is different in many ways: loads faster; code can be placed in the header rather than the bottom of the page; better uptime; and more. With the ability to place the analytics in the header the data is being recorded accurately because it is the first thing to load when someone visits the page. The previous snippet was placed at the bottom of the page; we would have to wait until the other javascripts were executed before it loaded. That meant if some other javascript was broken or someone left the page quickly, Google Analytics would not record the data.

Google has issued new instructions on how to create specialized implementations; however, one of the most commonly used features—virtual pageviews—is left out of the instructions. Virtual pageviews allows the analytics admin to track various elements of the page such as outbound clicks, form fields, downloads, etc.

By modifying the event tracking, I was able to create virtual pageviews.

The examples below show the original and async analytics code, as well as instructions for implementing virtual pageviews.

Old Google Analytics Script with placement

<!--Google Analytics-->
 
<script type="text/javascript"><!--mce:0--></script>
<script type="text/javascript"><!--mce:1--></script>
 
<!--Google Analytics-->

New Asynchronous Google Analytics Script with placement

<!--Google Analytics-->
<script type="text/javascript"><!--mce:2--></script>
<!--Google Analytics-->

Original Script for How to Implement a Virtual Pageview

<a onclick="javascript: pageTracker._trackPageview ('/easyidentifier');" href=" http://www.someurl.com/">Click Here</a>

New Asynchronous Tracker Script for Google Analytics

<a onclick="javascript: _gaq.push(['_trackPageview', '/easyidentifier']);" href="http://www.someurl.com/">Click Here</a>

From the above examples, place original and async analytics in the header and replace the pagetracker part of the code with _gaq.push. The virtual pageviews are still placed within the element that you wish to track. The ”easyidentifier” in the virtual pageview signifies what the link will be titled as within the reports. Remember to mark your virtual pageviews with some kind of identifier to distinguish it from your actual pages (e.g., /outbound,/link or /external). This will make it easier to find them and possibly make into a goal.

If you need help with implementation of GA’s new features, write out your issues in the comments section and I’ll be happy to walk you through them.

~Lorrin

Share/Save/Bookmark
Lorrin

6 Responses to 'Creating Virtual Pageviews with Google Analytics Asynchronous Tracking'

Subscribe to comments with RSS or TrackBack to 'Creating Virtual Pageviews with Google Analytics Asynchronous Tracking'.


  1. on December 11th, 2009 at 9:43 am

    [...] Creating Virtual Pageviews with Google Analytics Asynchronous Tracking [...]


  2. on January 9th, 2010 at 9:07 pm

    Thanks For this code snipet. I use virtual pageviews all the time .. I wish Google would have clarifeid this in their help docs but instead I found it on your site .. Thanks!

    If you name all of your outgoing links or affiliate links the same — you can some some fancy jquery code to save you time http://fieldsmarshall.com/8-tips-for-tracking-with-google/

    anyways thanks


  3. on January 21st, 2010 at 3:41 pm

    [...] Creating Virtual Pageviews with Google Analytics Asynchronous Tracking [...]


  4. on February 2nd, 2010 at 3:51 am

    [...] Usage GuideMake Google Analytics Load Faster With Asynchronous Tracking -  by Patrick Altoft Creating Virtual Pageviews with Google Analytics Asynchronous Tracking -by Lorrin AKPC_IDS += "1195,";If You Enjoyed This Post Subscribe to Our RSS Feed!!!Share This [...]

  5. Brian said,

    on February 3rd, 2010 at 8:18 pm

    FYI – the javascript: protocol prefix is 100% unnecessary

  6. Lorrin said,

    on February 4th, 2010 at 10:40 am

    Hi Brian,

    I use the javascript: protocol because when I do not use it the virtual pageview does not work. Only with this protocol I can guarantee that it will work. Thanks

Post a comment