Overview
Google Tag Manager (GTM) is a free tool that helps you easily manage marketing and analytics tags on your website or app without modifying code directly. GTM embeds a single container code on your website that dynamically loads tags based on rules you define.
Key GTM Components
- Tags: Code snippets that fire on your website for tracking (e.g., GroundTruth Base Pixel).
- Triggers: Rules that define when a tag fires (e.g., when a specific page loads).
- Variables: Dynamic values used in triggers/tags (e.g., page URL).
Step 1: Create RegEx Matching Trigger
It’s best practice to use RegEx matching for your GroundTruth Pixel trigger.
- In GTM, navigate to Triggers in the left menu and click New.
- Name the Trigger (e.g.,
GroundTruth - Page URL RegEx Match). - Click Trigger Configuration and select Page View.
- Change the selection from "All Page Views" to Some Page Views.
- Set the rule to Page URL > matches RegEx and paste your pattern (see reference table below).
- Click Save.
RegEx Pattern Reference
Google Tag Manager uses the RE2 regex engine. Replace example.com with your actual domain name.
| Use Case | RegEx Pattern | Explanation |
|---|---|---|
| Target All Pages of a Domain | ^https://(www\.)?example\.com |
The ^ anchors the match to the start of the URL, while (www\.)? makes "www." optional so it captures your domain regardless of how it’s typed. |
| Target the Homepage Only | ^https://(www\.)?example\.com/?$ |
The /?$ pattern ensures the URL match ends after the domain, allowing for an optional trailing slash but blocking subfolders. |
| Target a Specific Subdomain | ^https://shop\.example\.com |
Anchors the match to only trigger for URLs starting with that exact subdomain (e.g., shop.example.com). |
Step 2: Install the GroundTruth Pixel Code (Base Pixel)
Add the GTM container to your site, onto all pages that you wish to track. If GTM has not been installed, follow Google’s setup guide.
- In GTM, navigate to Tags in the left menu and click New.
- Click into the Tag Configuration box and select Custom HTML.
- Copy your auto-generated Base Pixel code snippet from Ads Manager (Step 6: Measurement) and paste it into the HTML text box.
- Click Triggering and select the Regex Page View Trigger created in Step 1.
- Name the tag (e.g.,
GroundTruth Base Pixel). - Click Save.
Step 3: Install Custom Event Codes (Optional)
To track post-click conversion actions (such as purchases or form fills), create secondary Custom HTML tags in GTM attached to specific event triggers.
🛍️ Add to Cart
This code enables you to track any action related to an add to cart event on your website.
-
Create Trigger: Go to Triggers > New. Select a trigger type matching your cart action (e.g., Click - All Elements or Custom Event named
addToCart). Name it (e.g.,Add to Cart Trigger). -
Create Tag: Go to Tags > New > Custom HTML. Paste the following snippet into the HTML box:
<script> gtpx('cart',{amount: {{Cart Value}}}); </script>Replace
{{Cart Value}}with your GTM variable or a numerical value. -
Attach Trigger: Click Triggering, select your
Add to Cart Trigger, name the tag (e.g.,GroundTruth Pixel | Add to Cart), and click Save.
💳 Purchase
This code enables you to track any action related to a purchase event on your website.
-
Create Trigger: Go to Triggers > New. Select a trigger type matching your order confirmation page (e.g., Page View on
/thank-you). Name it (e.g.,Purchase Trigger). -
Create Tag: Go to Tags > New > Custom HTML. Paste the following snippet into the HTML box:
<script> gtpx('purchase',{amount: {{Purchase Value}}}); </script>Replace
{{Purchase Value}}with your dynamic GTM purchase variable or keep it as{{Purchase Value}}. -
Attach Trigger: Click Triggering, select your
Purchase Trigger, name the tag (e.g.,GroundTruth Pixel | Purchase), and click Save.
📝 Conversion
This code enables you to track any conversion action related to a signup or form submission on your website.
-
Create Trigger: Go to Triggers > New. Select a trigger type matching your form completion page or button click (e.g., Page View on a confirmation page or a Form Submission trigger). Name it (e.g.,
Signup Trigger). -
Create Tag: Go to Tags > New > Custom HTML. Paste the following snippet into the HTML box:
<script> //Track conversion gtpx('conversion',{label: 'my_goal_name'}); </script>Replace
my_goal_namewith your custom goal name string in the label field (e.g.,newsletter_signup). -
Attach Trigger: Click Triggering, select your
Signup Trigger, name the tag (e.g.,GroundTruth Pixel | Lead Signup), and click Save.
Step 4: Verify & Publish
- Click Preview in the top right corner of GTM to enter Tag Assistant debugging mode.
- Enter your website URL to confirm your GroundTruth tags fire successfully on the intended pages.
- Once verified, click Submit / Publish in GTM to make your changes live.
Follow our [Validating & Troubleshooting Your Pixel Setup] guide for detailed inspection steps using Chrome DevTools.
Frequently Asked Questions
-
How do I generate the pixel? Your Base Pixel snippet is automatically generated with your unique account identifier (
gtid) inside Ads Manager at Step 6 (Measurement) during campaign creation. - Do I need to generate a new pixel for every campaign? No. Pixels are managed at the account level and can be reused across campaigns driving traffic to the same domain.
-
Why does exact URL matching fail in GTM? Ads Manager appends query parameters (e.g.,
?rid=123&campaignId=456) to landing page URLs to measure web engagement. Exact match rules fail when these parameters are present, whereas RegEx matching allows the pixel to fire reliably. - Do I need to select "Support document.write" when configuring my tag? No. The GroundTruth Pixel loads asynchronously using modern web standards. Leave "Support document.write" unchecked.
- What if my site uses a 3rd-party checkout platform? If users are redirected to an external domain during checkout, tracking data may be lost. We recommend directing ad traffic and conversion tracking to pages hosted on your primary domain whenever possible.
Need Help?
For additional support and to ensure your campaign is set up for success, please reach out to your dedicated GroundTruth representative, or contact our Self-Serve team directly at selfservehelp@groundtruth.com.
Comments
Please sign in to leave a comment.