TikTok7 min read3 views

Shopify TikTok Add to Cart tracking with GTM

Track TikTok AddToCart on Shopify with Customer events and GTM. Map the event payload, check values and test receipt in TikTok.

Watch on YouTube

Jump to the code

The short answer

Track TikTok AddToCart from Shopify's cart-add event, then pass its item data through GTM. Shopify exposes product_added_to_cart for an item added to the cartshopify.dev. This guide is for store implementers replacing a button-click listener with an event subscription and checking the selected variant, quantity and value.

  • GTM trigger: custom_add_to_cart.
  • Shopify event: product_added_to_cart.
  • TikTok event: AddToCart.
  • If an app already sends this event, check it before adding another sender.
  • Steps and settings checked against Shopify and TikTok documentation on 25 October 2026.

Ask an assistant

ChatGPTClaudePerplexity

FREE CALL

30 MIN

Meta stopped counting your leads? Get them counted again.

  1. Pick a time
  2. Check your Meta account with Hassan
  3. See what to do next

On a free 30-minute call, Hassan checks your Meta account with you and shows you what to do next.

Book my free recovery callFree 30-minute call with Hassan.

Not ready to talk? Run a free check

The video shows the older button-click method; the written steps below use Shopify Customer events.

How do I load GTM in Shopify Customer events?

Copy the GTM head loader for your development store's test container. Shopify's GTM tutorialhelp.shopify.com says to remove the HTML script tags from the head loader before pasting it into the pixel editor.

Use a development store, a GTM container reserved for testing, and a TikTok pixel chosen for these tests. Check whether an app or existing script already sends this event before adding another sender.

Shopify calls custom pixels an advanced, unsupported featurehelp.shopify.com. This guide is for implementers who can maintain JavaScript; it is the wrong starting point if you need an app-managed installation.

1. Create the pixel and add the loader

  1. In Shopify, open Settings > Customer events.
  2. Add a custom pixel.
  3. Review its Customer privacy settingshelp.shopify.com and match them to the store's consent requirements.
  4. Paste the loader below into the pixel editor.
  5. Replace GTM-XXXX with your test container ID.
  6. Add the event subscription from step 3 in the same editor.
javascript
// Use the GTM container reserved for your development store.
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXX');

Done when both pieces are in one pixel and the container ID is correct.

How do I add the TikTok base pixel?

Use the base code from the intended pixel in TikTok Events Manager. TikTok documentsads.tiktok.com a Custom HTML base tag with an All Pages trigger.

2. Add the base code to the test container

  1. In GTM, create a Custom HTML tag named TikTok base.
  2. Paste that pixel's base code.
  3. Set its trigger to All Pages.
  4. Retain the store's consent controls on the tag.
  5. Create a Constant variable named Constant - TikTok pixel ID containing the same ID, for the event tag.

Done when the saved base code and variable contain the intended test pixel ID.

How do I track a successful Shopify cart addition?

Subscribe to product_added_to_cart and keep the existing custom_add_to_cart data-layer name. The Shopify event referenceshopify.dev defines the payload used below; a subscription runs your function when Shopify emits that event.

3. Add the event subscription

The code uses cartLine.cost.totalAmount and cartLine.quantityshopify.dev from the addition event; the example calculates unit value by dividing that line amount by its quantity. Shopify's event referenceshopify.dev allows cartLine to be null; the code then stops with the message AddToCart mapping needs cartLine instead of sending an event with no line.

Shopify allows merchandise.id to be nullshopify.dev. The guard leaves that entry out of items while keeping the event, value and currency.

  1. Append the JavaScript below after the loader.
  2. Test the subscription and GTM mapping locally with a synthetic product_added_to_cart payload containing valid money and quantity but merchandise.id: null.
  3. Repeat the test with a real variant ID.
