call +44 (0)1273 622272
Virtual PageViews 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?
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:
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.
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
If you know a little bit of HTML, this is pretty straightforward. You just need to add a little bit of code within the <a> tag for the link or button that you are tracking the clicks on.
That code is:
onclick=”_gaq.push(['_trackPageview, '/YOUR-CHOICE-OF-PAGE-VIEW-NAME-HERE']);”
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
<a href=”http://www.siliconbeachtraining.co.uk/downloads/courses/advanced-google-analytics-training-394.pdf” title=”Download Google Analytics Training course outline” target=”_blank”>Download PDF</a>
With Virtual Page View Code (in bold)
<a href=”http://www.siliconbeachtraining.co.uk/downloads/courses/advanced-google-analytics-training-394.pdf” title=”Download Google Analytics Training course outline” target=”_blank” onclick=”_gaq.push(['_trackPageview' ,'/google-analytics-PDF-Download/']);”>Download PDF</a>
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!
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:
![]()
how to set up virtual page view, how to track external links, how to track form submissions, how to track PDF downloads, setting up virtual pageview google analytics, virtual page view, virtual pageview, Web Analytics, what are virtual page views, why use virtual pageviews
Alex says:
Aaron,
You have an issue with the code you’re showing:
onClick=_gaq.push ([‘_trackPageView’,’/YOUR-CHOICE-OF-PAGE-VIEW-NAME-HERE’]);
_trackPageView won’t work. _trackPageview will.
I spent a good chunk of my time trying to figure what’s wrong with my tracking… :)
Cheers,
Alex
6. 9. 2012 at 10:25 am
Aaron Charlie says:
Thanks for pointing that out, sorry about the mistake! We should have noticed because we got it right in the example, just wrong in the code! All changed now.
6. 9. 2012 at 1:04 pm
David says:
Thank you for not only explaining the gaq push method bot giving concrete examples too :-)
1. 11. 2012 at 9:59 am
jen says:
Aron,
I noticed a difference in code can you tell me which is correct.
onClick=_gaq.push ([‘_trackPageview’
and
onclick=”_gaq.push([‘_trackPageview’
19. 3. 2013 at 2:59 pm
Aaron Charlie says:
Hi Jen,
It’s definitely the second one; we’ll make sure we change the first so they both match.
Thanks for letting us know :)
19. 3. 2013 at 3:42 pm
Dave Brewster says:
They’ve still not been changed.
There are multiple syntax versions in this post, with many contradictory elements.
21. 5. 2013 at 6:58 am
Craig Charley says:
Hi Dave, I’ve had a look into this and have updated both instances of the code to match what currently works on our site. I believe the original code was copied directly from Google’s own help pages (which have since changed), syntax errors and all.
21. 5. 2013 at 8:46 am