I couldn’t get GTM to track a purchase in GA4 on Shopify and I have worked out why but unsure how to resolve it…
I have the following code in a custom pixel to track purchases and push to GTM…
analytics.subscribe("checkout_completed", (event) => {
dataLayer.push({ ecommerce: null });
const items = event.data?.checkout?.lineItems?.map((item) => {
return {
item_id: item.variant.product.id,
item_name: item.variant.product.title,
price: item.variant.price.amount,
quantity: item.quantity
}
});
dataLayer.push({
event: "purchase",
url: event.context.document.location.href,
ecommerce: {
currency: event.data?.checkout?.currencyCode,
value: event.data?.checkout?.subtotalPrice?.amount,
transaction_id: event.data?.checkout?.order?.id,
coupon: event.data?.checkout?.discountAllocations,
shipping: event.data?.checkout?.shippingLine?.price?.amount,
tax: event.data?.checkout?.totalTax?.amount,
items: items
}
});
});
However when we view this purchase in the GTM we can see that it is adding a send_to parameter which forces it to send to the Merchant Center and ignore all other triggers set out in GTM. How do we avoid this so we can correctly track purchases in GA4 and Google Ads?