Blog

Pass URL parameters from client GTM to sGTM

Click IDs, UTM parameters, and gclid all need to survive the hop from page to tagging server. Here is how each one travels.

Click IDs (gclid, fbclid, ttclid, li_fat_id) and UTM parameters arrive on landing pages as URL parameters. To attribute conversions correctly downstream, those values need to make it from the page where they arrived to the conversion event sent to your tagging server, often hours or days later.

The pattern: capture once, store, forward

  1. On every page load, check the URL for relevant parameters.
  2. If found, store in a first-party cookie with a long expiry (90 days for click IDs, session for UTMs).
  3. On every conversion event, read from the cookie and include in the payload.

The capture snippet

const params = new URLSearchParams(location.search);
const click_ids = ['gclid', 'fbclid', 'ttclid', 'li_fat_id', '_gl'];
click_ids.forEach(name => {
  const value = params.get(name);
  if (value) {
    document.cookie = `_${name}=${value}; max-age=7776000; path=/; secure; samesite=lax`;
  }
});

90-day cookie lifetime matches typical attribution windows. SameSite=Lax keeps the cookie on top-level navigations.

In your client GTM

Create a Variable for each click ID that reads the corresponding cookie. Reference these variables in your conversion tags so the values are forwarded to your tagging server as event parameters.

In your sGTM

The Meta CAPI tag template expects fbclid as user_data.fbc. The TikTok template expects ttclid as ttclid. The Google Ads template handles gclid via the standard click_id field. The LinkedIn template expects li_fat_id as acxiomId.

UTM parameters: session-scoped

Unlike click IDs, UTM parameters should not persist across sessions. They reflect the source of the current visit. Store in sessionStorage or use a session cookie that expires when the browser closes.

If you persist UTMs in a long-lived cookie, you misattribute every subsequent conversion to the original source. A user who arrived from a Google ad in March and converts in June via a direct visit will appear as a Google conversion in June, which is wrong.

The fbc edge case

Meta has a specific format for fbc: fb.{subdomainIndex}.{creationTime}.{fbclid}. Most teams just send the raw fbclid and rely on the Meta tag to format it correctly. The tag template handles this if you set the field to "fbclid" rather than "fbc."