Fix guide · Shopify · medium · about 30 min
TikTok Pixel fires before cookie consent on Shopify
For the finding “TikTok Pixel fires before cookie consent”. Also for: Any website, WordPress, Webflow, Framer.
What this means
Your store shows a cookie banner, but the TikTok Pixel sent data to TikTok while the banner was still waiting for an answer.
On Shopify, pixels under Settings > Customer events (app pixels and custom pixels) follow your customer privacy settings: where consent is required, they run only after the visitor has given the permissions the pixel needs. Code in your theme, Google Tag Manager (GTM) loaded from the theme, and scripts added by app embeds are not controlled by those settings; Shopify says such pixels may need a third-party banner or custom logic to honor consent. TikTok’s standard base code sends a page view as soon as it loads (ttq.load(...) followed by ttq.page()), so a copy outside Shopify’s pixel manager measures every visitor from the first second.
TikTok’s own TikTok app (the sales channel) installs the pixel without theme code, but TikTok’s Shopify help does not say how that pixel handles cookie consent. Check it on your store (step 3 below) instead of assuming.
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 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.
- The banner and that copy of the pixel are not connected. When this is fixed in a hurry, the usual result is the opposite problem: the pixel stops firing entirely and your TikTok campaigns lose their data.
How to confirm it yourself
Our check runs from a browser in the EU. Shopify shows its cookie banner based on where the visitor is and on the regions set under Settings > Customer privacy (with automated settings, visitors in the EEA and the UK). If you are elsewhere, use a VPN with a European location or ask a colleague in the EU.
- Open your store in a private (incognito) window.
- Open developer tools (F12), go to the Network tab and type
analytics.tiktok.com/apiinto the filter box. - Reload the page. Do not click the cookie banner.
- If requests to
analytics.tiktok.com/api/v2/pixelappear while the banner is still showing, the pixel fires before consent. In the request payload,eventis the event name andcontext.pixel.codeis your pixel ID. Requests that only load script files (such asevents.js) are not events. - In the same payload, look at the page address the pixel reports (under
context,page,url). Shopify documents that custom pixels run in a sandbox frame whose address is not your store page. So if the address is a Shopify sandbox address (it contains/sandbox/), the request came from a custom pixel. Your normal page address means code on the page or an app.
The TikTok Pixel Helper extension and Test Events in TikTok Events Manager (Tools > Events > Data sources > your pixel) show the same from TikTok’s side; see the general guide for those steps.
How to fix
The goal: every copy of the TikTok Pixel either goes through Shopify’s customer privacy settings or is removed.
-
Find every copy of the pixel. Check:
- Sales channels > TikTok: whether the app is installed, which data sharing level it uses (Standard, Enhanced or Maximum) and which pixel it is connected to.
- Settings > Customer events: app pixels (TikTok and other marketing apps; the More options menu next to each one has View customer privacy) and custom pixels (search each one for
ttqor your pixel ID). - Theme code: go to Online Store, open the menu of your current theme and click Edit code. Open
theme.liquidand search foranalytics.tiktok.com,ttq.loadandGTM-. Check the snippets your theme includes as well. - App embeds: Online Store > Edit theme > App embeds icon. Third-party tracking apps often add code here.
- Your GTM container, if the theme loads one: TikTok Pixel tags and Custom HTML tags containing
ttq.
-
Remove the copies that bypass Shopify’s settings. Delete the TikTok base code from
theme.liquidand click Save, remove the TikTok tags from a theme-loaded GTM container, and turn off app embeds that add another TikTok pixel. With the TikTok app connected, a theme copy is redundant anyway: TikTok says the app needs no changes to website code. -
Retest, then check the TikTok app’s pixel. Repeat the private-window test. If events still leave before consent with the pixel ID connected in the TikTok app, look for TikTok under Settings > Customer events. Shopify lists only apps that use its Web Pixels API there.
- If TikTok is listed, View customer privacy shows the permissions it requires. Shopify says the app partner determines these settings, so contact TikTok support with your test result.
- If it is not listed, Shopify’s pixel manager does not load that pixel, and your privacy settings do not hold it back. Contact TikTok support, or disconnect the app’s pixel and use a custom pixel (step 4). TikTok does not document this screen; Elevar, a third-party tracking vendor, describes it as Sales channels > TikTok > Settings > Data sharing, then Disconnect under Customer Data Sharing.
-
If you use a custom pixel, open it under Settings > Customer events. In the Customer privacy section, set Permission to Required and select Marketing. Not required means it runs whether or not the visitor has answered the banner. In Shopify’s sandbox, TikTok’s code may not see
ttclidin the address or keepttclidand_ttpon your store’s domain; see TikTok click ID lost on Shopify. The sandbox runs JavaScript only, so remove<script>and<noscript>tags from TikTok’s code, then save. Shopify handles consent here, so do not addttq.holdConsent()unless the code also callsttq.grantConsent(). -
If you need GTM, Shopify recommends running it as a custom pixel; step 4 then applies to the whole container. If GTM stays in
theme.liquid, each TikTok tag needs Advanced Settings > Consent Settings > Require additional consent for tag to fire withad_storage(TikTok’s template has no consent fields), and your banner must send Google consent updates to GTM. Check this in GTM’s Preview mode. -
Check Settings > Customer privacy. With automated settings on, Shopify shows its banner to visitors in the EEA and the UK when those are among your markets. If you chose regions yourself, make sure every region where you need consent is selected.
-
If you use a consent app instead of Shopify’s banner, check that it is integrated with Shopify’s Customer Privacy API (see the app’s documentation). Shopify’s pixels learn about the visitor’s choice only through that API.
-
For code that must stay in the theme (a developer task), combine TikTok’s consent mode with Shopify’s Customer Privacy API. Add
"holdConsent", "revokeConsent", "grantConsent"to thettq.methodslist in the base code, then:ttq.holdConsent(); // before ttq.load ttq.load('<YOUR PIXEL ID>'); ttq.page(); // queued until consent window.Shopify.loadFeatures([{ name: 'consent-tracking-api', version: '0.2' }], (error) => { if (error) return; const privacy = window.Shopify.customerPrivacy; if (privacy.marketingAllowed()) ttq.grantConsent(); else if (privacy.currentVisitorConsent().marketing === 'no') ttq.revokeConsent(); }); document.addEventListener('visitorConsentCollected', (event) => { if (event.detail.marketingAllowed) ttq.grantConsent(); else ttq.revokeConsent(); });grantConsent()sends the queued page view, so the landing page is not lost. Do not callrevokeConsent()before the visitor answers: it drops the queue.
Common causes
- TikTok base code is still in
theme.liquid, added by hand or by an agency before or next to the TikTok app. - GTM is loaded from
theme.liquid, and its TikTok tags have no consent requirement. - A custom pixel has Permission set to Not required.
- A third-party app adds its own TikTok pixel through an app embed and does not wait for consent.
- A consent app is not connected to Shopify’s Customer Privacy API, or the banner regions leave out some countries.
- Theme code calls
ttq.holdConsent()afterttq.load()andttq.page(), so the first page view has already left.
How to verify the fix
- In a private window with a European location: no
analytics.tiktok.com/api/v2/pixelrequests before you answer the banner, a page view request right after you click “Accept” (on the same page), and no page view or conversion events after “Reject” in a fresh private window. If Shopify’s privacy settings, your consent app or GTM hold back the pixel, there should also be no_ttporttclidcookies before you answer. TikTok does not document whether its consent mode (step 8) holds back cookies, so with that route judge by the event requests. - For a custom pixel, Shopify’s Pixel Helper (click Test on the pixel under Settings > Customer events) shows “Pixel is awaiting consent” until you accept.
- 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 app for Shopify respect cookie consent?
TikTok’s Shopify help articles do not mention cookie consent or Shopify’s Customer Privacy API. Shopify says app pixels listed under Customer events honor the visitor’s consent choices. Check whether TikTok is listed there, and use the private-window test above to see what the pixel does on your store.
Sources
- Shopify Help Center, Pixels overview (in consent-required markets, pixels run only with the required permissions): https://help.shopify.com/en/manual/promoting-marketing/pixels/overview
- Shopify Help Center, App pixels (only apps that use the Web Pixels API are listed; View customer privacy; settings determined by the app partner): https://help.shopify.com/en/manual/promoting-marketing/pixels/app-pixels
- Shopify Help Center, Manage your custom pixels (Permission Required / Not required): https://help.shopify.com/en/manual/promoting-marketing/pixels/custom-pixels/manage
- Shopify Help Center, Create custom pixel code (JavaScript only, remove HTML): https://help.shopify.com/en/manual/promoting-marketing/pixels/custom-pixels/code
- Shopify Help Center, Testing custom pixels (“Pixel is awaiting consent”): https://help.shopify.com/en/manual/promoting-marketing/pixels/custom-pixels/testing
- Shopify Help Center, Configuring customer privacy settings (automated settings, regions, manually installed pixels, third-party banners): https://help.shopify.com/en/manual/privacy-and-security/privacy/customer-privacy-settings/privacy-settings
- Shopify Help Center, Extend your theme with apps (app embeds): https://help.shopify.com/en/manual/online-store/themes/customizing-themes/apps
- Shopify Help Center, Google Tag Manager (use GTM through a custom pixel): https://help.shopify.com/en/manual/reports-and-analytics/google-analytics/google-tag-manager
- Shopify.dev, About web pixels (custom pixels run in a sandbox iframe; app pixels honor consent): https://shopify.dev/docs/apps/build/marketing/pixels
- Shopify.dev, Customer Privacy API (
loadFeatures,marketingAllowed,currentVisitorConsent,visitorConsentCollected): https://shopify.dev/docs/api/customer-privacy - TikTok Business Help Center, About TikTok on Shopify (pixel and Events API installed with no changes to website code): https://ads.tiktok.com/resources/help/article/tiktok-app-shopify?lang=en
- TikTok Business Help Center, Data Sharing on TikTok App on Shopify (Standard, Enhanced, Maximum): https://ads.tiktok.com/resources/help/article/data-sharing-tiktok-app-shopify?lang=en
- TikTok API for Business, Pixel Cookie consent mode (
holdConsentbeforettq.load, queued events sent ongrantConsent, dropped onrevokeConsent,ttq.methods): https://business-api.tiktok.com/portal/docs?id=1795929012554754 - TikTok API for Business, Install Pixel using code (base code with
ttq.loadandttq.page): https://business-api.tiktok.com/portal/docs?id=1739585702922241 - TikTok Business Help Center, How to use cookies with TikTok Pixel (notices and consents): 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,ttcsidare advertising cookies): https://ads.tiktok.com/resources/help/article/using-cookies-with-tiktok-pixel?lang=en - TikTok on GitHub, TikTok Pixel GTM template (no consent fields): https://github.com/tiktok/gtm-template-pixel
- Elevar (third-party vendor; TikTok does not document this screen), How to disable TikTok Pixel in Shopify: https://docs.getelevar.com/docs/how-to-disable-tiktok-pixel-in-shopify
- Google Tag Manager Help, Tag Manager consent mode support: https://support.google.com/tagmanager/answer/10718549