Fix guide · WordPress · medium · about 45 min

Meta Pixel fires before cookie consent on WordPress

For the finding “Meta Pixel fires before cookie consent”. Also for: Any website, Shopify, Webflow, Framer.

What this means

Your WordPress site shows a cookie banner, but the Meta Pixel (still often called the Facebook Pixel) sent data to Meta while the banner was still waiting for an answer. On WordPress this usually means the pixel is loaded by a plugin, a theme setting or a code snippet that your consent plugin does not control.

Why it costs you money:

  • If you advertise to people in the EU, sending marketing data before consent is a legal risk you probably did not intend to take. We report the technical behaviour only; we cannot tell you whether your setup is compliant.
  • The banner and the pixel are not connected. When this is fixed in a hurry later, the usual result is the opposite problem: the pixel stops firing and your ads lose their data.

How to confirm it yourself

Our check runs from a browser in the EU, so the site behaves as it would for an EU visitor. If your consent plugin only shows the banner in some regions, use a VPN or ask a colleague in the EU.

  1. Log out of WordPress, or use a private (incognito) window. Several plugins behave differently for logged-in users: some tracking plugins skip administrators, and optimization plugins can serve logged-in users different, unoptimized pages.
  2. Open developer tools (F12), go to the Network tab and type facebook.com/tr into the filter box.
  3. Load the page. Do not click anything on the cookie banner.
  4. If facebook.com/tr requests appear while the banner is still on screen, the pixel fires before consent. In Chrome they may show the type ping, because the pixel uses sendBeacon. In the request payload, id is your pixel ID and ev is the event name.

Meta Ads Data Advisor (Meta’s Chrome extension, formerly Meta Pixel Helper) and the Test events tool in Meta Events Manager (Data sources > your pixel > Test events, then Open website) show the same thing: watch whether PageView arrives before you accept.

How to fix

  1. Find every place the pixel comes from. Right-click the page, choose View page source and search for fbevents.js and fbq(. The code around each hit often names its source (a plugin’s script path or an HTML comment). The usual sources on WordPress:
    • Meta’s own plugins: Meta Pixel for WordPress (Settings > Meta) and, on WooCommerce stores, Meta for WooCommerce (formerly Facebook for WooCommerce, under Marketing > Facebook).
    • Tracking plugins such as PixelYourSite or Pixel Manager for WooCommerce.
    • A Google Tag Manager (GTM) container with a Meta tag inside, added by Site Kit by Google, GTM4WP or a snippet in the theme.
    • Code you pasted yourself: a snippet plugin such as WPCode, Elementor Pro’s Custom Code, a theme’s header code field (for example Divi’s Theme Options > Integration tab), or the theme’s header.php file.
  2. Keep one source and remove the others. A second installation usually sits outside your consent setup, and it also sends every event twice (see “Duplicate Meta Pixel events on WordPress”).
  3. Put that source under your consent plugin’s control. The plugin pages of Meta’s two plugins describe no consent setting, and neither is on the WP Consent API’s list of plugins that wait for consent. The WP Consent API only shares the visitor’s choice; it does not block anything. So your consent plugin has to block the pixel itself:
    • Complianz: under Complianz > Integrations, the Plugins tab lists recognized plugins; Complianz has integrations for both Meta plugins and PixelYourSite, in the marketing category. For a snippet or theme field, add a Script Center entry that blocks by URL (connect.facebook.net) or by text (fbq), in the marketing category.
    • CookieYes: in the Cookie Manager, add the pixel to the Advertisement category with a script URL pattern such as connect.facebook.net, or add data-cookieyes="cookieyes-advertisement" to the pixel’s script tag if it loads from a src URL.
    • Cookiebot: use the plugin’s automatic blocking mode, or in manual mode change the pixel’s script tag to type="text/plain" and add data-cookieconsent="marketing". The plugin also has add-ons for some plugins, including both Meta plugins; check that the add-on for yours is switched on.
    • Borlabs Cookie: look in the Library for a package for the service or plugin that loads your pixel. If there is none, create a Script Blocker for that plugin’s JavaScript (it also blocks inline scripts), or add the pixel as a custom service with the base code as its opt-in code and remove the other copy.
    • Real Cookie Banner: either let it load the pixel as a service (the PRO version has a Meta Pixel template) and remove every other copy, or keep your plugin and add a content blocker for it.
    • PixelYourSite: in its consent settings, switch on the integration for your consent plugin. Its documentation lists ConsentMagic, Cookiebot, Cookie Notice, CookieYes and Real Cookie Banner.
    • Google Tag Manager: in the Meta tag’s Advanced Settings > Consent Settings, choose Require additional consent for tag to fire and add ad_storage. This only works if your consent plugin sends Google Consent Mode updates to GTM.
  4. Check caching and optimization plugins. WP Rocket, LiteSpeed Cache, Autoptimize and similar plugins can minify, combine, defer or delay scripts. Consent plugins recognize the pixel by its script URL or code; once that code is merged into a combined file, they may no longer recognize it (Complianz’s documentation describes this). Exclude the pixel code and your consent plugin’s scripts from combining and delaying, as your consent plugin’s documentation describes, then clear every cache: the plugin’s, your host’s and your CDN’s.
  5. Check the banner’s mode and regions. For EU visitors the banner must ask first (opt-in), not just show a notice.
  6. Make sure “Accept” starts the pixel on the same page, so you do not lose the landing page view. See “Meta Pixel not firing after cookie consent on WordPress”.

Common causes

  • The pixel was added through a snippet plugin, a page builder or a theme setting, and the consent plugin was installed later without being told about it.
  • A tracking plugin loads the pixel, and the consent plugin’s integration or add-on for it is off or missing.
  • The consent plugin shares consent through the WP Consent API, but the plugin that loads the pixel does not read it.
  • An optimization plugin combines or delays scripts, so the consent plugin no longer recognizes the pixel code.
  • The Meta tag in GTM has no consent requirement, or the banner only shows a notice for the visitor’s region.

How to verify the fix

  1. Clear all caches, then repeat the test above while logged out: no facebook.com/tr requests before you answer the banner, and requests appear right after you click “Accept”.
  2. Click “Reject” in a fresh private window: no facebook.com/tr requests at all.
  3. Re-run the check on IsPixelWorking. The issue should be gone, and “Meta Pixel does not fire after consent” should not appear in its place.

Sources