Meta Pixel + Cookie-Einwilligung: Die praktische Einrichtungsanleitung
Wie man den Meta (Facebook) Pixel DSGVO-konform installiert — Skriptblockierung, die Marketing-Kategorie, Conversions API, Widerruf und wie man verifiziert, dass es wirklich funktioniert.
Veröffentlicht am
The Meta Pixel (still called the Facebook Pixel by most of the people who install it) is one of the most widely deployed pieces of third-party JavaScript on the open web. It is also one of the most lawsuit-prone. Belgian, French, Spanish, and Italian regulators have all gone after sites running it without explicit consent. Fines have landed in the low thousands for small sites and the millions for big publishers.
The Pixel drops cookies. It sends user data to Meta. That data feeds the same ad-targeting machine as Facebook itself. So it is marketing tracking, full stop. You cannot fire it before consent and stay GDPR-compliant.
Getting the install right is not hard. The details matter, though, and most guides skim them. This is what actually works.
Why the Pixel needs special handling
Unlike Google Analytics, the Pixel does not support Google Consent Mode. No cookieless ping, no fallback signal that lets Meta model denied users. The tag either runs or it does not. Every denied visitor is a hard zero in your Pixel data.
Meta added their own consent calls in 2024: fbq('consent', 'grant') and fbq('consent', 'revoke'). I'd skip them. The revoke call only stops future events. The PageView that fired before the visitor said no is already gone. The safer pattern is to never load the Pixel at all until consent is granted.
Three ways to do this
Script blocking via the CMP. Drop the Pixel snippet in <head> with type="text/plain" and a category attribute the CMP recognises. The CMP rewrites the type after consent and the browser executes the script. Works in any environment, including static HTML. This is what ConsentTrustee uses by default.
Conditional injection via JavaScript. Wait for the CMP's consent-granted event, then inject the Pixel snippet dynamically. There is a tiny delay for consented visitors because the snippet has to fetch after the accept click. Cleaner if you want zero Pixel DOM presence before consent.
Through Google Tag Manager. Wrap the Pixel in a GTM tag, gate it on a consent trigger. Fine if GTM already runs everything else. Overkill for one pixel otherwise.
For most sites, script blocking is the right call. It is the simplest setup, and it survives caching plugins without the weird race conditions you hit with conditional injection.
The actual install
Start with Meta's base code from Events Manager (replace YOUR_PIXEL_ID with your numeric ID):
<script type="text/plain" data-ct-category="marketing">
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>Two things matter. The type="text/plain" stops the browser from executing the script on load. Browsers only run scripts with a JavaScript MIME type, so anything else sits there as inert text. The CMP rewrites that to text/javascript after consent and the browser parses it.
The data-ct-category="marketing" attribute is how the CMP knows which consent category controls this tag. The Pixel is marketing. It feeds Meta's ad engine. Do not get cute and file it under statistics or functionality because all you do is read attribution reports. EU regulators treat the Pixel as marketing every time the question has come up.
The noscript fallback
Meta's snippet includes a <noscript> 1×1 tracking pixel for visitors with JavaScript disabled. That fallback bypasses every CMP because there is no JS to intercept it. Delete it. The trickle of JS-disabled traffic is not worth the compliance hole, and any regulator would call it a violation since there is no consent mechanism at all.
The Conversions API is not a workaround
CAPI is Meta's server-side event API. A lot of sites adopted it after iOS 14 broke browser-side tracking, and it gets pitched in dev forums as a way to recover “lost” data. It is not a way to bypass consent. The same GDPR rules apply. If a visitor declined cookies and you send their IP and email to Meta via CAPI, you have still processed personal data without consent. Don't.
If you do use CAPI, gate it on the same consent state as the browser Pixel. Easiest way: send a consent flag with every server-side event and drop the event upstream if the flag says no.
What the Pixel actually drops
ConsentTrustee's scanner picks up four Pixel-related cookies:
_fbp— first-party cookie holding a browser fingerprint Meta uses to match users across sites._fbc— first-party cookie storing the click ID for attribution when a user lands on your site from a Facebook ad.fr— third-party onfacebook.com, used for ad targeting and frequency capping.tr— third-party tracking endpoint, occasionally stored as a cookie.
All four are marketing. If your CMP filed _fbp under statistics because it is first-party, the CMP is wrong. The category is about purpose, not technical placement.
Verifying it works
The good news: Meta ships a Chrome extension called Pixel Helper that surfaces every Pixel loaded on the current page and every event fired. It is the fastest way to sanity-check the install.
Open your site in an incognito window with the extension on. First load, no consent yet. Pixel Helper should show nothing. If it shows your Pixel and a PageView event, your consent gate is not actually gating. The script is firing before the CMP intercepts. Common causes: missing type="text/plain", wrong category attribute, or a CDN or cache plugin that strips the type attribute during HTML minification.
Click Accept on the banner. Reload. Pixel Helper should now show the Pixel loaded and PageView fired. If you see “loaded” but no event, the init code did not run. Usually a syntax issue from however the CMP reinjects the script.
Network tab is the second confirmation. Filter for connect.facebook.net/en_US/fbevents.js (the Pixel JS) and www.facebook.com/tr/ (the event endpoint). Both absent before consent. Both present after.
Custom events
Most sites fire more than just PageView. AddToCart, InitiateCheckout, Purchase, custom events for form submissions. They all need the same gate. The simplest pattern is to wrap event calls:
function trackPixelEvent(eventName, params) {
if (typeof fbq !== 'function') return;
fbq('track', eventName, params);
}Because the CMP only injects the Pixel after consent, fbq will not exist for denied visitors. The guard turns event calls into silent no-ops instead of ReferenceErrors. One source of truth, no parallel consent state to maintain in app code.
Purchase events: where this usually breaks
The Purchase event is your highest-value data point to Meta. It is also the most common place teams accidentally lose tracking.
Classic scenario. Visitor accepts cookies on the landing page. Browses. Adds to cart. Checks out. Hits the order confirmation page. But the confirmation page is on checkout.example.com (different subdomain), or it is served from a third-party platform like Shopify Plus or Stripe Checkout. The consent cookie set on www.example.com does not carry over. The Pixel on the confirmation page sees “no consent” and does not fire. Purchase data lost.
Two fixes. Configure the CMP's consent cookie at the eTLD+1 (.example.com) so subdomains share it. And if your checkout lives on a fully separate platform, propagate the consent state via a URL parameter on the redirect, then re-apply it on the destination before the Pixel snippet runs. The WooCommerce install guide walks through the same problem in a different shape.
When the visitor withdraws consent
When someone toggles marketing off in the preferences modal, the Pixel should stop firing future events. This is harder than it sounds because fbq is already in the page. You cannot unload a script. Three options:
Reload the page. Simplest. Most reliable. Some CMPs do this automatically on withdrawal. New pageview, no Pixel loaded because consent is now denied, cookies cleared by the CMP's cookie reset.
Call fbq('consent', 'revoke'). Meta's native option. Stops future events but leaves the cookies in place. Pair it with explicit _fbp / _fbc deletion if you go this route.
Delete window.fbq. Crude but it works. delete window.fbq after withdrawal means any subsequent event call hits an undefined reference and silently fails. Don't forget the cookies.
The reload approach is the cleanest. The revoke-and-clear path avoids the visual jolt of a reload. Pick based on how strongly you feel about page flashes.
Before you ship
Walk through this list:
- Pixel snippet has
type="text/plain"and the marketing category attribute <noscript>fallback removed- Pixel Helper shows nothing on first load in incognito
- Pixel Helper shows Pixel + PageView after Accept
_fbpcookie is not set before Accept, is set after- Custom events guarded with
typeof fbq === 'function' - Consent cookie scoped to eTLD+1 if your checkout is on a subdomain
- CAPI events gated on the same consent flag as the browser Pixel
- Withdrawal path either reloads or revokes + clears cookies
What I'd read next
Google Tag Manager + Cookie Consent if you run the Pixel through GTM rather than directly. Block Third-Party Scripts for the wider pattern that gates more than just Meta. And Google Consent Mode v2 for the context on why GA can do cookieless pings while the Pixel cannot.