Skip to docs navigation
On this page

Add SourceTrack with Google Tag Manager

Add the SourceTrack script from your Google Tag Manager (GTM) container with one Custom HTML tag.

See which channels and campaigns bring your visitors, without editing your site's code.

You need: a SourceTrack account, and publish access to the Google Tag Manager container your site loads.

NoteSourceTrack does not publish a template in the GTM community gallery. You paste the snippet into a Custom HTML tag in your own container.

Add the tag in Google Tag Manager

  1. Open your container in Google Tag Manager, go to Tags and click New.
  2. Click Tag Configuration and choose Custom HTML.
  3. Paste the code below. Replace YOUR_SITE_KEY with your site key. You can see it in your snippet on Setup & Health under Install the script.
    HTML
    <!-- Paste this inside a Custom HTML Tag in GTM -->
    <script>
      // Queues sourcetrack calls from other tags (purchase, consent) until the script below has loaded.
      !function(w){if(w.sourcetrack)return;var q=[],s={_q:q};"track conversion identify group reset consent optIn optOut".split(" ").forEach(function(m){s[m]=function(){q.length<100&&q.push([m,[].slice.call(arguments)])}});w.sourcetrack=s}(window);
      (function() {
        if (document.querySelector('script[data-site-key]')) return;
        var script = document.createElement('script');
        script.src = 'https://api.srctk.com/tracker.min.js';
        script.setAttribute('data-site-key', 'YOUR_SITE_KEY');
        script.async = true;
        document.head.appendChild(script);
      })();
    </script>
  4. Click Triggering and choose Initialization - All Pages, or All Pages (Page View) if Initialization is not available. Tags that send purchases or consent to SourceTrack must fire after this one.
  5. Name the tag, for example SourceTrack - Base Pixel, and click Save.
  6. Click Submit, then Publish.
NoteSites with a cookie banner: add script.setAttribute('data-consent-mode', 'true'); under the site key line. SourceTrack then follows the Google Consent Mode choices your banner sends. To send nothing until the visitor agrees, use data-consent-required="true" instead, and add a Custom HTML tag that runs sourcetrack.consent(true) when your banner records consent.

Check that it worked

  1. In Google Tag Manager, click Preview, enter your website address and connect Tag Assistant. Your SourceTrack tag should show as fired.
  2. After you publish, open your live site in a new browser window and visit a page.
  3. In SourceTrack, open Setup & Health. Under Install the script, click Verify installation.
  4. You should see First event received. The script check cannot see tags added by Google Tag Manager, so it may say the script was not found. The first event is what counts.

If it did not work

  • Nothing shows up: Preview mode only works for you. Click Submit, then Publish, so the tag goes live for everyone.
  • Using a container loaded with a G- or AW- ID: Add SourceTrack to a container your site loads with its GTM- ID. Since July 9, 2026, Google says a container loaded with a product ID such as G-XXXX or AW-XXXX only permits tags and variables provided by Google, and a Custom HTML tag or a custom template is not one of those.
  • The tag does not fire: In the tag's Advanced Settings, check "Require additional consent for tag to fire". If your site does not grant that consent, the tag stays silent with no error. For visitors in the EU, EEA, UK and Switzerland, tracking should wait for consent, so requiring analytics_storage is the right setup there. SourceTrack respects Do Not Track and Global Privacy Control.
  • Your site blocks outside scripts: If your site uses a Content Security Policy, ask your developer to allow https://api.srctk.com.
  • Still nothing: See Troubleshooting.

Google tag gateway (optional)

Google tag gateway serves Google's own tag from your own domain instead of from googletagmanager.com. It is Google's feature. You set it up in your Google tag settings and on your CDN or server. If you do not use it, skip this section.

NoteThis is about Google's tag only. It does not change what SourceTrack records.
  • For Amazon CloudFront, Google offers a guided workflow in Tag Assistant that walks you through the steps in the AWS console.
  • Follow Google's current Google tag gateway setup guide. It is the authority and can change.

Check that it works

Your setup checks may show a note that links here. Use Google's two health checks, with the path you chose in place of /metrics:

  • Open https://yourdomain.com/metrics/healthy. The page should read ok, which checks the tag and the routing.
  • Open https://yourdomain.com/metrics/?validate_geo=healthy. The page should read ok, which checks that visitor location is passed on.

Next step

Count the actions that matter, like form submits or button clicks, with the Browser Conversions guide.

The script does not detect purchases. They come from a Shopify or Stripe connection, the SourceTrack WordPress plugin (WooCommerce), or a sourcetrack.conversion() call. To send the GA4 purchase events your site already pushes to the dataLayer, see GA4 dataLayer events via GTM.

Still stuck?

Email support@sourcetrack.ai with your site and what you have tried.

Start 28-day free trial
  • Google Ads
  • Meta
  • LinkedIn
  • Microsoft Ads
  • TikTok
  • Stripe
  • Shopify
  • HubSpot
  • GA4
  • Search Console
  • WooCommerce
  • Webflow
  • WordPress
  • Typeform
  • Calendly
  • Intercom
  • Zapier
Works with