Fix guide · Any website · medium · about 30 min
TikTok Pixel fires before cookie consent: how to fix it
For the finding “TikTok Pixel fires before cookie consent”. Also for: Shopify, WordPress, Webflow, Framer.
What this means
Your site shows a cookie banner, but the TikTok Pixel sent data to TikTok while that banner was still waiting for an answer. The banner is on screen, yet it is not controlling the pixel.
TikTok’s standard base code sends a page view as soon as it loads: it ends with ttq.load('<PIXEL ID>'); ttq.page();. Unless something holds it back, it measures every visitor from the first second.
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. TikTok itself asks advertisers to provide notices and obtain consents as required by applicable laws. We report the technical behaviour only; we cannot tell you whether your setup is compliant.
- It usually means the banner and your tags are not connected at all. When this gets fixed in a hurry, the common result is the opposite problem: the pixel stops firing completely and your TikTok campaigns lose their data.
- Your TikTok numbers mix consented and unconsented visitors, so they will shift unexpectedly once the setup is corrected.
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 banner only appears in some countries, use a VPN or ask a colleague there.
- Open a private (incognito) window, so no earlier consent choice is remembered.
- Open the browser’s developer tools (F12, or right-click and choose Inspect), go to the Network tab and type
analytics.tiktok.com/apiinto the filter box. - Load your page. Do not click anything on the cookie banner.
- If requests to
analytics.tiktok.com/api/v2/pixelappear while the banner is still on screen, the pixel is sending events before consent. Click one and look at its payload:eventis the event name (for examplePageview) andcontext.pixel.codeis your pixel ID. Requests that only load the library (events.jsand other script files) are not events. - Open the Application tab (Chrome) or Storage tab (Firefox), then Cookies for your domain. TikTok’s first-party cookies
_ttp(browser ID),ttclid(ad click ID) andttcsid_…are advertising cookies. If they appear before you answer the banner while the pixel is supposed to be blocked (by your consent tool or Google Tag Manager), the pixel ran without consent. TikTok does not document whether its own consent mode (ttq.holdConsent(), below) also holds back cookies, so with that route judge by the event requests.
You can also check with the TikTok Pixel Helper Chrome extension (it lists the pixel’s events on the page), or in TikTok Events Manager: open Tools > Events > Data sources, select your pixel and open Test Events. Open your site from there and watch whether a page view arrives before you accept cookies.
How to fix
The goal: the pixel must not send anything until the visitor has accepted marketing cookies, and it should send the page view right after they accept, on the same page. How you get there depends on how the pixel is installed. Find out first.
- Find every place the pixel is installed. Search the page source (right-click, View page source) for
analytics.tiktok.comandttq.load. Check your site’s header code or theme settings, your Google Tag Manager (GTM) container (the TikTok Pixel template and Custom HTML tags), and any plugins or apps (shop integrations such as TikTok’s own apps, tracking plugins, server-side tools). The fix only works if every copy goes through your consent setup. - Pick one way to gate the pixel and remove the others.
-
TikTok’s cookie consent mode. TikTok documents a “default opt-out” mode. Its standard base code does not include the consent commands, so add them in two places:
- In the loader part of the base code, add
"holdConsent", "revokeConsent", "grantConsent"to thettq.methodslist. - Call
ttq.holdConsent()beforettq.load(...):
ttq.holdConsent(); ttq.load('<YOUR PIXEL ID>'); ttq.page(); // When the visitor accepts marketing cookies: ttq.grantConsent(); // When they reject: ttq.revokeConsent();With
holdConsent(), TikTok queues events instead of sending them.grantConsent()sends them, including the ones queued earlier in the session, so the landing page view is not lost.revokeConsent()drops the queue. ConnectgrantConsent()to your consent tool’s “consent given” event, and call it on every page for visitors who accepted earlier. TikTok asks you to implement this on every page where the pixel is installed. - In the loader part of the base code, add
-
Your consent tool (CMP) blocks the script. Most consent tools can hold back a script until the visitor accepts a category: you change the script’s type and add a category attribute, or let the tool block known trackers automatically. Put the TikTok base code in the marketing (advertising) category, following your tool’s documentation; attribute names differ from tool to tool. If other code calls
ttq.track(...)directly, it must not run before the base code has been released. -
Google Tag Manager. Install the pixel only through GTM (TikTok’s own setup flow in Events Manager creates the tags for you). TikTok’s TikTok Pixel template has no consent fields of its own, so in each TikTok tag’s Advanced Settings > Consent Settings, choose Require additional consent for tag to fire and add
ad_storage(plusad_user_dataif your setup uses it). This works only if your consent tool sends Google Consent Mode updates to GTM; TikTok recommends Google Consent Mode for GTM users. Then make sure the tag’s trigger still fires after consent is given on the same page (see “TikTok Pixel does not fire after consent”).
-
- Make the “accept” path work on the same page. After a visitor clicks “Accept”, the pixel should start right away, not only on the next page. With TikTok’s consent mode this happens through
grantConsent(); with blocking or GTM, check that the released tag sends the page view without a reload. - Publish your changes and clear any site or CDN cache.
Common causes
- The TikTok base code was pasted into the site header (or a theme setting), and the cookie banner was added later as a separate widget that does not know about it.
- The pixel is a GTM tag without a consent requirement. GTM’s Consent Mode adjusts Google tags automatically; a TikTok tag needs its own consent setting.
- A shop app or plugin injects its own TikTok pixel that ignores the consent tool.
ttq.holdConsent()is called afterttq.load()andttq.page(), so the first page view has already left.- The consent tool runs in “notice only” or “implied consent” mode, or is configured to block scripts only outside the EU.
- The consent tool’s script loads after the pixel, so the pixel has fired before blocking can start.
How to verify the fix
- Repeat the private-window test: no
analytics.tiktok.com/api/v2/pixelrequests before you answer the banner, and, if your consent tool or Google Tag Manager blocks the pixel, no_ttporttclidcookies yet. - Click “Accept”: a page view request leaves within a few seconds, on the same page.
- In a fresh private window, click “Reject”: no page view or conversion events.
- Re-run the check on IsPixelWorking. The issue should be gone, and “TikTok Pixel does not fire after consent” should not appear in its place.
Questions people ask
Does the TikTok Pixel have a consent mode?
Yes. TikTok’s pixel cookie consent mode uses ttq.holdConsent(), ttq.grantConsent() and ttq.revokeConsent(). The pixel does not read your banner or Google Consent Mode by itself, so your consent tool or your code has to call these commands.
Does revokeConsent delete data TikTok already received?
No. TikTok says calling ttq.revokeConsent() does not affect data already shared with TikTok; it only stops future (and queued) events.
Sources
- TikTok API for Business, Pixel Cookie consent mode (
holdConsentbeforettq.load, queued events sent ongrantConsent, dropped onrevokeConsent, add the methods tottq.methods, implement on every page): https://business-api.tiktok.com/portal/docs?id=1795929012554754 - TikTok API for Business, Install Pixel using code (base code with
ttq.loadandttq.page, PageView by default, Test Events, Pixel Helper): https://business-api.tiktok.com/portal/docs?id=1739585702922241 - TikTok Business Help Center, How to use cookies with TikTok Pixel (notices and consents, disabling cookies with a tag manager, CMP or the pixel’s consent mode, Google Consent Mode for GTM users): https://ads.tiktok.com/resources/help/article/how-to-use-cookies-with-tiktok-pixel?lang=en
- TikTok Business Help Center, Using cookies with TikTok Pixel (
_ttp,ttclid,ttcsidcookies, advertising cookies): https://ads.tiktok.com/resources/help/article/using-cookies-with-tiktok-pixel?lang=en - TikTok Business Help Center, TikTok Pixel Helper: https://ads.tiktok.com/resources/help/article/tiktok-pixel-helper-2.0?lang=en
- TikTok Business Help Center, Get started with Google Tag Manager (set up from Events Manager): https://ads.tiktok.com/resources/help/article/get-started-google-tag-manager?lang=en
- TikTok on GitHub, TikTok Pixel GTM template (no consent fields): https://github.com/tiktok/gtm-template-pixel
- Google Tag Manager Help, Tag Manager consent mode support (Consent Settings, “Require additional consent for tag to fire”): https://support.google.com/tagmanager/answer/10718549