Tracking Virtual Pageviews in Google Tag Manager – Complete Guide

Quick recap of virtual pageviews

Virtual pageview is that pageview hit, which you send to Google Analytics, without loading a web page in your web browser.

By default, a pageview hit is sent to GA, when:

#1 You refresh a web page (on which Google Analytics tracking code is installed) in your web browser or

#2 You navigate to a new web page (on which Google Analytics tracking code is installed) in your web browser.

In that case the URL of a web page changes in the browser address bar.

Now there are many websites which use ajax to load new contents on a web page.

The new contents are loaded without page refresh and/or without navigating to a different web page (thus no change in the URL of a web page in the browser address bar).

So when new contents are loaded on a web page via ajax, (by default) no pageview hit is sent to GA.

This makes tracking users interactions on Ajax based websites, very difficult in Google Analytics.

In this situation, you can use virtual pageviews, which can be triggered, when new contents are loaded on a web page via ajax.

In fact, any user interaction which is equivalent to a page being viewed, can be tracked via virtual pageviews.

Following are such users interactions:

  • Loading of a new single page checkout step
  • Loading of popups or light boxes.
  • Downloading a file.
  • Scrolling down a page
  • Loading new text contents on a web page via ajax

One advantage of virtual pageviews over events is that, when you set up goals in GA, you can use virtual pageviews as funnel steps in Google Analytics.

You can’t use tracked events as funnel steps while setting up goals in GA.

Get the E-book (72 Pages)

Get the E-Book (62 Pages)

 


Before you Start tracking virtual pageviews via Google Tag Manager


Before you start tracking virtual pageviews via Google Tag Manager (GTM), make sure that you have enabled all the ‘built-in variables‘ of type: Pages, Clicks and Forms.

By doing that these variable will be available to you, when you create tags and triggers later on.

Follow the steps below:

Step-1: Navigate to your GTM account, click on the ‘Variables’ link (in the left hand side navigation):

Step-2: Click on the ‘Configure’ button:

 

Step-3: Enable all the ‘built-in variables’ of type: Pages, Clicks and Forms:


Sending virtual pageview to Google Analytics when a user click on a link


In order to track clicks on a link (say a link through which user can download wedding planning checklist) via virtual pageviews in GTM, you would need to take following steps:

#1 Find the web page which contains the download link you want to track via GTM and note down the URL.

#2 Find the ID attribute of the download link. If the ‘ID’ attribute is missing then ask your developer to add one.

#3  Create a trigger in GTM which can check click on the download link.

#4 Create a tag which send virtual pageview to Google Analytics when a user click on the download link.

Following is the example of a download link on a web page:

<a id="checklist" href="http://www.realsimple.com/weddings/weddings-planning/wedding-planning-checklist">Download Wedding Planning Checklist</a>

Fig. Link

In order to send virtual pageviews to GA, when a user click on the link, follow the steps below:

Step-1: Navigate to the web page (in Google Chrome browser) which contains the link you want to track via GTM and then note down the URL of the web page.

Step-2: Right click on the link and select ‘Inspect‘ from the drop down menu:

inspect

You will now see the Google developer console window at the bottom of the page.

This window should show the ID attribute of the download link:id checklist

Note: If the ‘ID’ attribute is missing then ask your developer to add one.

Step-3: Note down the value of the ‘id’ attribute of the anchor tag (<a>). In our case, it is ‘checklist‘. You will need this ‘id’ later on, while setting up triggers in GTM. If you can’t find the ‘ID’ attribute then you would need to add one.

Step-4: Navigate to your Google Tag Manager account and create a new trigger with following similar configurations:

Trigger Name: Check for click on the download link

Trigger Type: Click – Just links

Check Validation

Enable this trigger when:

Page URL equals <<enter the URL of the page where the link you want to track is embedded>>

This trigger fires on: Some link clicks

Click ID equals <<enter the ID of your <a> element>>

Note(1): ‘Check Validation‘ ensure that the trigger fires on successful link click and not just when a user try to click the link.

Note(2): If you are not sure what trigger is and how to create a new trigger in GTM, then read this article: Understanding Triggers and Variables in Google Tag Manager

Note(3): ‘Page URL’ is a built-in variable of GTM which returns the URL of a web page.

Note(4): ‘Click ID’ is a built-in variable in GTM which returns the ‘id’ attribute of the link clicked.

Step-5: Create a new tag with following similar configuration, which send virtual pageviews to GA when a user click on the download link:

Tag Name: Send virtual pageviews on click on download link

Tag Type: Universal Analytics

Track Type: Pageview

Google Analytics Settings: << Use your Google Analytics Settings Variable>>

Enable overriding settings in this tag

Choose Product: Google Analytics

