Install Pixel in Google Tag Manager (GTM)

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).

Create RegEx Matching Trigger

It’s best practice to use RegEx (Regular Expressions) matching to ensure the pixel fires even if the URL contains unique tracking parameters that would break an “Exact Match” rule.

  1. In GTM, navigate to Triggers in the left menu and click New.
  2. Name the Trigger (e.g., Page URL RegEx Match)
  3. Select Page View as the Trigger Type.
  4. Change the selection from “All Page Views” to “Some Page Views”
  5. Select “Page URL” > matches RegEx and paste your pattern (see use case examples below*)
  6. Save the trigger.

RegEx (Regular Expressions) Technical Note & Use Cases

Google Tag Manager uses the RE2 regex engine, which does not support lookaheads or lookbehinds. Ensure you replace “example.com” with your actual domain name.

Use Case RegEx Pattern Explanation
Target all pages of a domain ^https://(www\.)?example\.com

^ anchors the match to the start of the URL

(www\.)? makes the "www." optional so it captures your domain regardless of how it's typed

Target the homepage only ^https://(www\.)?example\.com/?$ /?$ ensures the URL match ends right 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)

Important: Remember to replace example.com with your actual domain.


Install the GroundTruth Pixel Code

Step-by-step guide on how to implement the base pixel code for the web engagement pixel via GTM.

  1. 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.
  2. Create a new tag in GTM.
    1. In GTM, navigate to Tags in the left menu.
    2. Click New.
    3. Click into the Tag Configuration box.
    4. Choose Custom HTML as the tag type.
  3. Add the pixel in GTM. Copy and paste the following base pixel code snippet into the HTML box.

    • IMPORTANT ACTION: Replace XXXXX with the unique GTID provided by your representative.
    <script>
      window.GTPX_DEBUG = false;  // Set to true to enable console debugging
      (function(g, r, o, u, n, d, t) {
        g[n] = g[n] || function() {
          (g[n].q = g[n].q || []).push(arguments);
        };
        g[n].l = 1 * new Date();
        t = r.createElement(o); t.async = 1; t.src = u;
        r.getElementsByTagName('head')[0].appendChild(t);
      })(window, document, 'script', 'https://analytics.groundtruth-data.com/pixel.v2.js', 'gtpx');
    
      // Initialize with your unique identifier
      gtpx('init', {
        gtid: 'XXXXX' 
      });
    
      // Explicitly track pageview (Recommended for standard sites and SPAs)
      gtpx('pageview');
    </script>
  4. Set the Trigger.
    1. Click into the Triggering box.
    2. Choose All Pages so the tag fires on every page of your site.
  5. Name the tag (e.g., GroundTruth Base Pixel)
  6. Save. See below for how the tag should look in GTM
  7. 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.
GTM-V2.png

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 custom events (e.g. add to cart, purchase), continue on for further instructions.


Install Custom Event Code(s)

Add to Cart

This code enables you to track any action related to an add to cart event on your website.

  1. Create a Custom Event Trigger.
    1. In GTM, navigate to Triggers in the left menu.
    2. Click New.
    3. Choose a trigger type that matches your event (e.g., Click - All Elements or Custom Event, depending on your setup).
    4. Name the trigger (e.g., Add to Cart Trigger).
    5. Save.
  2. Create a Custom HTML Tag.
    1. Navigate back to Tags in the left menu.
    2. Click New.
    3. Choose Custom HTML as the tag type.
    4. Copy and paste the following custom code snippet into the HTML box:

      <script>
          //Track add-to-cart
      gtpx(‘cart’,{amount: XXXXX});
      </script>
    5. 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.
  3. Link Trigger to Tag
    1. In the new tag, click Triggering and select the trigger created in Step 1.
    2. Name your tag (e.g., GroundTruth Pixel | Add to Cart).
    3. Click Save then Submit the GTM container to make the changes live.
Purchase

This code enables you to track any action related to a purchase event on your website.

  1. Create a Custom Event Trigger
    1. In GTM, navigate to Triggers in the left menu.
    2. Click New.
    3. Choose a trigger type that matches your event (e.g., Page View on the "Thank You" page or Custom Event, depending on your setup).
    4. Name the trigger (e.g., Purchase Trigger).
    5. Save.
  2. Create a Custom HTML Tag
    1. Navigate back to Tags in the left menu.
    2. Choose Custom HTML as the tag type.
    3. Copy and paste the following custom code snippet into the HTML box:

      <script>
          //Track completed purchase
      gtpx(‘purchase’,{amount: XXXXX});
      </script>
    4. 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.
  3. Link Triggers to Tag
    1. In the new tag, click Triggering and select the trigger created in Step 1.
    2. Name your tag (e.g., GroundTruth Pixel | Purchase).
    3. Click Save then Submit the GTM container to make the changes live.

 

Signup

This code enables you to track any action related to a signup event on your website.

  1. Create a Custom Event Trigger
    1. In GTM, navigate to Triggers in the left menu.
    2. Click New.
    3. 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).
    4. Name the trigger (e.g., Signup Trigger).
    5. Save.
  2. Create a Custom HTML Tag
    1. Navigate back to Tags in the left menu.
    2. Choose Custom HTML as the tag type.
    3. Copy and paste the following custom code snippet into the HTML box:

      <script>
          //Track completed signup
      gtpx(‘signup’);
      </script>
  3. Link Trigger to Tag
    1. In the new tag, click Triggering and select the trigger created in Step 1.
    2. Name your tag (e.g., GroundTruth Pixel | Signup).
    3. Click Save then Submit the GTM container to make the changes live.

Frequently Asked Questions

  1. How do I generate the pixel? The base pixel can be found above, which you can copy but remember that you need a unique identifier (GTID) to replace the XXXXX before implementing it onto your website. Reach out to a representative to receive your GTID. 
  2. Do I need to generate a new pixel for every campaign? Your GTID is mapped to your Account ID. One pixel can have multiple website domains. 
  3. 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.
  4. Where do I place custom event code? Place custom code only on the specific page that confirms the action (e.g., the post-submission confirmation page). Do not place custom event code in the global header.
  5. 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. 
  6. 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. 
  7. Do I need to select “Support document.write" when configuring my tag? No. Our pixel loads asynchronously, which is the modern industry standard. “Support document.write” is a legacy requirement for older scripts; since our tag uses an updated loading process, selecting this option is unnecessary and should be left disabled.
  8. What if my site uses a 3rd-party checkout platform? If your site redirects to a different domain, the tracking data may be lost during the redirect. We suggest directing your ad traffic directly to the final conversion domain to ensure accurate reporting.
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.