Virtual Pageviews for Google Analytics

Caryn Farvour (Humphreys)
Vehikl News
Published in
2 min readFeb 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.

Step 1

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:

Step 2

Enable enhanced link attribution.

  1. Log in to Google Analytics
  2. Click Admin in the top navigation
  3. Choose the property you want to use enhanced link attribution for, and click Property Settings
  4. In the Basic Settings section, ensure that Default View is set to All Web Site Data
  5. In the In-Page Analytics section, turn Use enhanced link attribution to the on position
  6. Click Apply

Step 3

Apply the 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’

Virtual Pageviews seen as Pageviews in Analytics

Categorized under ‘virtual’ and then ‘home’ for easy searching and organization.

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.

Happy tracking!

Originally published at transmission.vehikl.com on February 25, 2014.

--

--

Caryn Farvour (Humphreys)
Vehikl News

UX Designer, UI Developer, PC gamer, bibliophile, board gamer, coffee drinker, painter, photographer, unapologetic smartass.