Fields to Set:

campaignMedium<<Enter campaign medium>>

(For example: user activity)

campaignSource<<Enter campaign source>>

(For example: link click)

page<<Enter the name of your virtual pageview>>

(For example:/virtual/forming-event-company/downloadLinkClick)

title<<Enter the page title of virtual page>>

(For example: Virtual – Download Link Click – Forming event company)

Firing Triggers: Check for click on the download link

Note(1): You can select fields like: campaignMedium, campaignSource, page and title from the drop down menu:

drop down menu

Note(2): CampaignMedium, campaignSource, page and title are all built-in variables in GTM.


Virtual Pageview Field Name – CampaignMedium


‘CampaignMedium’ GTM variable is used to specify the medium of a marketing campaign.

In case of virtual pageviews, use this variable to specify the medium of your virtual pageviews.

I created and used ‘user activity‘ as a medium.

This is because, a virtual pageview is generated as result of a user activity.

So traditional traffic mediums like: organic, CPC, direct, referral etc are not the best way to represent the medium in this particular case.

The other reason is, I do not want to mix data related with virtual pageviews with other website usage data.

It is important, that you specify the medium of your virtual pageviews.

Otherwise you will see medium set to ‘(none)’ in your GA reports:

medium none


Virtual Pageview Field Name – CampaignSource


‘CampaignSource’ GTM variable is used to specify the source of a marketing campaign.

In case of virtual pageviews, use this variable to specify the source of your virtual pageviews.

I created and used ‘link click‘ as a source, so that I can determine from GA reports, which user activity resulted in virtual pageview.

Using traditional traffic sources like: Google, facebook, bing etc are not relevant, in this particular case.

The other reason is, I do not want to mix data related with virtual pageviews with other website usage data.

It is important, that you specify the source of your virtual pageviews.

Otherwise you will see source set to ‘direct’ in your GA reports:

source direct


Virtual Pageview Field Name – page


‘page’ GTM variable is used to specify the path portion of a URI. Its value should start with forward slash ‘/’.

In case of virtual pageviews, use this variable to specify the name of your virtual pageviews.

Since ‘virtual page views’ are not highlighted as ‘virtual’ any where in the Google Analytics reports, I use the word ‘virtual’ somewhere in the virtual pageview name, so that I can easily differentiate them from regular pageviews, in my GA reports.

I created and used ‘/virtual/forming-event-company/downloadLinkClick‘ as a ‘path’,

The characters ‘/virtual/’ at the start of the virtual pageview name, make it easy to determine, that it is a virtual pageview.

The next set of characters ‘forming-event-company/’ denotes the name of the web page, where this virtual pageview was triggerd.

The next set of characters ‘downloadLinkClick/’ denotes the type of virtual page view.

In my case, it is the click on a link which results in a download.


Virtual Pageview Field Name – title


‘title’ GTM variable is used to specify the title attribute of a web page.

In case of virtual pageviews, use this variable to specify the title attribute of your virtual page.

Since ‘virtual page views’ are not highlighted as ‘virtual’ any where in the Google Analytics reports, I use the word ‘virtual’ somewhere in the virtual pageview name, so that I can easily differentiate them from regular pageviews, in my GA reports.

I created and used ‘Virtual – Download Link Click – Forming event company‘ as a ‘title’, so that I can see data for virtual pages by page title in ‘All Pages’ report (under Behavior > Site Content):

It is important, that you specify the title attribute of your virtual pages.

Otherwise the ‘title’ attribute will be set to the title of the web page, on which the virtual pageview was triggered and you will have a hard time understanding the performance of virtual pages via the ‘All pages’ report:

page title


 

Step-6: Preview your container to make sure that the new tag fires when you click on the download link.

Check the Google developer console window, to check what data the tag is sending out to GA:

fields virtual pageviews

Step-7: If everything is working as intended then publish the new version of your container.

Step-8: Click on the download link once again and test whether the virtual pageview data is being sent to Google Analytics via Real Time Content report:

real time report


Sending virtual pageview to Google Analytics when a user click on an image link


In order to track clicks on a image link (say a image link through which user can download wedding planning checklist) via virtual pageviews in GTM, you would need to take following steps:

#1 Find the web page which contains the image link you want to track via GTM and note down the URL.

#2 Find the ID attribute of the image link

#3 Create a trigger in GTM which can check click on the image link

#4 Create a tag which send virtual pageview to Google Analytics when a user click on the image link.

Following is the example of an image link (link in the form of an image):

<a href="http://www.realsimple.com/weddings/weddings-planning/wedding-planning-checklist"><img id="checklist3" src="https://summerschoolblogdotcom1.files.wordpress.com/2014/08/google-drive-download-button.png?w=600" /></a>
image link

