• Courses
    • Courses
    • Course bundles
  • Blog
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • Services
  • About
    • About
    • Contact
  • Login
  • Courses
    • Courses
    • Course bundles
  • Blog
  • Resources
    • Youtube channel
    • E-books and Guides
    • GTM Recipes
    • View All Resources
    • GTM Community
    • GA4 community
  • Services
  • About
    • About
    • Contact
  • Login

March 30, 2025

Page Variables and Pageview Triggers in Google Tag Manager

Updated: March 30th, 2025

As you probably already know, Google Tag Manager is a fantastic tool that lets you manage your tracking codes and activate them whenever needed. With GTM, you can fire your tags whenever a visitor submits a form, clicks a link, etc.

But the most basic (yet still very crucial) is when the page loads. You can instruct Google Tag Manager to fire a tag only on certain pages. That is possible thanks to two components: pageview triggers and page variables.

Subscribe and Get the Ebook - Real Book Img - GTM for Beginners

Table of Contents

  • Pageview-based triggers
  • Pageview-based trigger on a particular page
  • Built-in page variables
  • Page Path vs Page URL
  • Custom Page variables
  • Example of a Custom Page variable
  • Multiple URLs in a single trigger
  • Track page views in a single-page application
  • Several ideas/examples where Page variables and Pageview triggers are useful
  • Page Variables and Triggers in GTM: Final Words

 

Pageview triggers

When creating a new Google Tag Manager container, it already contains three default triggers – All Pages, Consent Initialization – All Pages and Initialization – All Pages. Although you cannot see them in the list of triggers, you can find them when you try to create a new tag and click “Triggering”.

These triggers cannot be deleted and fire whenever a Google Tag Manager container loads on a page.

If you want to customize this behavior and fire a certain tag on some pages, you must create a new trigger. In the GTM interface, go to Triggers > New > Trigger Configuration. You will see five types of page-load-related triggers:

  • Consent Initialization: This trigger is set to capture the user’s consent status as they enter your website. This is the first trigger that fires; however, it is recommended to use only tags that work with the consent management.
  • Initialization: This is the trigger to use when you want the respective tag to load early on the page. This is typically used to fire tags that should send information before the rest of the page loads. For example, right now, Googe recommends firing the GA4 configuration tag with this trigger.
  • Page View: This trigger is essential to capture data generated during page impressions. It is fired when a browser begins to load a web page.
  • DOM Ready: This trigger is activated when the page’s document object model is loaded. In other words, the browser has rendered elements on a page.
  • Window Loaded: This is the final stage of the page-loading process. The Window Loaded trigger activates when the page is fully loaded (including with 3rd party scripts).

Which one to choose?

  • If the tag is related to user consent (e.g., it loads the consent popup or consent state), use Consent initialization.
  • If you want to fire a tag ASAP on a page (and that tag does not rely on other website elements, their content/text/etc.), use the Initialization trigger.
  • Pageview fires immediately when the web browser begins to load a page.
  • If you want to fire a tag and it must send a value of a particular website element (e.g., its text), then you should use DOM Ready trigger or Window Loaded
  • If you want to fire a tag and ensure the page has fully loaded before that, use the Window Loaded trigger.

 

Pageview trigger on a particular page

Let’s say that you have created a Page View trigger and want it to be activated only on page X. To achieve this, you need to click Some Page Views and then enter the condition. For example, Page Path equals /pages/contact-us/

But which variable should you choose when? Let’s find out.

 

Built-in page variables

Currently, Google Tag Manager offers four standard page variables

  • Page Hostname
  • Page URL
  • Page Path
  • Referrer

By default, they are all enabled, and you can find them by going to the Variables section of your GTM container.

