Shopify9 min read1 view

Shopify Facebook Pixel Purchase tracking with GTM

Track Shopify purchases with GTM and Customer events. Replace legacy checkout scripts, map Meta Purchase values and test for duplicate events.

Watch on YouTube

Jump to the code

The short answer

Track Shopify purchases through GTM by subscribing to customer events inside a custom pixel, then sending Meta a Purchase event. Shopify documents checkout_completed as firing once per checkout, sometimes before the Thank you page. This guide helps store owners and implementers replace legacy checkout scripts and check the resulting purchase data.

  • If Facebook and Instagram by Meta already sends purchases, investigate it before adding another sender.
  • Keep the GTM trigger custom_purchase separate from Meta's event name Purchase.
  • Use Customer events, not Additional Scripts, for this checkout setup.
  • Steps and settings checked against Shopify documentation and Meta's template 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

Can I still use Additional Scripts for Shopify purchases?

Use Customer events for the replacement setup. Shopify has retired the legacy checkout route: its checkout.liquid documentationshopify.dev marks checkout.liquid and Additional Scripts as sunset on Thank you and Order status pages. Pasting the old Liquid snippet into a custom pixel is not a migration.

The video above shows the older Additional Scripts checkout method; follow the current written steps below for Customer events. Keep a copy of your old configuration so you can compare event names and amounts.

Should I use GTM or the Shopify Meta integration?

Use this GTM path when you need to maintain a custom purchase mapping. If the store already uses Facebook and Instagram by Metahelp.shopify.com, first check its connected pixel and data-sharing settings. Shopify warns that overlapping pixel installations can produce duplicate or incorrect reporting.

  • Have access to Shopify Customer events, the intended GTM web container and the store's Meta pixel in Events Manager.
  • Write down which app, theme script or custom pixel currently sends Purchase. Plan which sender the replacement will retire.
  • Use a development store and a GTM container reserved for testing these steps. Record a test order's ID, currency, subtotal, tax and shipping for comparison.

This is a browser purchase setup, not a Conversions API implementation. A second browser tag is the wrong fix when the existing integration already records the order correctly. Shopify describes custom pixels as an advanced, unsupported featurehelp.shopify.com; choose an app integration if you need a maintained installation rather than custom code.

How do I load GTM through Shopify Customer events?

Create a custom pixel and place the GTM loader inside it. Shopify's GTM custom pixel tutorialhelp.shopify.com instructs you to copy the head installation snippet and remove its HTML script tags.

1. Create the pixel and check its permissions

  1. In Settings > Customer events, give the custom pixel a clear name.
  2. Select Add pixel.
  3. Review Customer privacy using Shopify's permission and data-sale settingshelp.shopify.com.
  4. Choose settings that match the store's consent requirements.

Do not copy a blanket "Not required" setting from an older tutorial.

Done when the pixel editor is open and its Customer privacy settings match your consent plan.

2. Add the loader and purchase subscription

  1. Paste your GTM loader as JavaScript.
  2. Use the ID of a test container that only your development store loads.
  3. Append the subscription in the next section.
  4. Save the pixel.
  5. Connect it when you are ready to test.

Done when Customer events shows Connected, the status required by Shopify's testing instructionshelp.shopify.com.

Which Meta tag should I use in GTM?

Use the Meta Pixel template published from Meta's official GTM template repositorygithub.com. Check the publisher before installing a similarly named community template. Reuse the intended pixel ID rather than creating a new pixel for this migration.

The purchase tag below uses explicit properties. Leave automatic ecommerce mapping off for this example, and keep any existing PageView configuration separate. Do not give the Purchase tag an All Pages trigger.

How do I replace the Liquid purchase data layer?

Subscribe to checkout_completed and read its checkout payload. The Shopify event referenceshopify.dev provides the order, currency, amounts and line items; it replaces the old Shopify.checkout and first_time_accessed dependencies.

  1. Append this code after the GTM loader in your custom pixel.

It keeps the original custom_purchase trigger contract and subtotal-based value. It does not collect names, email addresses or street addresses; advanced matching needs a separate, deliberate implementation.

javascript47 lines
// Paste inside the same Shopify custom pixel as your GTM loader.// Add this subscription once. Do not paste it into theme.liquid.window.dataLayer = window.dataLayer || []; analytics.subscribe("checkout_completed", (event) => {  const checkout = event.data.checkout;  const amount = checkout.subtotalPrice?.amount;  const currency = checkout.currencyCode;  const orderId = checkout.order?.id;   if (amount == null || !Number.isFinite(Number(amount)) || !currency || !orderId) {    throw new Error("Purchase mapping needs an order ID, subtotal and currency");  }   // Shopify allows a line item variant to be null; skip those lines.  const items = checkout.lineItems    .filter((item) => item.variant?.id)    .map((item) => ({

29 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 uses subtotalPrice.amount, which Shopify defines as the price before duties, shipping and taxes. Keep that meaning when comparing old and new reports. The transaction ID now comes from Shopify's order ID, not the legacy order number; check any downstream joins that depended on its old format. The checkout_completed referenceshopify.dev allows a line item's variant to be null, so the code leaves those lines out of items instead of sending an item without an ID; the purchase and its value are still pushed. Catalog matching is outside this example, so the Purchase tag below sends only value, currency and order ID.