image link

In order to track clicks on the image link via virtual pageviews, follow the steps below:

Step-1: Navigate to the web page (in Google Chrome browser) which contains the image link you want to track via GTM and note down the URL of the web page.

Step-2: Find and note down the ‘id’ attribute of the image link. If the ‘ID’ attribute is missing, then add one.

Step-3:Navigate to Google Tag Manager and create a new trigger with following similar configurations:

Trigger Name: Check for click on the download link

Trigger Type: Click – All Elements

This trigger fires on: Some Clicks

Fire this trigger when an Event occurs and all of these conditions are true:

Page URL equals <<enter the URL of the page where the image link you want to track is embedded>>

Click ID equals <<enter the ID of your image link>>

Note: Since we are using the ‘id’ attribute of the image tag instead of the ‘id’ attribute of <a> tag, we need to set the ‘Trigger type’ to ‘Click -All Element’. In GTM, if you want to track any HTML element other than a link, then you set the ‘Trigger type’ to ‘Click -All Element’.

Step-4: Create a new tag with following similar configuration, which send virtual pageviews when a user click on the image link:

Tag Name: Send Virtual pageview on click on the image download link

Tag Type: Universal Analytics

Track Type: Pageview

Google Analytics Settings: << Use your Google Analytics Settings Variable>>

Enable overriding settings in this tag

Choose Product: Google Analytics

Fields to Set:

campaignMedium<<Enter campaign medium>>

(For example: user activity)

campaignSource<<Enter campaign source>>

(For example: image link click)

page<<Enter the name of your virtual pageview>>

(For example:/virtual/forming-event-company/downloadImageLinkClick)

title<<Enter the page title of virtual page>>

(For example: Virtual – Download Image Link Click – Forming event company)

Firing Triggers: Check for click on the image download link.

Step-5: Preview your container, click on the image link and test whether the virtual pageview data is being sent to Google Analytics, via real time content reports:

virtual image click

Step-6: Publish your new container.


Sending virtual pageview to Google Analytics when a user click on a button


In order to track clicks on a button (say a button through which user can download wedding planning checklist) via virtual pageviews in GTM, you need to do the following:

#1 Find the web page which contains the download button you want to track via GTM and note down the URL.

#2 Find the ID attribute of the download button.

#3 Create a trigger in GTM which can check click on the download button.

#4 Create a tag which send virtual pageview to Google Analytics when a user click on the download button.

Following is an example of a button:

<button id="checklist4" type="button" onClick='location.href="http://www.realsimple.com/weddings/weddings-planning/wedding-planning-checklist"'>Download</button>

button

In order to track clicks on the button via virtual pageviews, follow the steps below:

Step-1: Navigate to the web page which contains the download button you want to track via GTM and note down the URL of the web page.

Step-2: Find and note down the ‘id’ attribute of the button. If the ‘ID’ attribute is missing, then add one.

Step-3: Navigate to Google Tag Manager and create a new trigger with following similar configurations:

Trigger Name: Check for click on the download button

Trigger Type: Click – All Elements

This trigger fires on: Some Clicks

Fire this trigger when an Event occurs and all of these conditions are true:

Page URL equals <<enter the URL of the page where the button you want to track is embedded>>

Click ID equals <<enter the ID of your button element>>

Step-4: Create a new tag with following similar configuration, which send virtual pageviews when a user click on the download button:

Tag Name: Send virtual pageview on click on download button

Tag Type: Universal Analytics

Track Type: Pageview

Google Analytics Settings: << Use your Google Analytics Settings Variable>>

Enable overriding settings in this tag

Choose Product: Google Analytics

Fields to Set:

campaignMedium<<Enter campaign medium>>

(For example: user activity)

campaignSource<<Enter campaign source>>

(For example: button click)

page<<Enter the name of your virtual pageview>>

(For example:/virtual/forming-event-company/downloadButtonClick)

title<<Enter the page title of virtual page>>

(For example: Virtual – Download Button Click – Forming event company)

Firing Triggers: Check for click on the download button

Step-5: Preview and publish your container.


Sending virtual pageview to Google Analytics when a user click on a button embedded across a website


The whole process of sending virtual pageview when a user click on the download button, which is embedded across a website (instead of just one particular page) is similar to sending virtual pageview, when a user click on a button, embedded on a single page.

The only difference is that, when you create the trigger, you set the ‘Page URL‘ to .* so that trigger can fire on any page of your website.

For example:


Sending virtual pageview to Google Analytics when a user click on a Form submit button


In order to track clicks on a form submit button via virtual pageviews in GTM, you need to do the following:

#1 Find the web page which contains the form and note down the URL.

#2 Find the ID attribute of the form.

