Virtual Pageviews for Google Analyticsby Caryn Humphreys on February 25, 2014
The Scenario: You have built a beautiful single-page website or web application, and you’ve included the traditional Google Analytics tracking snippet:
The Problem: Having only the one page, you are only seeing one metric for pageviews in Analytics – hits on your index page. The Solution: Asynchronous tracking and Virtual Pageviews.
Replace the above mentioned traditional tracking snippet with the Asynchronous Google Analytics snippet (below) (Google recommends including this just before the closing </head> tag.) Copy the snippet below and replace the
UA-XXXXX-X with your web property ID:
To use Enhanced Link Attribution, the above code needs a minor modification:
Enable enhanced link attribution.
- Log in to Google Analytics
- Click Admin in the top navigation
- Choose the property you want to use enhanced link attribution for, and click Property Settings
- In the Basic Settings section, ensure that Default View is set to All Web Site Data
- In the In-Page Analytics section, turn Use enhanced link attribution to the on position
- Click Apply
onclick event on elements you’d like to track.
So when a user clicks on the above link, Google Analytics will generate a virtual pageview called ‘/virtual/home/work’
You can organize your virtual pageviews into any number of virtual categories you like. If, for example, you have PDF downloads you’d like to track, you could write it as: ‘/downloads/pdf/google-analytics-for-dummies.pdf’ Use as many or as few hierarchy categories as you feel are necessary.
You can read more about Virtual Pageviews on Google.