Shopify TikTok View Cart tracking with GTM
Track Shopify cart-page views as a TikTok custom event with GTM. Send cart items, discounted value and the matching currency.
Shahzada Ali Hassan, founder of Crisperchecked against 15 sources
The short answer
Track a Shopify cart-page view with a custom TikTok ViewCart event and a GTM trigger. TikTok custom events support reporting and audience creation, not direct campaign optimizationads.tiktok.com. This guide is for store implementers measuring cart-page visits separately from cart additions and sending the cart's current items and value.
- GTM trigger:
custom_view_cart. ViewCartis a custom event, notAddToCart.- This snippet measures cart-page loads, not cart-drawer openings.
- Steps and settings checked against Shopify and TikTok documentation on 25 October 2026.
FREE CALL
30 MINMeta stopped counting your leads? Get them counted again.
- Pick a time
Check your Meta account with Hassan- 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.
Not ready to talk? Run a free check
The video shows the older configuration; follow the current written steps below for the corrected event mapping and data fields.
01How do I add GTM to the Shopify storefront?
Add the container to the development store's theme.liquid. Google's web-container instructionssupport.google.com place the script near the start of <head> and the noscript block immediately after <body>.
Use a development store and a GTM container reserved for testing. Check existing theme scripts and app pixels before adding another installation. This guide is for a Liquid storefront; use a separate implementation for a headless storefront.
1. Install or verify the test container
- Replace
GTM-XXXXin both snippets below with the test container ID. - In the development store's
theme.liquid, paste the script near the start of<head>. - Paste the noscript block immediately after
<body>. - If that container is already installed, verify its location instead of inserting it again.
<!-- Google Tag Manager -->
<script>(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');</script>
<!-- End Google Tag Manager -->
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
Done when the development theme contains the intended loader once.
02How 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
- In GTM, create a Custom HTML tag named TikTok base.
- Paste that pixel's base code.
- Set its trigger to All Pages.
- Retain the store's consent controls on the tag.
- 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.
03How do I put the Shopify cart in the data layer?
Read cart.items and cart.total_priceshopify.dev when the cart page renders. The total is after discounts; use it instead of summing undiscounted item prices.
3. Add the cart data-layer snippets
- Create
snippets/head-datalayer.liquidwith the first block below. - If
head-datalayer.liquidalready exists, merge this page condition with its existing conditions instead. - Create
snippets/datalayer-cart.liquidwith the second block. - Add the render line (third block) inside
theme.liquidafter the GTM head loader. - Keep one initialization and one render call in the theme.
<script>
window.dataLayer = window.dataLayer || [];
</script>
{%- if template.name == 'cart' -%}
{%- render 'datalayer-cart' -%}
{%- endif -%}
<script> window.dataLayer = window.dataLayer || []; var product_details = [ {%- for item in cart.items -%} { item_id: {{ item.variant_id | append: "" | json }}, id: {{ item.variant_id | append: "" | json }}, item_name: {{ item.product.title | json }}, item_brand: {{ item.vendor | json }}, item_category: {{ item.product.type | json }}, quantity: {{ item.quantity | json }}, currency: {{ cart.currency.iso_code | json }}, google_business_vertical: 'retail', price: {{ item.final_price | divided_by: 100.0 | json }} }{%- unless forloop.last -%},{%- endunless -%} {%- endfor -%} ]; dataLayer.push({ ecommerce: null });
10 more lines of Liquid
- 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.
{% render 'head-datalayer' %}
The item mapping uses Shopify's line_item fieldsshopify.dev, including variant_id, quantity and final_price.
Done when a cart-page load pushes custom_view_cart, its items and discounted total agree with the cart, and any earlier conditions in head-datalayer.liquid remain alongside this page's own condition.
04How do I send ViewCart to TikTok?
ViewCart is not in TikTok's standard event listads.tiktok.com; keep it as a custom eventads.tiktok.com instead of calling a cart view AddToCart.
Use custom_view_cart as the GTM trigger and ViewCart 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.
- Create each Data Layer Variable in the table below, using Version 2 for nested paths.
- Create a Custom Event trigger whose event name is exactly
custom_view_cart. - Leave regular-expression matching off on that trigger.
- 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
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.
- Create a Custom HTML tag with the code below.
- Attach only the
custom_view_carttrigger. - Use GTM tag sequencingsupport.google.com to run TikTok base before this event tag.
- Set the base tag to Once per pagesupport.google.com.
- Keep consent requirements on both tags.
<script>
ttq.track('ViewCart', {
contents: {{JS - TikTok contents}},
value: {{DLV - Value}},
currency: {{DLV - Currency}}
}, {
pixel_code: {{Constant - TikTok pixel ID}}
});
</script>
Done when the saved event tag has the intended trigger, variables and base setup tag.
05How do I test the Shopify ViewCart event?
Use GTM Previewsupport.google.com to inspect the data-layer event and tag, then check receipt in TikTok Test eventsads.tiktok.com. Save both observations; a successful tag firing is only one part of the check.
6. Test the event and its boundaries
- Open a cart containing several items.
- Test a discounted cart.
- Test an empty cart.
- Follow the intended TikTok pixel's Test events flow.
- Repeat the action.
- Repeat with each consent choice and compare the result with your consent plan.
- Switch the development storefront to a second supported presentment currency.
- Reload the cart in GTM Preview.
- Repeat the TikTok Test events check.
The snippet uses cart.currencyshopify.dev, the presentment currency on multi-currency stores, and its iso_codeshopify.dev for the label.
Done when custom_view_cart has the correct items, currency and total, including numeric zero for the empty cart; the browser event is ViewCart, its parameters match the data layer and no unexplained duplicate appears; and in the second currency, item prices, the value derived from cart.total_price, and the currency code agree with the displayed cart and the received ViewCart.
06When is this setup the wrong fix?
Use another event source if the job is to track a cart drawer. This Liquid snippet runs when the cart page renders; it has no drawer-open listener.
- Calling ViewCart AddToCart: opening a cart is a different action. Keep the custom event name.
- Summing undiscounted item prices: that can disagree with the cart. Compare the event value with cart.total_price.
- Testing only a populated cart: an empty cart must still preserve its zero value. Include that case before review.
Continue with the next Shopify event guide once the event name and payload match your test action. Save the tested container, pixel ID and observations for production review.
07What changed in this guide
- 25 October 2026: Corrected ViewCart to a custom event. Updated discounted cart values and currency, and added explicit TikTok mapping and cart-page tests. Added a second-presentment-currency completion check. The video was not re-recorded.
Sources
15 sources
- 1TikTok custom events support reporting and audience creation, not direct campaign optimizationads.tiktok.com↩
- 2Google's web-container instructionssupport.google.com↩
- 3TikTok documentsads.tiktok.com↩
- 4cart.items and cart.total_priceshopify.dev↩
- 5Shopify's line_item fieldsshopify.dev↩
- 6TikTok's standard event listads.tiktok.com↩
- 7data layerdevelopers.google.com↩
- 8Data Layer Variablesupport.google.com↩
- 9TikTok documents contents as an array of product objectsads.tiktok.com↩
- 10Pixel template sourceraw.githubusercontent.com↩
- 11GTM tag sequencingsupport.google.com↩
- 12Once per pagesupport.google.com↩
- 13GTM Previewsupport.google.com↩
- 14TikTok Test eventsads.tiktok.com↩
- 15iso_codeshopify.dev↩


