This guide ensures the Facebook Click ID is captured from the URL, stored in a 1st-party cookie, and passed to both the Meta Pixel and Conversions API (CAPI) using Google Tag Manager.
Part 1: Implementation Steps
1. Capture the ID (Web Container)
Variable: Create a URL variable named
{{URL - fbclid}}with Query Keyfbclid.Cookie Setter Tag: Create a Custom HTML Tag with the script below. Set the trigger to All Pages (Container Loaded).
HTML
<script>
(function() {
var urlParams = new URLSearchParams(window.location.search);
var fbclid = urlParams.get('fbclid');
if (fbclid) {
var timestamp = new Date().getTime();
var fbcValue = 'fb.1.' + timestamp + '.' + fbclid;
var date = new Date();
date.setTime(date.getTime() + (90 * 24 * 60 * 60 * 1000)); // 90 Days
document.cookie = "_fbc=" + fbcValue + "; expires=" + date.toUTCString() + "; path=/; domain=." + location.hostname.replace(/^www\./, "");
}
})();
</script>
2. Configure the Data Bridge
1st-Party Cookie Variable: Create
{{Cookie - fbc}}for cookie name_fbc. In settings, check “Convert undefined to…” and leave it blank.Google Tag (GA4): Set the trigger to All Pages (Container Loaded). In Configuration Parameters, add:
Field:
x-fb-ck-fbc| Value:{{Cookie - fbc}}
3. Map to Server (Server Container)
Event Data Variable: Create
{{ED - x-fb-ck-fbc}}with Key Pathx-fb-ck-fbc.Meta CAPI Tag: Map the Click ID field to
{{ED - x-fb-ck-fbc}}.
Part 2: How to Check if it Works
1. Browser Level (The Cookie)
Visit your site with
?fbclid=TEST_IDin the URL.Open Inspect > Application > Cookies.
Verify
_fbcexists with the format:fb.1.[timestamp].TEST_ID.
2. GTM Level (The Data Flow)
Web Preview: Click the Google Tag. Under Configuration Parameters, confirm
x-fb-ck-fbchas a value (not “undefined”).Server Preview: Click the incoming
/collectrequest. In the Event Data tab, confirmx-fb-ck-fbcis present with the correct string.CAPI Tag: Under the Tags tab in Server Preview, click the Meta CAPI tag. Check the outgoing payload for the “fbc” or “Click ID” field.
3. Meta Level (The Processing)
In Meta Events Manager, go to Test Events.
Navigate your site. Confirm “Server” events appear.
Click an event and verify the fbc parameter is listed under event details.