Tracking orders from your Shopify store can be a bit tricky, but it’s essential for understanding your customers’ behaviour. By sending data from Shopify Checkout to Google Tag Manager (GTM), you can keep tabs on your orders more effectively. Here’s a simple guide to help you set this up.
How to set up custom pixel
The Shopify checkout is sandboxed, for security. Meaning we cannot add our own code in directly. Instead if we want to add tracking we must use Shopify Pixels. We can create a custom pixel within here and make it trigger when the checkout is completed.
- To do this navigate to Customer Events in your Shopify settings menu.
- And then create a new pixel.
- You’ll now to configure some pixel code with your Google Tag Manager ID and you may also wish to configure what data is collected and passed to Google Tag Manager. We’ve provided some sample code below.
To explain in this custom pixel code, we are subscribing (telling Shopify we want to be notified) to specific customer events (actions on the store, like viewing a product or paying for an order happen). Because we want to track completed orders we are subscribing to the ‘checkout_completed’ event. Then we are using ‘window.dataLayer.push’ to send event data to the dataLayer where Google Tag Manager can access it.
Example pixel code
// Ensure the dataLayer is available
window.dataLayer = window.dataLayer || [];
// (Optional) Consent Mode v2 if not using Shopify's built-in Consent Management
window.dataLayer.push({
event: 'consent_update',
ad_storage: 'granted',
analytics_storage: 'granted',
ad_user_data: 'granted',
ad_personalization: 'granted',
});
// Subscribe to checkout completed event
analytics.subscribe("checkout_completed", (event) => {
window.dataLayer.push({
event: "checkout_completed",
timestamp: event.timestamp,
transaction_id: event.data?.checkout?.order?.id,
currency: event.data?.checkout?.currencyCode,
value: event.data?.checkout?.totalPrice?.amount,
shipping: event.data?.checkout?.shippingLine?.price?.amount,
tax: event.data?.checkout?.totalTax?.amount,
subtotal: event.data?.checkout?.subtotalPrice?.amount,
});
});
Important: You do not need to reload or install GTM scripts inside the pixel. GTM should already be installed globally on your store. Also, avoid sending personally identifiable information (PII) like email, phone, or address unless properly anonymised.
How to set up Google Tag Manager to receive the data
With your pixel ready to send data, you need to set up GTM to receive it:
To start, open your Google Tag Manager account. Create a new Trigger by selecting “Custom Event” as the type, setting the Event Name to checkout_completed
, and choosing to trigger on all custom events.
Once your trigger is ready, create a new Tag. You can choose a GA4 Event Tag if you are sending data to Google Analytics, a Google Ads Conversion Tag for advertising tracking, or a Custom HTML Tag if needed for other integrations.
Then configure the tag to fire when the checkout_completed
event occurs. In the tag settings, make sure to map the key parameters you want to track, including transaction_id
, value
, currency
, shipping
, tax
, and subtotal
, so that your reports capture all the essential purchase details.
Final step is to set up Variables:
- Go to Variables > Configure.
- Enable built-in variables.
- Add user-defined variables to capture
transaction_id
,value
,currency
, etc., from thedataLayer
.
Once everything is set up, your GTM workspace will capture checkout completions and send them into GA4, Google Ads, or any other destination you choose.
Conclusion
By following these steps, you’ll be able to track order data from Shopify Checkout using Google Tag Manager. This will give you valuable insights into your customers’ buying habits, helping you make better business decisions.
Remember, while this process might seem a bit technical, taking it step by step will make it manageable. And the payoff in terms of improved tracking and understanding of your orders is well worth the effort.