#3 Create a trigger in GTM which can check click on the form submit button.

#4 Create a tag which send virtual pageview to Google Analytics when a user click on the form submit button.

Following is an example of a form with three input elements and a submit button:

<form id="gform_1" action="http://www.realsimple.com/weddings/weddings-planning/wedding-planning-checklist">
Username: <input type="text" id="username"><br>
Password: <input type="text" id="password"><br>
Email: <input type="text" id="email"><br>
<input id="submitButton" type="submit" value="Submit">
</form>

form

To track form submissions on a website via virtual pageviews, follow the steps below:

Step-1: Navigate to the web page which contains the form and note down the URL of the web page:

note down page url

Step-2: Find and note down the ‘id’ attribute of the form. To find your form id, right click on the form, select ‘Inspect Element’ (Google Chrome) and look for ‘id’ attribute in the <form> tag:

form idIn my case, the form ID is ‘gform_1’. If the ‘ID’ attribute is missing, then add one.

Step-3:  Navigate to Google Tag Manager and create a new trigger with following similar configurations:

Trigger Name: Check for click on the form submit button

Trigger Type: Form Submission

Check Validation

Enable this trigger when all of these conditions are true:

Page URL equals <<enter the URL of the page where your form is embedded>>

This trigger fires on: Some Forms

Fire this trigger when an Event occurs and all of these conditions are true:

Form ID equals <<enter the ID of your embedded form>>

Note(1): If your form is embedded on several pages across your website, then set the ‘Page URL‘ to .* as explained earlier.

Note(2): Make sure that ‘check validation‘ option is checked.  This is done to ensure that the trigger fires on successful form submission and not just when a user clicks on the form submit button.

Note(3): ‘Form ID’ is a built-in variable of GTM which returns the ‘id’ attribute of a form.

Step-4: Create a new tag with following similar configuration, which send virtual pageviews when a user click on the form submit button:

Tag Name: Send virtual pageview on click on the form submit button

Tag Type: Universal Analytics

Track Type: Pageview

Google Analytics Settings: << Use your Google Analytics Settings Variable>>

Enable overriding settings in this tag

Choose Product: Google Analytics

Fields to Set:

campaignMedium<<Enter campaign medium>>

(For example: user activity)

campaignSource<<Enter campaign source>>

(For example: form submit click)

page<<Enter the name of your virtual pageview>>

(For example:/virtual/forming-event-company/formSubmitClick)

title<<Enter the page title of virtual page>>

(For example: Virtual – Form Submit Click – Forming event company)

Firing Triggers: Check for click on the form submit button

Step-5: Preview and publish your container.


Tracking Single page checkout steps via virtual pageviews in Google Analytics


In case of a single page checkout steps, individual steps are usually loaded via ajax using jQuery.

The whole process of checking single page checkout steps is quite similar to the process of tracking clicks on a link or a button via virtual pageview.

Generate a virtual pageview after each button/link click on a single page checkout and then set up sales funnel in Google analytics which include virtual pageviews as funnel steps:

final funnel1

final funnel2


Tracking sales funnel across websites via cross domain tracking and virtual pageviews


If you are using a third party shopping cart, where the final part of the checkout process occurs on a different website and you want to set up sales funnel in Google Analytics which starts on your website but ends on the third party shopping cart, then you can do that by:

#1 Setting up cross domain tracking between your website and the third party shopping cart

#2 Configure the destination domain (which host the shopping cart) to send virtual pageviews

cross domain tracking set up

To learn more about such tracking setup, read this article: Setting up Sales Funnel across websites in Google Analytics.

Related Articles:

#1 Virtual pageviews in Google Analytics – Complete Guide – in this article I introduced the concept of virtual pageviews in Google Analytics.

#2 Event Tracking in Google Tag Manager – Complete Guide – in this article I explained in great detail how to do event tracking via Google Tag Manager.

Learn about the Google Analytics Usage Trends Tool

The Google Analytics usage trend is a new tool which is used to visualise trends in your Google Analytics data and to perform trend analysis.


Take your knowledge of Web Analytics to the next level. Checkout my web analytics training course.

Take your Analytics knowledge to the next level. Checkout my Best Selling Books on Amazon

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Himanshu Sharma

Certified web analyst and founder of OptimizeSmart.com

My name is Himanshu Sharma and I help businesses find and fix their Google Analytics and conversion issues. If you have any questions or comments please contact me.

  • Over eleven years' experience in SEO, PPC and web analytics
  • Google Analytics certified
  • Google AdWords certified
  • Nominated for Digital Analytics Association Award for Excellence
  • Bachelors degree in Internet Science
  • Founder of OptimizeSmart.com and EventEducation.com

I am also the author of three books:

error: Alert: Content is protected !!