You will see them enabled if you click the Customize button in the top right corner of the built-in variables list. Let’s take a quick look at what each variable means:

  • Hostname returns the hostname (domain) of the URL without, e.g., www.example.com
  • Page URL returns the full URL without the hash fragment (#), e.g., https://www.example.com/welcome?gclid=aabbcc123
  • Page Path returns only the pathname in the URL (in other words – everything after the hostname, except port, fragment, and query). If the page URL is https://www.example.com/welcome?gclid=aabbcc123, this variable will return /welcome/ value.
  • Referrer returns the page address that a visitor previously visited (including query parameters) and then landed on the current page. But due to various privacy changes in the industry and configurations on a page, this variable can return an empty value or just the hostname.

 

Page Path vs Page URL

If you’re just starting with web tracking and have no prior technical knowledge of the web, you might be confused about which variable to use and when. Let’s take a look.

Page Path returns way less info compared to the Page URL. Page Path returns only what comes after the hostname (domain) but before the question mark “?” (a.k.a. query parameters), hashmark “#” (a.k.a. URL fragment), colon “:” (a.k.a. port).

It just returns the subdirectory (page) on which you currently are.

If you want to also use query parameters (e.g., utm_parameters) in your triggers, then the Page Path variable is the wrong choice. You should instead use the Page URL because it returns:

  • protocol (e.g., https://)
  • hostname (e.g., www.example.com)
  • page path (e.g., /pages/contact-us/)
  • query parameters (e.g., ?utm_medium=referral&utm_source=othersite.com)

To sum up, the difference between the Page URL and Page Path is that Page URL returns almost the entire URL while Page Path returns the value after the hostname (but before the query parameter).

If, on the other hand, you want to isolate and access only other parts of the URL (but without getting the full URL, you will have to rely on custom page variables. Continue reading, and I’ll show you how.

Subscribe and Get the Ebook - Real Book Img - GTM for Beginners

Custom Page variables

Another amazing thing about GTM is its customization possibilities. If the built-in functionality is not enough for you (it probably won’t), you can do some awesome user-defined stuff.

In Google Tag Manager’s interface, scroll to Variables until you see the User-defined Variables section. Click New and choose the URL variable.

The URL Variable can access components of the current page URL. This is a very versatile Variable type and is especially useful for traversing query parameters and hash fragments in your URLs.

Note: There are Built-In Google Tag Manager Variables for some situations (i.e. Page URL, Page Hostname, Page Path).

Let’s say the address of the web page I am currently on is https://www.example.com/welcome:8080?gclid=aabbcc123#home. Now I will describe every component type that is available in the URL variable:

  • Full URL – returns the full URL without the hash fragment, e.g., https://www.example.com/welcome?gclid=aabbcc123.
  • Protocol – returns the protocol of the URL, e.g., https.
  • Host Name – returns the hostname of the URL without the port number, e.g., www.example.com. You can choose the “Strip www” to strip the ‘www’ subdomain from the hostname.
  • Port – returns the port number used in the URL. In my example, the variable will return an 8080 value. Or 80 for HTTP / 443 for HTTPS if the URL had no port number.
  • Path – returns only the pathname in the URL (in other words, everything after the hostname, except port, fragment, and query). In my example, I would get /welcome/ value. You can also specify Default Pages to strip pages like ‘index.html’ or ‘index.php’ from the return string.
  • Query – returns the entire query parameter string (without leading ‘?’) if you don’t specify a query key. In my case, I could specify the query key to gclid; thus, theURL variable’s value would be aabbcc123. If you specify a query key that is absent, the variable’s value will be undefined.
  • Fragment – returns the value of the URL’s fragment without the leading ‘#’. In my case, the value would be home.

You can expand the More Settings tab to find a source selector. In this selector, you can choose the Variable whose return value the URL Variable will access (for example, Click URL). But by default, the URL variable returns parts of the Page address.

 

Example of a Custom Page variable

If you’re using an email marketing tool, you’ve probably already noticed that after a recipient clicks a link in your email, they are redirected to your website. The link contains a lot of parameters after a question mark, e.g. https://www.mybusiness.com/?utm_campaign=awesomecampaign&utm_source=campaignid&utm_medium=email.

These 3 query keys are called UTM parameters. They are beneficial when it comes to tracking campaigns in Google Analytics.

You can easily turn utm_campaign, utm_source, and utm_medium into GTM variables and then utilize them in triggers or tags. Just create three variables with the following settings. Here’s one example:

After creating these variables, enable Preview and Debug mode in GTM and head to the website you’re working on. At the end of the URL, add ?utm_medium=test1&utm_source=test2&utm_campaign=test3. If the URL you’re working on already has some query (it starts with a question mark), add &utm_medium=test1&utm_source=test2&utm_campaign=test3 to the end of the link and hit enter.

The page will refresh, and the GTM Preview and Debug console will load. Click on any event (e.g., Page view) and open the Variables tab. The result should look like this:

Now you can use these variables in your triggers if you wish. Of course, an alternative solution could be to use the condition: Page URL contains utm_medium=xxxxxx.

But if you want to pass the actual value of utm_medium with some tag, then the URL variable is irreplaceable here.

 

Multiple URLs in a single trigger

In some cases, you might fire a tag on ONE of many possible pages (e.g., if a visitor visits ANY of 5 pages, you want to fire a tag). What I’ve noticed among beginners is that they try to create the following trigger:

Unfortunately, this will not work because ALL of the conditions must be met in a trigger. And if you add five different URLs in a trigger, it’s impossible for a trigger to fire (because a page cannot have five different URLs simultaneously).

So you have a couple of options here:

  • Option #1: Create a separate pageview-based trigger for EVERY pageview and add ALL to the tag. The tag will fire if at least one of those triggers gets activated. But this solution isn’t very scalable and can quickly turn your GTM container into a mess.
  • Option #2: Create a single trigger that uses Regular Expressions. RegEx allows you to write more complex conditions, including “OR”. So if you want to target 2 URLs, you can take their parts and separate them with a pipe “|”. This symbol in Regular Expressions means “OR”. Here’s an example:
  • /pages/contact-us/|/pages/other-page

See? I just separate parts of the URL with a pipe “|”. Of course, you will need to choose Matches RegEx (ignore case) to make the trigger work

 

Track page views in a single-page application

Unlike traditional websites, single-page websites/apps require additional configuration to correct your pageview tracking. I’ve published a guide about this exact topic, so check it out.

 

Several ideas/examples where Page variables and triggers are useful

If you’re just starting with Google Tag Manager, here are several ideas to get you inspired by GTM’s possibilities.

  • Thank you page tracking (when a visitor submits the form and is redirected to another page)
  • Enrich form submission data (take the values of UTM parameters in the URL and send them together with form submission data)

 

Page Variables and Triggers in GTM: Final Words

In today’s blog post, we looked at the fundamental functionality of Google Tag Manager – firing triggers when the page loads. With the help of page variables and pageview triggers, you can decide when exactly to fire your tags, for example:

  • On certain pages, as soon as Google Tag Manager loads
  • On certain pages, when the website has fully loaded, and so much more!

Were you looking for some other answer to this topic? If yes, please comment below, and I’ll get back to you asap.

Subscribe and Get the Ebook - Real Book Img - GTM for Beginners
Julius Fedorovicius
In Google Tag Manager Tips
6 COMMENTS
Mon
  • Jun 21 2023
  • Reply

Not sure if this is the correct post to ask this but we're getting lower page views in GA4 versus UA. The more glaring discrepancy is that we I filter the hostname, the breakdown of the PVs per hostname do not even total to the lower total PVs that GA4 is showing for a certain period.

Thank you.

harsh
  • Jun 27 2023
  • Reply

I am also seing the discrepancy GA3 has more page views and GA4 less. Which is a concern for business. Do you have find resolution to resolve this issue.

    Julius Fedorovicius
    • Jun 27 2023
    • Reply

    Many things could have gone wrong. Most likely, something is misconfigured. I don't have a blog post about that.

Mahesh Vaghela
  • Jul 13 2023
  • Reply

Hey, Julius

I want to track use when they visit a minimum of 5 page views on the site, there is any way to track them from GTM or GA4

Mahesh Vaghela
  • Jul 13 2023
  • Reply

I want to track user when they visit a minimum of 5 page views on the site, there is any way to track them from GTM or GA4

Eric Pecharki
  • Feb 22 2024
  • Reply

Hi Julius! Excellent article. Is it possible to use Fragment to categorize the pages in my website? i.e. /services/ as "Services", /properties/ as "Properties", etc? I did a Case statement in Looker Studio but it consumes a lot of my GA4 data quota. Wondering if I can use GTM to give me this info as custom dimensions.

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *


 

Hi, I'm Julius Fedorovicius and I'm here to help you learn Google Tag Manager and Google Analytics. Join thousands of other digital marketers and digital analysts in this exciting journey. Read more
Analytics Mania
  • Google Tag Manager Courses
  • Google Tag Manager Recipes
  • Google Tag Manager Resources
  • Google Tag Manager Community
  • Login to courses
Follow Analytics Mania
  • Subscribe to newsletter
Recent Posts
  • Setting up cookie consent for Microsoft Clarity (V2)
  • Conversion rate in Google Analytics 4
  • Google Tag Manager Data Layer Explained
Analytics Mania - Google Tag Manager and Google Analytics Blog | Privacy Policy
Manage Cookie Settings