How to Track Virtual Page Views in Google Analytics
In our last free Google Analytics resource we looked at how to set up Goals in Google Analytics. Some of those goals required virtual page views to enable you to track user clicks on things that don't have a URL within the site that can be tracked in the usual way (e.g PDF downloads).
So - we thought it only fair to let you know how to set up Virtual Page views too!
Check out our step by step guide below. To learn about all of this in more depth and try it out hands on - why not come along to our next Google Analytics Training course here in Brighton?
What can Virtual Page Views be used for?
Virtual page views can be used to track clicks on any links that do not lead to a standard URL within your site. That includes:
- PDF downloads hosted on your site (you can't have the normal GA tracking code on a PDF!)
- Links to external sites
- Clicks on form buttons / popups where the URL doesn't change for the user (e.g if you have a dynamic form is all hosted on one page which you want to track the user's progress through)
- Click's on the "Play" button for video hosted on your site (you can also track pause, stop etc... - although we don't cover that here - check out Google's Event Tracking Guide on how to do that)
How to Set up Virtual Page Views in Google Analytics
Virtual page views will only work if you've got the most recent version of the Google Analytics tracking code (known as the async code) installed on your site, so first step is to make sure you've got it.
A quick way to check this is to visit a page on your site - right click somewhere on the page and select view page source (or whatever the equivalent is in your browser), and search for the phrase async in the code. If you find the line that includes ga.async = true; then you're already in business - ignore the next bit!
If you can't find that - you're using the old code and you'll need to update it.
How to find your 'async' Google Analytics Tracking Script
Log in to your Google Analytics account.
Hit the Edit button to the right of the profile you're using
Now (and this is a silly place to put it) look in the top right hand corner of the profile settings page where it says "check status"
Click on this and the tracking script for your account is there to copy and paste. If you're not sure where to paste it, check out our post on how to install the Google Analytics Tracking Code
How to track a Virtual Page View
If you know a little bit of HTML, this is pretty straightforward. You just need to add a little bit of code within the tag for the link or button that you are tracking the clicks on.
That code is:
So - if you want to track the number of people who are downloading a PDF, you might call your virtual page view "PRODUCTx-PDF-DOWNLOAD"
To show exactly where you should put the code - see the before and after code for the "Download PDF" button for our Google Analytics Course PDF below.
Without Virtual Page View Code
With Virtual Page View Code (in bold)
onclick="_gaq.push(['_trackPageview' ,'/google-analytics-PDF-Download/']);">Download PDF
With the above code in place, we're now able to start tracking how many people are clicking on the PDF download for our Google Analtytics course (and all of our other PDFs, which we've also applied this method to), which we wouldn't be able to do without virtual page views. Hurrah!
How to See the Results
Once you've implemented the code - your virtual page views will start showing up in your Google Analytics content report just like your 'normal' page views.
Simply go to your top content report and filter the results by the name of the virtual page (or pages) - and hey presto - tracking for things where tracking was not possible before:
Backblog comments powered by Disqus