English Posts

How to track Virtual Pages: Google Tag Manager and Google Analytics

how to track virtual pages with gtm and ga

In this post, we see how to track Virtual Pages with the help of Google Tag Manager and Google Analytics.

If you don’t know what Virtual Pages are and learn more about how they can help you especially if you are tracking a Single Page Application, I suggest you to read my dedicated post.

To better follow the different steps I will take, let’s imagine this kind of situation: I want to implement virtual pages within a sellout funnel.

My funnel behaves like this:

  • Step 1: The URL you upload is www.example.com/product123#/account
  • Step 2: The URL you upload is www.example.com/product123#/order
  • Step 3: The URL you upload is www.example.com/product123#/shipping
  • Step 4: The URL you upload is www.example.com/product123#/thank-you

By default, in Google Analytics I am unable to collect values ​​after the # symbol (account, order, shipping, thank-you).

For this reason I need to create a virtual page in each step of the checkout.

Let’s begin!

Virtual Pages: create a new tag

The steps to take within Google Tag Manager are as follows:

  1. Create a new Tag by clicking on Tag> New:
create a new tag in google tag manager

2. Select the type of tag (we select the Google Analytics tag: Universal Analytics):

tag google analytics

3. We select the type of hit for this tag: we choose the pageview hit:

hit pageview google tag manager

4. We select the Google Analytics variable, in order to send the information to the Property that interests us:

google analytics settings variable

5. We select the Enable overriding settings in this tag and click on More Settings> Fields to set:

fields to set google tag manager

6. In this field we will create our virtual page by entering the page we want to create and the title of the same. Click on Add Field and write in ‘page‘, while in the “Value” block we insert the path of the page we want to create: I will use ‘/step-1-account‘:

create a virtual page tag

7. Now we have to insert another field to give a Title to this virtual page. Click on Add Field and enter ‘title‘ and in the “Value” block the title you want to give to the page: I will write ‘Checkout Step 1- Account‘ to acknowledge that it is the first step of the checkout.

page title of the virtual page

8. Let’s give our tag a name.

save a tag in google tag manager

Recap: we created the tag and entered the path of the virtual page and its title. We have also selected the Google Analytics variable to indicate which tool to send the information to.

We continue by inserting the trigger to activate our tag under certain conditions.

Virtual Pages: Create a new trigger

Now we need to create the trigger in order to fire the tag in certain situations.

In this case a lot depends on the type of website you are tracking and when you want to activate your tag. The indications below are indicative and may vary, depending on what you want to track in your case.

As mentioned above, I want to send my virtual page when the user is in the first step of the sellout funnel which, in my example was in this URL: www.example.com/product123#/account.

  1. I create my own History Change trigger:
history change trigger tag manager

2. Select the item Some History Changes:

some history change google tag manager

3. Now select the Choose Built-in Variable item from the list:

new buil-in variable tag manager

4. We look for the variable that is called New history Fragment from the list:

new history fragment variabile

5. We select the variable to enable it and make it available in the future in Google Tag Manager and in the value field enter the ‘/ account‘ item that is present within the URL, so that GTM will be able to read the value after the # symbol

new history fragment

6. Let’s name the trigger and save:

save a trigger

Recap: we have associated to our tag the trigger to read the value of the URL after the # symbol.

Now let’s save and test everything.

This process must be done for all the pages of the sellout that we want to track and in which we want to insert virtual pages.

If I go back to my initial example, this means that in each of these pages of the website, the following virtual page will be shot:

  • Step 1: site page www.example.com/product123#/account -> virtual page created in GTM: /step-1-account
  • Step 2: site page www.example.com/product123#/order -> virtual page created in GTM: /step-2-order
  • Step 3: site page www.example.com/product123#/shipping -> virtual page created in GTM: /step-3-shipping
  • Step 4: site page www.example.com/product123#/thank-you -> virtual page created in GTM: /step-4-thank-you

A tag and trigger must be created for each page as described above.

Virtual Pages: Create a Goal in Google Analytics

Now that we’ve created the tags and triggers, a virtual page will be created on each page of the checkout funnel website.

We can now use these virtual pages to create a new Goal in Google Analytics.

The purpose of this Goal is to show us every time a user arrives at the Thank you page by passing through every page of the funnel.

In this case, we need to go to in the Admin section and, within the View where we want to set the goal, create a new Destination Goal.

Here’s how to do it. Let’s create a new Goal in the GA view.

new goal google analytics

We select a custom type template and give a talking name to the Goal, for example: “Checkout Completed”

custom goal google analytics

We select the Destination as the type of Goal: this means that my goal will be completed if the designeted destination is reached.

destination goal google analytics

Click on Continue and enter various information:

  1. the landing page, that is the thank-you page that must be reached by the user to complete the Goal
  2. let’s activate the Funnel option
  3. We insert the name of the Page (the “title” value written in the GTM Tag in the previous steps)
  4. We insert the URL of the virtual page we created (the “page” value written in the GTM tag)
destination goal google analytics

Once the new Goal is set, you will be able to see the conversions in the dedicated report:

rapporto conversioni google analytics

Good analysis!


You may also be interesting by the following articles:

  • Google Analytics 4: source/medium report
    One of the most popular reports within the Universal Analytics version is definitely the Source/Medium Report. In this Report, you can quickly observe the source and medium of users landing on the website. In UA we can find it under Acquisition > All Traffic > Source/Medium The new version of GA4 offers many features but […]
  • Landing Pages Report in GA4
    One of the most interesting reports in Google Analytics – Universal Analytics is the Landing Pages Report. In this report you can observe the first landing page of a user on the analyzed website. It’s a very useful report to quickly understand what our user’s entry points are. However, the question may arise: how do […]
  • Google Analytics 4: Comparison
    In this post, I’ll show you how to compare data in Google Analytics 4. Just as with the UA (Universal Analytics) version, where you can use segments to better analyze your users’ behavior on the site, GA4 offers a similar feature. However, there are some nuances, compared to the UA version. Compare data in GA4 […]
  • Search Console and Google Analytics 4
    In this post I will show you two things that I find very useful: Connect the Google Search Console directly to your Google Analytics Property 4 Save a widget for faster access to Search Console data in the GA4 User Interface Let’s start! How to Link Search Console to GA4 Property The steps to link […]
  • How to Change Language in Google Data Studio
    Google Data Studio is a great data visualization tool that is completely free, allowing you to connect different data sources to create dashboards. Some of the available data sources are: Google Analytics Google Sheets Google BigQuery File in .csv etc. The sources are different and, as you have seen, they are not only from the […]
  • How to Implement Content Group in Google Analytics 4
    Content Groups allow you to create sections of the website, grouping contents in a convenient way for your analysis. Let’s give some examples: I can create a specific group that shows me the most viewed Brands on my website or I can create Product categories to analyze, at a higher level, the interactions of users […]
  • Server-side Tagging: what is it?
    Update: October 5th. Google Tag Manager Server Side is officially out of Beta, as confirmed by Google, and has entered a new phase. Announced in August 2020, Google Tag Manager Server-side is still a tool / theme unknown to most. There are many doubts and questions on the subject and in this post I want […]
  • Content Grouping in Google Analytics
    Note: this article refers to the Universal Analytics version. If you want to know how to implement Content Groups in GA4 via Google Tag Manager, you can read this blog post. Analyzing the contents of a website, has it ever happened to you that you want to know what are the performances of the main […]

Lascia un commento

Il tuo indirizzo email non sarà pubblicato.