Adflix Consulting
Tracking guide

How to Capture fbclid and Store It in a Cookie with Google Tag Manager

By Arafat · Updated November 2026 · 5 min read

Meta adds a click ID called fbclid to the link when someone clicks your ad. If your site does not keep it, the lead or sale arrives with no link to the ad, and Meta reports less than it should. This guide shows how to keep the click ID across pages.

Upwork Top RatedGoogle Ads Certified

What fbclid is

fbclid is a short code that Meta adds to the address of the landing page after a click on a Meta ad. It helps match a later sale or lead back to the ad. The code is only in the first page's address, so it disappears as soon as the visitor clicks to another page.

Why it matters

Without the click ID, Meta has less to match. Your reports show fewer conversions from Meta than really happened, and the algorithm learns from less data. A first-party cookie keeps the click ID for a set time, so the form or checkout can still send it.

Step 1: Read the parameter in Google Tag Manager

  1. Create a Custom JavaScript variable that reads fbclid from the page address.
  2. Return the value, or an empty string if there is none.

Step 2: Save it in a first-party cookie

  1. Create a Custom HTML tag that writes a cookie named fbclid only when the variable has a value.
  2. Set the cookie path to / and an expiry of 90 days.
  3. Fire the tag on All Pages, and only when the visitor accepted the matching cookie choice.

Step 3: Send it with the lead or sale

Add a hidden field to your form, or a parameter to your purchase event, that reads the cookie. Your CRM then stores the click ID next to the lead, and the sale can be sent back to Meta with it.

Consent and privacy

The click ID is personal data in many countries. Only save it when the visitor has accepted the relevant cookie choice, and say so in your privacy policy. Do not store anything else in the same cookie.

Test it

  • Open your landing page with ?fbclid=test123 at the end of the address.
  • Browse to another page, then check that the cookie still holds test123.
  • Submit a test form, and check that the hidden field carries the value.

Want this set up on your site? Book a free 30-minute call and I will check your tracking with you.

Book a free 30-minute call

Questions

Is fbclid the same as the Meta pixel?

No. The pixel sends events. fbclid is a click ID in the address that links a click to a later event.

How long should I keep the cookie?

Many setups use 90 days. Use the period that matches your sales cycle and your privacy policy.