javascript32 lines
window.dataLayer = window.dataLayer || [];analytics.subscribe("product_added_to_cart", (event) => {  const line = event.data.cartLine;  if (!line) {    throw new Error("AddToCart mapping needs cartLine");  }  const variant = line.merchandise;  const amount = line.cost.totalAmount.amount;  const currency = line.cost.totalAmount.currencyCode;  const quantity = Number(line.quantity);  if (amount == null || !Number.isFinite(Number(amount)) || !currency ||      !Number.isFinite(quantity) || quantity <= 0) {    throw new Error("AddToCart needs an amount, currency and quantity");  }  window.dataLayer.push({ ecommerce: null });  window.dataLayer.push({    event: "custom_add_to_cart",    event_id: event.id,

14 more lines of JavaScript

  • Copy and download
  • Emailed to you

Unlock this snippet

Two details, and the full code is yours

No account needed. Unlock once and every snippet on the blog opens.

We email you a copy.

Done when the saved subscription listens to product_added_to_cart, pushes custom_add_to_cart, and includes the selected item when its ID is available, rather than a page-load snapshot. A normal addition logs custom_add_to_cart with its line value, and a null cartLine logs that message and pushes nothing. Both test runs push custom_add_to_cart and call ttq.track with the original value and currency; only the identified item appears in contents.

When no items have IDs, the tag below omits contents.

How do I send AddToCart from GTM to TikTok?

AddToCart is the standard event code in TikTok's supported events listads.tiktok.com.

Use custom_add_to_cart as the GTM trigger and AddToCart as the name sent to TikTok. A trigger tells GTM when to run a tag; the data layerdevelopers.google.com holds the event and values that tag reads.

4. Create the variables and trigger

A Data Layer Variablesupport.google.com reads a named value for a tag. TikTok documents contents as an array of product objectsads.tiktok.com; its Pixel template sourceraw.githubusercontent.com uses content_id, content_type, content_name, price and quantity inside each object.

  1. Create each Data Layer Variable in the table below, using Version 2 for nested paths.
  2. Create a Custom Event trigger whose event name is exactly custom_add_to_cart.
  3. Leave regular-expression matching off on that trigger.
  4. Create a Custom JavaScript variable named JS - TikTok contents with the mapping below.

DLV - Value

Data layer path
ecommerce.value
Expected value
Number, including zero

DLV - Currency

Data layer path
ecommerce.currency
Expected value
Currency code

DLV - Items

Data layer path
ecommerce.items
Expected value
Array of items

DLV - Event ID

Data layer path
event_id
Expected value
Shopify customer-event ID
Create these variables in the same container as the event tag.
javascript15 lines
function() {  var items = {{DLV - Items}};  if (!Array.isArray(items)) {    throw new Error('TikTok mapping needs an ecommerce.items array');  }  return items.map(function(item) {    return {      content_id: String(item.item_id),      content_type: 'product',      content_name: item.item_name,      price: Number(item.price),

4 more lines of JavaScript

  • Copy and download
  • Emailed to you

Unlock this snippet

One form opens every snippet on the blog

This example uses Shopify variant IDs and content_type: "product". For catalog use, compare an ID with your actual feed and adapt the mapping if needed: TikTok recommends matching the catalog SKU or item-group ID and pairing it with product or product_groupads.tiktok.com. Choose the matching ID and type together.

Done when each variable path and the trigger name match the table and the snippet, JS - TikTok contents returns the expected items, and the ID convention is documented.

5. Add the TikTok event tag

The code below uses the ttq.track(event, properties, options) call and pixel_code option in TikTok's official Pixel templateraw.githubusercontent.com; it keeps this guide's event name and value explicit.

  1. Create a Custom HTML tag with the code below.
  2. Attach only the custom_add_to_cart trigger.
  3. Use GTM tag sequencingsupport.google.com to run TikTok base before this event tag.
  4. Set the base tag to Once per pagesupport.google.com.
  5. Keep consent requirements on both tags.
html14 lines
<script>var contents = {{JS - TikTok contents}};var properties = {  value: {{DLV - Value}},  currency: {{DLV - Currency}}};if (contents.length) {  properties.contents = contents;}ttq.track('AddToCart', properties, {

4 more lines of HTML

  • Copy and download
  • Emailed to you

Unlock this snippet

One form opens every snippet on the blog

Done when the saved event tag has the intended trigger, variables and base setup tag.

How do I test Shopify AddToCart tracking?

Test the Shopify event first, then confirm the browser event in TikTok Events Manager > Test eventsads.tiktok.com. Shopify's helper checks the subscription; TikTok receipt is a separate check.

6. Publish the version in the test container

Changes saved in a workspace do not run yet. Google sayssupport.google.com you need to publish workspace changes to make them operational.

  1. Open the test container that only your development store loads.
  2. Select Submit, then choose Publish and Create Version.
  3. Name the version and publish.

Do not publish to a container your live store loads; move the tested setup there through your normal release process.

Done when the test container's Versions list shows your version as published and the pixel code loads that container's ID.

7. Connect the test pixel and exercise the event

  1. Save and connect the custom pixel on the development store.
  2. Select Test, following Shopify's Pixel Helper procedurehelp.shopify.com.
  3. Exercise the consent choices and check that the helper's consent state matches your choice.
  4. Choose a different variant.
  5. Set quantity above one.
  6. Add it to the cart.
  7. Also try adding an unavailable item.
  8. Record which actions Shopify reports as successful additions.
  9. In Shopify Pixel Helper, check that product_added_to_cart appears with a green dot and the expected payload.
  10. Open the intended TikTok pixel's Test events flow.
  11. Repeat the action.
  12. Keep the results with the test container version and pixel ID for production review.

Done when the pixel is Connected, the helper's consent state matches your choice, product_added_to_cart appears in Shopify Pixel Helper with a green dot and the expected payload, and AddToCart arrives in TikTok as a browser event whose currency and value agree with the Shopify payload, with no unexplained duplicate.

Shopify says Tag Assistant's Troubleshoot tag feature is incompatible with custom pixelshelp.shopify.com. Use Shopify Pixel Helper and destination checks for this sandboxed setup.

Which mistakes should I check first?

Start with the event source, then check the values and the tag that sent them.

  • Counting a click as a cart addition: the old listener ran before any success check. Use the Shopify addition event and compare the cart contents.
  • Keeping page-load product details: a later variant or quantity choice can differ. Compare the event payload with the item actually added.
  • Running two senders for the same action: your test can contain overlapping events. Identify the app or tag responsible for each event.

Continue with the next Shopify funnel-event guide after this event passes its checks. Keep the same pixel ID and document which setup sends each action.

What changed in this guide

  • 25 October 2026: Replaced the button-click listener with Shopify Customer events. Added selected-item mapping, explicit TikTok parameters and development-store checks. Added null-ID checks that preserve event values and explicit test-container publication checks. The video was not re-recorded.

Sources

14 sources
  1. 1Shopify exposes product_added_to_cart for an item added to the cart↩
  2. 2Shopify's GTM tutorial↩
  3. 3Customer privacy settings↩
  4. 4TikTok documents↩
  5. 5TikTok's supported events list↩
  6. 6data layer↩
  7. 7Data Layer Variable↩
  8. 8TikTok documents contents as an array of product objects↩
  9. 9Pixel template source↩
  10. 10GTM tag sequencing↩
  11. 11Once per page↩
  12. 12TikTok Events Manager > Test events↩
  13. 13Google says↩
  14. 14Shopify's Pixel Helper procedure↩