Essential Analytics: Event Tracking & Virtual Pageviews

By Joli Skow | January 2015

Google Analytics captures much of your site’s essential data right out of the box. For many websites, it'll track all your main metrics without much customization beyond setting up some goals. However, for other websites, what it won't track without customization can sometimes be some of your most important, impactful metrics. 

When this happens, it's important to understand the features of Google Analytics that you'll need to implement in order to capture the key data for your campaign: events & virtual pageviews.

Essential-Analytics-Events-Pageviews

Event Tracking

You can use a handy snippet of code to track anything on your website that you want to consider as an event. Some examples of things you’d want to keep track of as an event that Google Analytics doesn’t automatically track out of the box include:

  • Video plays
  • Clicks on links that lead away from your website
  • Clicks to download documents
  • Clicks on carousel or slider arrows
  • Clicks on buttons that bring up dynamic elements, like lightboxes or pop-out forms

When you set up something to track as an event, you’ll be able to see your captured data in the Behavior > Events area in Google Analytics. The best part about events is, you can label them in whatever way makes the most sense to you, and they’ll show up as such in your analytics.

For instance, let’s say you have a button on your site that triggers a case study PDF download when clicked. Event tracking requires you to create a Category, Action, and optional Label for every event. In this case, your category could be “button,” your action could be “click,” and your label could be “casestudypdf.” After implementing the event code, you’d see in analytics how many “casestudypdf” actions were completed, which corresponds to the number of clicks on your PDF download button.

In Universal Analytics, your code will look like this: ga(‘send’, ‘event’, ‘category’, ‘action’, ‘label’);

Or in our case: ga(‘send’, ‘event’, ‘button’, ‘click’, 'pdfdownload’);

For more on implementing event tracking code on your website, visit Google’s Developer Guide.

Virtual Pageviews

Like events, virtual pageviews allow you to track a piece of data you wouldn’t otherwise see in Google Analytics. However, the difference here is that setting up an action as a virtual pageview will trigger a pageview in Google Analytics, and you’ll begin to see your data in any of your regular Pages reports. You choose what action you’d like to be counted as a pageview, and what to call it, and Analytics takes care of the rest.

So, let’s say you have a long scrolling website (which is becoming an ever more popular web design trend). Clicking on one of the navigation buttons simply scrolls a visitor down your page, using anchor tags, to the right section, instead of opening another page. This click is not tracked by Analytics. Analytics works by reading the code on each page of your site, so simply scrolling down your page doesn’t trigger any reading of any code.

For instance, when someone clicks on your About button in your navigation, they’re scrolled down to www.yoursite.com/#about. Since this click is not tracked by Google Analytics, you won’t see any data about it. However, setting up the “About” button in your navigation as a virtual pageview with a page name of your choosing (probably something like /about) will show you that valuable data that you want to see within Pages reports. 5 clicks on “About” in your navigation will show up in Google Analytics as 5 pageviews for /about, even though that page doesn’t exist on your site.

Keep in mind that virtual pageviews will also affect your bounce rate. With a one-page scrolling website, visitors probably won’t visit a second page on your site and technically count as a bounce when they leave. Setting up virtual pageviews will turn clicks into pageviews, so a user is more likely to visit more than one “page” on your website during a visit.

To implement virtual pageviews on anchor tags like in the above example, using the Universal version of Google Analytics, your code would look like this:

<a href="#about" title="About" onClick="ga('send', 'pageview', 'about')">About Us</a>

This code tells Google Analytics that, upon clicking this link, a pageview called “/about” should be sent/captured. You will always use ‘send’ and ‘pageview’, but the slug can be whatever you’d like, and corresponds to what you’ll see in your Analytics data. If you input ‘about-us-home-nav-click’, in your analytics you’ll see visits for /about-us-home-nav-click.

A Real-Life Example

The long scrolling site in the screenshot below utilizes virtual pageviews. A click on any of the navigation buttons just scrolls you down the page, rather than opening a new page. Virtual pageview tracking to the rescue!

Screen_Shot_2015-01-22_at_3.18.28_PM

Setting up the navigation with virtual pageviews looks like this, behind the scenes:

Screen_Shot_2015-01-22_at_3.25.58_PM

After implementing our virtual pageview code, Google Analytics will capture the pageview data you told it that you want. After a couple days, navigating to the Behavior > Site Content > All Pages report will show you the click data you're looking for. See how the slugs I used in my code are showing up as pages viewed?

Pageview

 

Modifications

The above examples are the simplest (believe it or not) ways and instances in which to use Event and Virtual Pageview tracking code snippets. These code snippets can be modified in many different ways, depending on what you want to track and how you want it to show up in Analytics.

Need help setting up your Google Analytics to track what you’d like it to track? Let us know!

Topics: Digital Marketing