Done when a logged custom_purchase carries the order's value and every entry in items has an item_variant_id.

How do I map the data layer to Meta Purchase?

Create a Custom Event trigger for custom_purchase, then map the purchase properties into the Meta tag. Here custom_purchase is the event name your GTM trigger listens for; Purchase is the event name sent to Meta. A trigger tells GTM when to run a tag. Google's data-layer guidedevelopers.google.com shows a push that carries the event name and its values together.

3. Create variables and the trigger

A Data Layer Variablesupport.google.com reads a named value from the data layer for a tag to use.

  1. Create one for each path in the table below, using Version 2 for the nested paths.
  2. Create the Custom Event trigger with event name custom_purchase.
  3. Leave regular-expression matching off.

DLV - Purchase value

Data layer variable name
ecommerce.value
Use
Meta object property value

DLV - Purchase currency

Data layer variable name
ecommerce.currency
Use
Meta object property currency

DLV - Order ID

Data layer variable name
ecommerce.transaction_id
Use
Meta object property order_id

DLV - Event ID

Data layer variable name
event_id
Use
Meta Event ID field
These names describe this snippet; use the same paths in your GTM variables.

Done when the saved variables show the paths in the table and the saved trigger uses exactly custom_purchase.

4. Configure the purchase tag

  1. In the Meta Pixel template, enter your pixel ID.
  2. Select standard event Purchase.
  3. Under Object Properties, add value, currency and order_id using the variables above.
  4. Set Event ID to DLV - Event ID.
  5. Attach the custom_purchase trigger.
  6. 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.
  7. Save the tag.

Done when reopening the tag shows Purchase, the intended pixel ID, all three properties, the Event ID variable, the purchase trigger and the opt-in box cleared.

The template's Event ID fieldraw.githubusercontent.com supports browser/server deduplication. This snippet sends browser events only. If you also use a server sender, check that it sends the same event ID for the same purchase before combining the two.

How do I test the Shopify Purchase event?

Use Customer events > Test to check a test order in Shopify Pixel Helper, then compare the Purchase event in Meta Events Manager. In Shopify Pixel Helperhelp.shopify.com, a green dot means the pixel received the event and ran its code without an error; it does not prove Meta received the correct amount.

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. Follow a test order through the setup

  1. In Customer events, open the connected pixel and choose Test.
  2. Exercise the store's consent flow, following Shopify's Pixel Helper procedurehelp.shopify.com, and check that Pixel Helper's consent status matches your choice.
  3. Complete a test checkout.
  4. Expand checkout_completed in Pixel Helper and check that it has a green dot and its order fields match your recorded test order.
  5. Check Purchase in Meta Events Manager for the intended pixel: match the event to your test order, compare its currency and value, and look for any unexplained second Purchase for that order.
  6. Save the test order ID, time, observed event values and any failures in your test notes.

Done when every check above matches and your notes identify the tested pixel and container and show the Shopify and Meta checks separately.

Shopify says Tag Assistant's Troubleshoot tag feature is incompatible with custom pixelshelp.shopify.com. Do not treat its failure to find a sandboxed tag as proof the pixel is absent. Use Shopify Pixel Helper and destination checks together.

Which mistakes make this setup unreliable?

The most costly mistakes confuse installation, consent and event receipt. Fix the failing stage before adding another tag.

  • Using the old checkout script: the replacement pages do not use that installation route. Move the purchase subscription into Customer events.
  • Running the app and custom Purchase together without a deduplication plan: reports can include overlapping data. Choose the sender or verify the shared event ID.
  • Testing only the successful consent path: a missing event may reflect the selected privacy settings. Test both choices and document the expected behavior.

What else should I check about Shopify purchase events?

Why is there no new event on the Thank you page after an upsell?

Shopify can emit checkout_completed on the first upsell offer page instead. Its event referenceshopify.dev says the event will not repeat on the Thank you page, so inspect the earlier event before changing the trigger.

Will this capture an order if the completion page never loads?

No. Shopify documentsshopify.dev that the event is not triggered if its relevant page fails to load. Compare store orders with received purchases separately to find missing orders.

What should I check after Purchase is verified?

Check the earlier funnel events next. The customer-pixel Add to Cart guide and customer-pixel checkout guide cover those event mappings. Apply the current privacy settings and testing method above when using older companion tutorials.

What changed in this guide

  • 25 October 2026: Replaced Additional Scripts and Liquid checkout instructions with Customer events, added Meta template mapping and completion checks, and corrected testing and purchase-event limitations, including the test-container publish step and the Conversions API opt-in setting. The video was not re-recorded and shows the older method.

Sources

12 sources
  1. 1checkout.liquid documentation↩
  2. 2Facebook and Instagram by Meta↩
  3. 3Shopify describes custom pixels as an advanced, unsupported feature↩
  4. 4GTM custom pixel tutorial↩
  5. 5Shopify's testing instructions↩
  6. 6Shopify pixels run in a sandbox↩
  7. 7Meta's official GTM template repository↩
  8. 8Shopify event reference↩
  9. 9Google's data-layer guide↩
  10. 10Data Layer Variable↩
  11. 11template's Opt in to a Meta-enabled Conversions API integration box↩
  12. 12Google says↩