Overview
Google Tag Manager (GTM) is a free tool that helps you easily manage marketing and analytics tags on your website or app - without having to modify code. With GTM, you can add, edit, and organize tags through an intuitive interface, reducing the need for ongoing developer involvement and enabling faster campaign deployment with fewer errors.
If you do not use a tag manager and need to add the code directly into your website code, please refer to Install Pixel Manually.
GTM works by embedding a small container code on your site. This container dynamically loads and manages tags based on rules you define.
Key GTM components include:
- Tags: Code snippets for tracking (e.g., GroundTruth web engagement pixel, Google Analytics).
- Triggers: Rules that define when a tag fires (e.g., when a page loads or a button is clicked).
- Variables: Values used in triggers/tags (e.g., page URL, user inputs).
Set Up RegEx Matching
Pixels are critical for tracking conversions. However, misconfigurations, especially around URL matching can cause dropped conversions and inaccurate reporting. This guide outlines best practices to ensure your pixels fire reliably, even when your landing page URLs change due to appended parameters.
Why Exact Matching Fails
By default, some advertisers set GTM triggers to fire pixels only on exact URL matches (e.g., https://www.example.com/thank-you). In our platform, we append query parameters to the landing page URL to track web engagements and provide detailed analytics for your campaigns (e.g., ?rid=123&capmaignId=456), the URL no longer matches exactly. This results in the pixel not firing and therefore lost conversions.
Solution: Use RegEx (Regular Expressions) Matching
Always configure pixel triggers in GTM to match URLs with regex instead of exact match. Regex ensures the pixel fires even if parameters are added.
| Use Case | RegEx Pattern | Explanation |
| Fire pixel on all pages of a domain | ^https://(www\.)?example\.com |
^ anchors the match to the beginning of the URL (www\.)? makes the "www." optional example\.com matches your specific domain, ensuring it only fires on your site. |
| Fire only on the homepage | ^https://(www\.)?example\.com/?$ |
Builds on the previous pattern /?$ ensures the URL ends right after the domain, with or without a final slash |
| Fire on a specific subdomain (e.g., shop.example.com) | ^https://shop\.example\.com | ^ ensures match only with URLs that start with the exact subdomain specified |
| Fire for all blog content | ^https://(www\.)?example\.com/blog | ^ anchors the start of the URL and looks for any pages that begin with your domain followed by the /blog path |
Note: Google Tag Manager uses the RE2 regex engine, which does not support lookaheads/lookbehinds. Remember to replace example.com with your actual domain.
Create RegEx Matching Trigger
- In GTM, navigate to Triggers in the left menu.
- Click New.
- Name the Trigger (e.g., Page URL RegEx Match)
- Click into the Trigger Configuration box and select Page View as the Trigger Type.
- Change selection from All Page Views to Some Page Views.
- In the conditional settings that populate:
- Select the (+) image and choose Page URL
- Click the next drop-down menu (default shows contains) and select matches RegEx
- In the last blank field, paste your RegEx Pattern. See examples above for reference.
- Click Save in the top right corner.
- Follow the steps below to add/set the created trigger to your tag setup. For reference, example below shows use case #1.
Install the GroundTruth Pixel Code
Step-by-step guide on how to implement the base pixel code for the web engagement pixel via GTM. Always configure pixel triggers in GTM to match URLs with regex (Regular Expressions Matching) instead of exact match. Regex ensures the pixel fires even if parameters are added.
- Add the GTM container to your site, onto all pages that you wish to track. If GTM has not been installed, you can follow Google’s setup guide.
-
Create a new tag in GTM.
- In GTM, navigate to Tags in the left menu.
- Click New.
- Click into the Tag Configuration box.
- Choose Custom HTML as the tag type.
-
Add the pixel in GTM. Copy and paste the following base pixel code snippet into the HTML box:
<script> window.GTPX_DEBUG = true; (function(w, d, s, u, o, q, j) { w[o] = w[o] || function() { (w[o].q = w[o].q || []).push(arguments); }; j = d.createElement(s); j.async = true; j.src = u; d.getElementsByTagName('head')[0].appendChild(j); })(window, document, "script", "https://gt-pixel-prod.groundtruth.com/pixel.v1.js", "gtpx"); </script> -
Set the Trigger.
- Click into the Triggering box.
- Select the RegEx trigger previously created.
-
Finalize the tag.
- Name the tag (e.g., GroundTruth Base Pixel).
- Click Save.
- Click Submit in the main Tag window to make the changes live.
- See below for how the tag should look in GTM.
- Confirm that the pixel is firing on all site pages where you want tracking using the validation steps. Use Preview/Debug Mode to test and confirm the pixel fires correctly on target pages.
The GroundTruth Pixel’s base code automatically tracks standard engagement events such as pageview, scroll, and click. No additional configuration is needed to capture these. If you wish to measure additional events (e.g. add-to-cart, purchase), continue on for instructions to set up triggers for these custom event(s).
Install Custom Event Code(s)
This code enables you to track any action related to an add to cart event on your website.
-
Create a Custom Event Trigger.
- In GTM, navigate to Triggers in the left menu.
- Click New.
- Choose a trigger type that matches your event (e.g., Click - All Elements or Custom Event, depending on your setup).
- Name the trigger (e.g., Add to Cart Trigger).
- Save.
-
Create a Custom HTML Tag.
- Navigate back to Tags in the left menu.
- Click New.
- Choose Custom HTML as the tag type.
-
Copy and paste the following custom code snippet into the HTML box:
<script> //Track add-to-cart gtpx("cart",{value: XXXXX}); </script> -
Replace XXXXX with your GTM variable for the add-to-cart value (e.g., 49.99 or a dynamic value like {{Cart Value}}).
- Note: The variable name and setup may differ per website. Consult your developer if unsure.
-
Link Trigger to Tag
- In the new tag, click Triggering and select the trigger created in Step 1.
- Name your tag (e.g., GroundTruth Pixel | Add to Cart).
- Click Save then Submit the GTM container to make the changes live.
This code enables you to track any action related to a purchase event on your website.
-
Create a Custom Event Trigger
- In GTM, navigate to Triggers in the left menu.
- Click New.
- Choose a trigger type that matches your event (e.g., Page View on the "Thank You" page or Custom Event, depending on your setup).
- Name the trigger (e.g., Purchase Trigger).
- Save.
-
Create a Custom HTML Tag
- Navigate back to Tags in the left menu.
- Choose Custom HTML as the tag type.
-
Copy and paste the following custom code snippet into the HTML box:
<script> //Track completed purchase gtpx("purchase",{value: XXXXX}); </script> -
Replace XXXXX with your GTM variable for the purchase value (e.g., 139.99 or a dynamic value like {{Purchase Value}}).
- Note: The variable name and setup may differ per website. Consult your developer if unsure.
-
Link Triggers to Tag
- In the new tag, click Triggering and select the trigger created in Step 1.
- Name your tag (e.g., GroundTruth Pixel | Purchase).
- Click Save then Submit the GTM container to make the changes live.
This code enables you to track any action related to a conversion (form fill) event on your website.
-
Create a Custom Event Trigger
- In GTM, navigate to Triggers in the left menu.
- Click New.
- Choose a trigger type that matches your form submission event (e.g., Page View on a confirmation page or Form Submission, depending on your setup).
- Name the trigger (e.g., Conversion Trigger).
- Save.
-
Create a Custom HTML Tag
- Navigate back to Tags in the left menu.
- Choose Custom HTML as the tag type.
-
Copy and paste the following custom code snippet into the HTML box:
<script> //Track completed conversion gtpx("conversion",{label: "XXXXX"}); </script> - IMPORTANT: Replace XXXXX with your GTM conversion value maintaining the string format (e.g., "aed089"), keeping the label inside double quotes. If you're tracking leads, then XXXXX should be replaced with a label name like leads or leadforms.
-
Link Trigger to Tag
- In the new tag, click Triggering and select the trigger created in Step 1.
- Name your tag (e.g., GroundTruth Pixel | Conversion).
- Click Save then Submit the GTM container to make the changes live.
Frequently Asked Questions
- How do I generate the pixel? You don’t. The GT Pixel is a universal code snippet, ready to be copied and placed on any website. No unique generation is required.
Where does the pixel need to be placed? On every page of the website to ensure it captures a comprehensive view of the user journey.
Do I need to remove the existing conversion pixel if I want to add a web engagement pixel? No, both pixels can exist on the same page. They track different goals and have separate reporting, so they will not interfere with each other.
If I’m setting up a custom conversion event (e.g., form fill), where do I place the custom code? Place the custom event code only on page that confirms the conversion. For example, to track a form fill, you would place the code on the post-submission “Thank You” page.
Why do I need to use regex matching in when setting up pixels in a tag manager? Misconfigurations, especially around URL matching can cause dropped conversions and inaccurate reporting.
Why does exact matching fail when setting up pixels in a tag manager? By default, some advertisers set GTM triggers to fire pixels only on exact URL matches (e.g., https://www.example.com/thank-you). In our platform, we append query parameters to the landing page URL to track web engagements and provide detailed analytics for your campaigns (e.g., ?rid=123&capmaignId=456), the URL no longer matches exactly. This results in the pixel not firing and therefore lost conversions.
My ad's clickthrough URL links to my site, but a 3rd-party site (like an ordering platform) handles the final conversion. What should I do? If your ad sends a user to
YourSite.comfirst, and then your site redirects them to3rdPartySite.comto complete the action, the tracking data will not get pass along. The 3rd-party site never receives the tracking code, so it has no way of knowing that user came from your ad. Our suggested solution is to direct traffic directly to the final conversion domain (e.g., the 3rd-party ordering page), which will skip the redirect and ensure the tracking codes are received and reporting more accurately.
Comments
Please sign in to leave a comment.