Shopify6 min read1 view

Shopify Facebook Pixel Add to Cart with GTM

Track Shopify Add to Cart with Customer events and GTM. Replace the click listener, map line values and verify Meta AddToCart.

Watch on YouTube

Jump to the code

The short answer

Track Shopify Add to Cart through Customer events, then map the resulting data-layer event to Meta AddToCart in GTM. Shopify's product_added_to_cart payloadshopify.dev supplies the cart line, quantity and amount. This guide is for store owners and implementers replacing a button-click listener with data about the product actually added.

  • Shopify event: product_added_to_cart; GTM trigger: custom_add_to_cart.
  • Meta event: AddToCart; value comes from the cart line.
  • If the Meta app already sends AddToCart, check it before adding this sender.
  • Steps and settings checked against linked documentation and tutorial files 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

How do I track Shopify Add to Cart with GTM?

Subscribe to the cart event instead of treating a click as a successful addition. The original listener captured the initial product variant and hard-coded quantity 1; the replacement reads the event payload.

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

Should I use a custom pixel for AddToCart?

Use this custom path when you need to maintain your own AddToCart mapping. Inspect the connected pixel in Facebook and Instagram by Metahelp.shopify.com first; Shopify warns about duplicate reporting from overlapping installations. Use a development store and test container for this guide.

How do I load GTM in Shopify Customer events?

Load the test container inside the custom pixel that receives the cart event.

1. Create a custom pixel in the development store

  1. Open Settings > Customer events.
  2. Name the pixel and choose Add pixel.
  3. Review Customer privacy against the store's consent plan using Shopify's permission and data-sale settingshelp.shopify.com.

Done when the editor is open and its privacy settings match the intended test behavior.

2. Load the test GTM container

  1. Copy the GTM head snippet, following Shopify's GTM custom pixel examplehelp.shopify.com.
  2. Remove its HTML script tags.
  3. Use the ID of a test container that only your development store loads.
  4. Keep the loader and the subscription below in the same custom pixel.

Done when the editor contains JavaScript for the intended container and no surrounding HTML script tags.

Do I need a separate PageView tag?

Keep the storefront PageView sender separate from this custom-pixel event. The Shopify PageView guide covers theme-based page tracking; it does not replace the GTM loader inside this custom pixel. Give AddToCart only its event trigger below.

How do I capture the added product and quantity?

Read event.data.cartLine inside the subscription. Shopify's event referenceshopify.dev defines its merchandise, quantity and line total; this implementation uses those values instead of reading the product page when it first loads.

3. Append the cart subscription

The callback, the function run when the event arrives, pushes the event and its data together.

  1. Place this JavaScript after the GTM loader in the same custom pixel.
javascript36 lines
// Append once after the GTM loader in the same custom pixel.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 amount = line.cost.totalAmount.amount;  const currency = line.cost.totalAmount.currencyCode;  if (amount == null || !Number.isFinite(Number(amount)) || !currency) {    throw new Error("AddToCart mapping needs line value and currency");  }  // Shopify allows merchandise.id to be null; send no item rather than one without an ID.  const variant = line.merchandise;  window.dataLayer.push({ ecommerce: null });  window.dataLayer.push({    event: "custom_add_to_cart",    event_id: event.id,

18 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.

Here value means the cart line's totalAmount.amount, not the whole cart value. Shopify defines this field as the merchandise line totalshopify.dev. The item ID now uses the event's variant ID; compare its format with any existing catalog feed before reusing an older ID mapping. Shopify's event referenceshopify.dev allows the merchandise ID to be null; the code then sends an empty items list and keeps the event, value and currency.

Done when the saved editor includes one product_added_to_cart subscription and the custom_add_to_cart event name from the snippet, and a logged custom_add_to_cart has the line value and currency and every entry in items has an item_id.

How do I map and test Meta AddToCart?

Map custom_add_to_cart to Standard > AddToCart in the Meta Pixel templateraw.githubusercontent.com. Keep the trigger name separate from the Meta name. A trigger tells GTM when to run a tag.

4. Create the variables and event tag

Each Data Layer Variablesupport.google.com reads one named value from the event.

  1. Create a Version 2 Data Layer Variable for each path in the table below.
  2. Create the Meta tag with Standard > AddToCart and enter your pixel ID.
  3. Under Object Properties, map value and currency.
  4. Map event_id to Event ID.
  5. Leave automatic ecommerce mapping off.
  6. Attach a Custom Event trigger matching custom_add_to_cart exactly.
  7. Clear the template's Opt in to a Meta-enabled Conversions API integration boxraw.githubusercontent.com. It is ticked by default, and while it is ticked the tag opts the pixel in to that integration. This guide sets up the browser tag only, so clear it on this tag and on any other Meta Pixel tag that uses the same pixel.
  8. Save the tag.

value

Data layer path
ecommerce.value

currency

Data layer path
ecommerce.currency

Event ID field

Data layer path
event_id
These paths match the subscription in this guide.

Done when reopening the tag shows AddToCart, the intended pixel ID, both properties, the Event ID variable, the custom_add_to_cart trigger and the opt-in box cleared.

The snippet also preserves item details for your other mappings. It does not define a catalog ID convention; compare any existing catalog mapping before adding contents or content_ids to this tag.

Use Shopify Pixel Helperhelp.shopify.com to inspect the source event, then check AddToCart in Meta Events Manager. A green helper status means the subscribed code ran without an error; keep the destination field check separate.

5. 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.

6. Connect the pixel and run its test

  1. Save the pixel.
  2. Select Connect in the development store.
  3. Choose Test, following Shopify's test procedurehelp.shopify.com.
  4. Exercise the consent flow.
  5. Add a chosen variant and quantity to the cart.

Done when Pixel Helper shows product_added_to_cart with the fields you expected and no execution error.

7. Compare the event received by Meta

  1. Open the intended pixel's Test Events in Events Manager.
  2. Find AddToCart from the same test action.
  3. Compare the line amount and currency.
  4. Repeat with a different quantity.
  5. Record the time, source fields and destination fields.

Done when the received event matches the action and there is no unexplained second sender.

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

Why is my Shopify AddToCart data wrong?

Start with the source event and the cart contents. Check the cart-line fields before changing the Meta tag.

  • Counting clicks: a click can precede a failed addition. Use the cart event rather than the old click listener.
  • Using initial product data: variant and quantity choices can differ from the page-load values. Read the cart-line payload.
  • Leaving both senders active: the action may be sent twice. Plan which old listener the replacement retires.

What should I track after AddToCart?

Continue with Shopify InitiateCheckout, checking the transition from added products to checkout.

What changed in this guide

  • 25 October 2026: Replaced the button-click listener and fixed quantity with product_added_to_cart payload mapping. Preserved custom_add_to_cart while adding line value, event ID, consent and destination checks. Added isolated test-container publication before testing and explicit Meta-enabled Conversions API opt-out checks.

Sources

8 sources
  1. 1Shopify's product_added_to_cart payload↩
  2. 2Facebook and Instagram by Meta↩
  3. 3Shopify recommends reviewing available pixel apps before custom code↩
  4. 4Shopify's permission and data-sale settings↩
  5. 5Meta Pixel template↩
  6. 6Data Layer Variable↩
  7. 7Shopify Pixel Helper↩
  8. 8Google says↩