Skip to Content

Track Cross Domain for Meta Pixel Using

Google Tag Manager

Last Update: 27 October 2025

Introduction


When advertisers track conversions across multiple domains, Meta tracking can easily break, especially when a user moves between sites.

This happens because Meta Pixel stores a unique identifier (_fbc) in a first-party cookie tied to one domain. When users click from a Meta ad and convert on another domain, Meta can’t automatically match that click data to the conversion event.

In this blog post, I’ll show you how to implement cross-domain tracking for Meta Pixel using Google Tag Manager (GTM) and custom JavaScript, ensuring Meta correctly attributes conversions across multiple domains.

Why This Matters


Meta Pixel relies on the _fbc cookie to link website events to ad clicks on Meta’s network.
When a user moves from Site A → Site B, the _fbc value from the first domain doesn’t transfer, leading to underreported conversions.

Proper cross-domain tracking ensures:

✅ Consistent attribution across domains
✅ Better data accuracy in Meta Ads Manager

✅ More optimized ad delivery and conversions

How It Works


Let’s say you have two domains:

Site A → where a Meta ad link first lands.

Site B → where the conversion happens (checkout, signup, etc.).

The goal is to pass the _fbc value from Site A to Site B using a first-party cookie.

This helps Meta identify the same user session and attribute conversions accurately.

Requirements


Before setting this up, make sure:

  • Both domains share the same GTM container ID

  • Meta Pixel is installed on both sites (via GTM or directly)


Step-by-Step Implementation

Step 1: Append fbclid/_fbc/_fbp to Outbound Links (Site A)


  • Tag Type: Create A new Custom HTML
  • Trigger: All Pages (Safe - Script waits for DOM automatically). 

Replace siteB.com with your target domain.


This script reads tracking parameters (fbclid, _fbc, _fbp) from cookies and appends them to outbound links leading to your target domain(s)

<script>
(function () {
// === CONFIG ===
var TARGET_DOMAIN = 'siteB.com'; // <-- Change your destination domain


var KEYS = ['fbclid', '_fbc', '_fbp'];

function getCookie(name) {
var m = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
return m ? decodeURIComponent(m[1]) : '';
}

function setQueryParam(href, key, value) {
if (!value) return href;

var hash = '';
var hashIndex = href.indexOf('#');
if (hashIndex > -1) {
hash = href.substring(hashIndex);
href = href.substring(0, hashIndex);
}

var qIndex = href.indexOf('?');
var base = href;
var qs = '';
if (qIndex > -1) {
base = href.substring(0, qIndex);
qs = href.substring(qIndex + 1);
}

var parts = qs ? qs.split('&') : [];
var found = false;
for (var i = 0; i < parts.length; i++) {
var kv = parts[i].split('=');
if (decodeURIComponent(kv[0]) === key) {
parts[i] = encodeURIComponent(key) + '=' + encodeURIComponent(value);
found = true;
break;
}
}
if (!found) parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));

var newQs = [];
for (var j = 0; j < parts.length; j++) {
if (parts[j]) newQs.push(parts[j]);
}
return base + (newQs.length ? ('?' + newQs.join('&')) : '') + hash;
}

function rewriteLinks() {
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
var a = links[i];

// hostname resolve (anchor trick)
var parser = document.createElement('a');
parser.href = a.href;
var host = parser.hostname || '';

if (host.indexOf(TARGET_DOMAIN) > -1) {
for (var k = 0; k < KEYS.length; k++) {
var val = getCookie(KEYS[k]);
if (val) {
a.href = setQueryParam(a.href, KEYS[k], val);
}
}
}
}
}

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', rewriteLinks);
} else {
rewriteLinks();
}
})();
</script>

Step 2: Capture Params and Set Cookies (Site B)


  • Tag Type: Create a new Custom HTML
  • Trigger: All Pages

This script checks if fbclid, _fbc, or _fbp parameters exist in the URL and stores them in first-party cookies so Meta Pixel can access them across domains.

<script>
(function () {
  var KEYS = ['fbclid', '_fbc', '_fbp'];

  function getQueryParam(name) {
    var regex = new RegExp('[?&]' + name + '=([^&]+)');
    var m = window.location.search.match(regex);
    return m ? m[1] : '';
  }

  function setCookie(name, value, days, domain) {
    if (!value) return;
    var cookie = name + '=' + value + ';path=/';
    if (domain) cookie += ';domain=' + domain;
    if (days) cookie += ';max-age=' + (days * 24 * 60 * 60);
    document.cookie = cookie;
  }

  function getRootDomain() {
    var host = window.location.hostname.split('.');
    if (host.length >= 2) {
      return '.' + host.slice(-2).join('.');
    }
    return window.location.hostname;
  }

  var rootDomain = getRootDomain();
  for (var i = 0; i < KEYS.length; i++) {
    var key = KEYS[i];
    var val = getQueryParam(key);
    if (val) setCookie(key, val, 90, rootDomain);
  }
})();
</script>

Step 3: Verify Tracking


If you’re testing using Meta Pixel Helper, open the Network tab and confirm the _fbc parameter value in the event payload is identical on both domains.

Outcome


After implementing this setup:

  • Users moving between domains retain their original Meta Click ID (_fbc), ensuring consistent attribution.

  • Conversions properly attribute back to the ad click.

  • You’ll see improved event matching and conversion accuracy in Meta Ads Manager.

  • Events show consistent fbc parameter across both domains (verify via Network tab)


Bonus: Server-Side Tagging

When sending events server-side, make sure to forward the same _fbc and _fbp values from your client cookies into your Meta Conversion API (CAPI) requests for proper deduplication.

Conclusion


Cross-domain tracking is essential for accurate Meta attribution in multi-domain user journeys.

By passing and preserving the _fbc parameter between domains, you ensure Meta Ads can correctly identify users and measure conversions.

This method is simple, compliant, and future-proof, and can be expanded easily into server-side setups for even cleaner data.

"Have questions or need help setting up your tracking? Feel free to reach out, I’m happy to help!"

Sanjida Islam Misty

Web Analytics & Tracking Specialist

Social Media

Related Blogs