Tracking Virtual Pageviews in Google Tag Manager – Tutorial
Quick recap of virtual pageviews
A 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:
- You refresh a web page (on which Google Analytics tracking code is installed) in your web browser or
- 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 that use Ajax to load new content 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).
When new content is 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 content is 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 lightboxes.
- 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.
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 variables 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 clicks 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 the ‘click on the download’ link.
#4 Create a tag that sends a virtual pageview to Google Analytics when a user clicks 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>
In order to send virtual pageviews to GA, when a user clicks 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:
You will now see the Google developer console window at the bottom of the
e page.
This window should show the ID attribute of the download link:
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 sends virtual pageviews to GA when a user clicks on the download link:
Tag Name: Send virtual pageviews on click on the 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:
Note(2): CampaignMedium, campaignSource, page and title are all built-in variables in GTM.
Virtual Pageview Field Name – CampaignMedium
The ‘CampaignMedium’ GTM variable is used to specify the medium of a marketing campaign.
In the 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 a result of 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 to 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:
Virtual Pageview Field Name – CampaignSource
The ‘CampaignSource’ GTM variable is used to specify the source of a marketing campaign.
In the 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 to 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:
Virtual Pageview Field Name – page
The ‘page’ GTM variable is used to specify the path portion of a URI. Its value should start with a forward slash ‘/’.
In the case of virtual pageviews, use this variable to specify the name of your virtual pageviews.
Since virtual pageviews are not highlighted as ‘virtual’ anywhere 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 triggered.
The next set of characters ‘downloadLinkClick/’ denotes the type of virtual pageview.
In my case, it is the click on a link that results in a download.
Virtual Pageview Field Name – title
The ‘title’ GTM variable is used to specify the title attribute of a web page.
In the case of virtual pageviews, use this variable to specify the title attribute of your virtual page.
Since virtual pageviews are not highlighted as ‘virtual’ anywhere 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:
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:
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:
Sending virtual pageview to Google Analytics when a user clicks on an image link
In order to track clicks on an image link (say an 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 that sends a virtual pageview to Google Analytics when a user clicks 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>
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 sends virtual pageviews when a user clicks 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:
Step-6: Publish your new container.
Sending virtual pageview to Google Analytics when a user clicks 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 that sends a virtual pageview to Google Analytics when a user clicks 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>
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 sends virtual pageviews when a user clicks 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 clicks on a button embedded across a website
The whole process of sending virtual pageview when a user clicks 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 clicks 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 clicks 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 that sends a virtual pageview to Google Analytics when a user clicks 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>
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:
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:
In 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 sends virtual pageviews when a user clicks 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 the case of a single page checkout step, 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 includes virtual pageviews as funnel steps:
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
To learn more about such a tracking setup, read this article: Setting up Sales Funnel across websites in Google Analytics.
Things to consider before tracking virtual pageviews in Google Analytics
There has been lots of discussion among the analytics experts on whether virtual pageviews are good or bad. So, the question arises: Event vs Virtual Pageviews
Event tracking is straight forward and simple option for tracking user interaction on a webpage, like a link click, download, media play pause, scroll tracking, etc.
Another benefit of using event tracking is that it does not affect the bounce rate and is tracked separately from pageviews. You can check all events in Google Analytics under the behavior tab with details like event category, event action and event label. But the drawback of events is that you cannot use events in setting up funnels in Google Analytics.
Virtual pageviews can give the actual user journey on the website by triggering virtual pages in funnels and thus allows you to check goal flow, reverse goal path and user path across different components of a website.
As we have seen above, we can set virtual pageviews for any event, such as link click, image click, button click, form submission and on dynamic Ajax for single page applications as well. But virtual pageviews are also treated as normal pageviews in Google Analytics and hence virtual pageviews increase the overall pageview count of the website.
As virtual pageviews are also added into the overall pageview count, it reduces the bounce rate and increases pages per session count. There is no separate report in Google Analytics for virtual pageview, so if you have lots of virtual pageviews, it severely affects the bounce rate and increases pages per session
In a nutshell, it is really dependent on what scenario you are tracking virtual pageviews. In general, event tracking is the best option to go with but, in the case that you have a single page website and wanted to track user journeys in a funnel, virtual pageviews can be a good option. Also if you want a complete analysis of user journeys in a funnel, virtual pageview are the best option to consider.
Tips to get the best out of virtual pageviews in Google Analytics
So the downsides of virtual pageviews are not actually drawbacks in every case, but it is true that virtual pageviews affects the default pageview count, reduce the bounce rate and increase the pages per session count. In order to get the most out of your virtual pageview tracking, the following tips could be beneficial
Tip1: Adding ‘Virtual’ word or prefix in URL
You can do this by using fields in Google Tag Manager and set the page to value “virtual/downloadlinkclick”. The text in double-quotes will represent the URL of the virtual page.
Additionally, you can add a title field with the value “Virtual-Download link click”. The text in double-quotes will appear as the title of the virtual page
By using ‘virtual’ as a prefix or part of the url you can easily identify all your virtual pages in Google Analytics reports.
Tip2: Create a separate view in Google Analytics to exclude all virtual pageviews so that you can get your actual default pageview count and not affect other metrics.
As we have seen, lots of virtual pageviews can affect the default pageview count of a website, bounce rate and increased pages per session. It is best to create a separate view which will exclude all virtual pageviews. This view will give you the actual default page view, exact bounce rate and correct avg pages per session.
To create a separate view excluding virtual pageviews, follow the following steps:
Step 1: Go to ‘Admin’ setting of Google Analytics, select the appropriate property and click on ‘Create View’.
Step 2: Give a name such as “Excluding Virtual Page View”, select your reporting timezone and click on ‘Create View’.
Step 3: Once the view is created click on the ‘View’ setting in admin console and then click on ‘Filters’.
Step 4: Click on ‘Add Filter’, select ‘Custom’, select the ‘Exclude’ option. Then select ‘Page Title’ in the filter field and add “virtual” in the filter pattern. Click ‘Save’.
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.
Other articles on specialized tracking in Google Analytics
- How to see Organic Search Keywords in GA4 (Google Analytics 4)
- Google Analytics Ecommerce Tracking Tutorial
- Google Tag Manager Event Tracking Tutorial
- Google Analytics Event Tracking Tutorial
- Google Analytics Store Visits Tracking Tutorial
- Offline Conversion Tracking in Google Analytics – Tutorial
- Ecommerce Tracking Google Tag Manager (GTM) – Tutorial
- Tracking Virtual Pageviews in Google Tag Manager – Tutorial
- Google Tag Manager YouTube Video Tracking
- Google Analytics Virtual Pageviews Tutorial
- Google Analytics YouTube Integration & Analysis Tutorial
- Google Analytics for Facebook Tutorial
- Cross Domain Tracking in Google Analytics – Complete Guide
- How to use two Google Analytics codes on one page
- How to correctly use referral exclusion list in Google Analytics
- Google Analytics Calculated Metrics – Tutorial
- Creating your own Google Analytics Tag Auditing System
- Google Tag Manager Search Tracking without Query Parameter
- Tracking Google Analytics Paypal Referral and other payment gateways
- How to Track Phone Calls in Google Analytics 4 – Call Tracking Tutorial
- How to track leads in Google Analytics via CRM
- Postbacks in Google Analytics Explained
- Subscription & Recurring Revenue Analytics in Google Analytics
- Track the Impact of Google Analytics Cookie Consent on Website Traffic
- Tracking Offline Conversions in Google Ads
- Implementing Scroll Tracking via Google Tag Manager
- Scroll Depth Tracking in Google Tag Manager – Tutorial
- Site Search Tracking In Google Analytics Without Query Parameters
- Google Tag Manager Youtube Video Tracking via YouTube Video Trigger
- How to Correctly Measure Conversion Date & Time in Google Analytics
- Google Analytics Social Tracking – Twitter, Facebook, Google Plus and LinkedIn
- Cross Domain Tracking in Google Analytics – Complete Guide
- Google Analytics Linkedin & Twitter Tracking
- Creating Content Group in Google Analytics via tracking code using gtag.js
- Google Analytics Site Search Tracking via Query Parameters
- Google Analytics Site Search Tracking Tutorial
- Creating and Using Site Search Funnel in Google Analytics
- How to add Facebook Pixel to Google Tag Manager
- AMP Google Analytics Tracking – Learn to track AMP pages
- Setting up Sales Funnel across websites in Google Analytics
- Google Analytics 4 Regex (Regular Expressions) Tutorial
Frequently Asked Questions for Tracking Virtual Pageviews in Google Tag Manager – Tutorial
What is a virtual pageview?
A virtual pageview is that pageview hit, which you send to Google Analytics without loading a web page in your web browser.
When new content is loaded on a web page via Ajax, no pageview hit is sent to GA (by default). 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 content is loaded on a web page via Ajax.
What type of user interactions can be tracked with virtual pageviews?
Any user interaction which is equivalent to a page being viewed can be tracked via virtual pageviews. For example:
– Loading of a new single-page checkout step
– Loading of popups or lightboxes.
– Downloading a file.
– Scrolling down a page
– Loading new text contents on a web page via Ajax
Are there any benefits of using virtual pageviews over event tracking?
There has been lots of discussion among the analytics experts on whether virtual pageviews are good or bad. So, the question arises: Event vs Virtual Pageviews.
In general, event tracking is the best option to go with but the drawback of events is that you cannot use events in setting up funnels in Google Analytics.
Virtual pageviews can give the actual user journey on the website by triggering virtual pages in funnels and thus allows you to check goal flow, reverse goal path and user path across different components of a website.
Quick recap of virtual pageviews
A 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:
- You refresh a web page (on which Google Analytics tracking code is installed) in your web browser or
- 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 that use Ajax to load new content 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).
When new content is 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 content is 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 lightboxes.
- 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.
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 variables 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 clicks 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 the ‘click on the download’ link.
#4 Create a tag that sends a virtual pageview to Google Analytics when a user clicks 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>
In order to send virtual pageviews to GA, when a user clicks 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:
You will now see the Google developer console window at the bottom of the
e page.
This window should show the ID attribute of the download link:
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 sends virtual pageviews to GA when a user clicks on the download link:
Tag Name: Send virtual pageviews on click on the 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:
Note(2): CampaignMedium, campaignSource, page and title are all built-in variables in GTM.
Virtual Pageview Field Name – CampaignMedium
The ‘CampaignMedium’ GTM variable is used to specify the medium of a marketing campaign.
In the 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 a result of 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 to 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:
Virtual Pageview Field Name – CampaignSource
The ‘CampaignSource’ GTM variable is used to specify the source of a marketing campaign.
In the 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 to 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:
Virtual Pageview Field Name – page
The ‘page’ GTM variable is used to specify the path portion of a URI. Its value should start with a forward slash ‘/’.
In the case of virtual pageviews, use this variable to specify the name of your virtual pageviews.
Since virtual pageviews are not highlighted as ‘virtual’ anywhere 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 triggered.
The next set of characters ‘downloadLinkClick/’ denotes the type of virtual pageview.
In my case, it is the click on a link that results in a download.
Virtual Pageview Field Name – title
The ‘title’ GTM variable is used to specify the title attribute of a web page.
In the case of virtual pageviews, use this variable to specify the title attribute of your virtual page.
Since virtual pageviews are not highlighted as ‘virtual’ anywhere 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:
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:
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:
Sending virtual pageview to Google Analytics when a user clicks on an image link
In order to track clicks on an image link (say an 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 that sends a virtual pageview to Google Analytics when a user clicks 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>
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 sends virtual pageviews when a user clicks 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:
Step-6: Publish your new container.
Sending virtual pageview to Google Analytics when a user clicks 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 that sends a virtual pageview to Google Analytics when a user clicks 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>
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 sends virtual pageviews when a user clicks 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 clicks on a button embedded across a website
The whole process of sending virtual pageview when a user clicks 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 clicks 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 clicks 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 that sends a virtual pageview to Google Analytics when a user clicks 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>
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:
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:
In 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 sends virtual pageviews when a user clicks 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 the case of a single page checkout step, 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 includes virtual pageviews as funnel steps:
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
To learn more about such a tracking setup, read this article: Setting up Sales Funnel across websites in Google Analytics.
Things to consider before tracking virtual pageviews in Google Analytics
There has been lots of discussion among the analytics experts on whether virtual pageviews are good or bad. So, the question arises: Event vs Virtual Pageviews
Event tracking is straight forward and simple option for tracking user interaction on a webpage, like a link click, download, media play pause, scroll tracking, etc.
Another benefit of using event tracking is that it does not affect the bounce rate and is tracked separately from pageviews. You can check all events in Google Analytics under the behavior tab with details like event category, event action and event label. But the drawback of events is that you cannot use events in setting up funnels in Google Analytics.
Virtual pageviews can give the actual user journey on the website by triggering virtual pages in funnels and thus allows you to check goal flow, reverse goal path and user path across different components of a website.
As we have seen above, we can set virtual pageviews for any event, such as link click, image click, button click, form submission and on dynamic Ajax for single page applications as well. But virtual pageviews are also treated as normal pageviews in Google Analytics and hence virtual pageviews increase the overall pageview count of the website.
As virtual pageviews are also added into the overall pageview count, it reduces the bounce rate and increases pages per session count. There is no separate report in Google Analytics for virtual pageview, so if you have lots of virtual pageviews, it severely affects the bounce rate and increases pages per session
In a nutshell, it is really dependent on what scenario you are tracking virtual pageviews. In general, event tracking is the best option to go with but, in the case that you have a single page website and wanted to track user journeys in a funnel, virtual pageviews can be a good option. Also if you want a complete analysis of user journeys in a funnel, virtual pageview are the best option to consider.
Tips to get the best out of virtual pageviews in Google Analytics
So the downsides of virtual pageviews are not actually drawbacks in every case, but it is true that virtual pageviews affects the default pageview count, reduce the bounce rate and increase the pages per session count. In order to get the most out of your virtual pageview tracking, the following tips could be beneficial
Tip1: Adding ‘Virtual’ word or prefix in URL
You can do this by using fields in Google Tag Manager and set the page to value “virtual/downloadlinkclick”. The text in double-quotes will represent the URL of the virtual page.
Additionally, you can add a title field with the value “Virtual-Download link click”. The text in double-quotes will appear as the title of the virtual page
By using ‘virtual’ as a prefix or part of the url you can easily identify all your virtual pages in Google Analytics reports.
Tip2: Create a separate view in Google Analytics to exclude all virtual pageviews so that you can get your actual default pageview count and not affect other metrics.
As we have seen, lots of virtual pageviews can affect the default pageview count of a website, bounce rate and increased pages per session. It is best to create a separate view which will exclude all virtual pageviews. This view will give you the actual default page view, exact bounce rate and correct avg pages per session.
To create a separate view excluding virtual pageviews, follow the following steps:
Step 1: Go to ‘Admin’ setting of Google Analytics, select the appropriate property and click on ‘Create View’.
Step 2: Give a name such as “Excluding Virtual Page View”, select your reporting timezone and click on ‘Create View’.
Step 3: Once the view is created click on the ‘View’ setting in admin console and then click on ‘Filters’.
Step 4: Click on ‘Add Filter’, select ‘Custom’, select the ‘Exclude’ option. Then select ‘Page Title’ in the filter field and add “virtual” in the filter pattern. Click ‘Save’.
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.
Other articles on specialized tracking in Google Analytics
- How to see Organic Search Keywords in GA4 (Google Analytics 4)
- Google Analytics Ecommerce Tracking Tutorial
- Google Tag Manager Event Tracking Tutorial
- Google Analytics Event Tracking Tutorial
- Google Analytics Store Visits Tracking Tutorial
- Offline Conversion Tracking in Google Analytics – Tutorial
- Ecommerce Tracking Google Tag Manager (GTM) – Tutorial
- Tracking Virtual Pageviews in Google Tag Manager – Tutorial
- Google Tag Manager YouTube Video Tracking
- Google Analytics Virtual Pageviews Tutorial
- Google Analytics YouTube Integration & Analysis Tutorial
- Google Analytics for Facebook Tutorial
- Cross Domain Tracking in Google Analytics – Complete Guide
- How to use two Google Analytics codes on one page
- How to correctly use referral exclusion list in Google Analytics
- Google Analytics Calculated Metrics – Tutorial
- Creating your own Google Analytics Tag Auditing System
- Google Tag Manager Search Tracking without Query Parameter
- Tracking Google Analytics Paypal Referral and other payment gateways
- How to Track Phone Calls in Google Analytics 4 – Call Tracking Tutorial
- How to track leads in Google Analytics via CRM
- Postbacks in Google Analytics Explained
- Subscription & Recurring Revenue Analytics in Google Analytics
- Track the Impact of Google Analytics Cookie Consent on Website Traffic
- Tracking Offline Conversions in Google Ads
- Implementing Scroll Tracking via Google Tag Manager
- Scroll Depth Tracking in Google Tag Manager – Tutorial
- Site Search Tracking In Google Analytics Without Query Parameters
- Google Tag Manager Youtube Video Tracking via YouTube Video Trigger
- How to Correctly Measure Conversion Date & Time in Google Analytics
- Google Analytics Social Tracking – Twitter, Facebook, Google Plus and LinkedIn
- Cross Domain Tracking in Google Analytics – Complete Guide
- Google Analytics Linkedin & Twitter Tracking
- Creating Content Group in Google Analytics via tracking code using gtag.js
- Google Analytics Site Search Tracking via Query Parameters
- Google Analytics Site Search Tracking Tutorial
- Creating and Using Site Search Funnel in Google Analytics
- How to add Facebook Pixel to Google Tag Manager
- AMP Google Analytics Tracking – Learn to track AMP pages
- Setting up Sales Funnel across websites in Google Analytics
- Google Analytics 4 Regex (Regular Expressions) Tutorial
Frequently Asked Questions for Tracking Virtual Pageviews in Google Tag Manager – Tutorial
What is a virtual pageview?
A virtual pageview is that pageview hit, which you send to Google Analytics without loading a web page in your web browser.
When new content is loaded on a web page via Ajax, no pageview hit is sent to GA (by default). 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 content is loaded on a web page via Ajax.
What type of user interactions can be tracked with virtual pageviews?
Any user interaction which is equivalent to a page being viewed can be tracked via virtual pageviews. For example:
– Loading of a new single-page checkout step
– Loading of popups or lightboxes.
– Downloading a file.
– Scrolling down a page
– Loading new text contents on a web page via Ajax
Are there any benefits of using virtual pageviews over event tracking?
There has been lots of discussion among the analytics experts on whether virtual pageviews are good or bad. So, the question arises: Event vs Virtual Pageviews.
In general, event tracking is the best option to go with but the drawback of events is that you cannot use events in setting up funnels in Google Analytics.
Virtual pageviews can give the actual user journey on the website by triggering virtual pages in funnels and thus allows you to check goal flow, reverse goal path and user path across different components of a website.
My best selling books on Digital Analytics and Conversion Optimization
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 BeyondSECOND EDITION OUT NOW!
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.
Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.