Skip to content

GTM Deployment

John Williams edited this page Mar 11, 2026 · 1 revision

GTM Deployment Guide

Deploy any script from this repo via Google Tag Manager — no code deploys, fully versioned, testable before going live.


Why GTM?

  • No code deploys required
  • Preview mode lets you test before publishing
  • Full version history — roll back instantly
  • Works across Salesforce, HubSpot, WordPress, Shopify

Step 1 — Create the Tag

  1. GTM → TagsNew
  2. Tag Configuration → Custom HTML
  3. Paste the appropriate script from /scripts/
  4. Update the CONFIG section (field names, property internal names, etc.)

Step 2 — Set the Trigger

⚠️ Critical: use All Page Views, not just the form page.

The GCLID arrives on the landing page URL. The script needs to fire there to read it from the URL and store it in localStorage. On subsequent pages, it reads from localStorage and writes to the form field.

Trigger: All Pages → Page View


Step 3 — Test in Preview Mode

  1. Click Preview in GTM
  2. Enter your URL with ?gclid=TEST_123 appended
  3. Navigate to your form page in the same session
  4. In the GTM Tag Assistant panel, confirm your tag appears in "Tags Fired"
  5. Open browser console and run:
    // Replace with your actual field name
    document.querySelector('[name="Gclid__c"]').value
    // Should return: "TEST_123"
  6. ✅ Pass → close Preview → Submit

Step 4 — End-to-End Test

After publishing:

  1. Visit: yourdomain.com/landing-page?gclid=TEST_LIVE_001
  2. Navigate to your form page and submit with a test email
  3. Check CRM — the GCLID field on the new lead must show TEST_LIVE_001

Finding Your Field Names

// Paste in DevTools console on your form page
Array.from(document.querySelectorAll('input[type=hidden]'))
  .map(i => ({ name: i.name, id: i.id, value: i.value }))
  .filter(i => i.name || i.id)
  .forEach((i,n) => console.log('['+n+']', JSON.stringify(i)));

Compare the name values to what you have in the script's CONFIG. Case-sensitive: Gclid__cgclid__c.

Clone this wiki locally