I am trying to fire a GTM event after purchase gets completed. I have pasted the code below in custom pixel in customer events. I need SKU of the products purchased. How can I get?
analytics.subscribe(“checkout_completed”, (event) => { dataLayer.push({ ‘event’: ‘purchase’, ‘userID’: , ‘sku’: }); });
Hi you can fetch the SKU from the line_items:
It would look something like this :
const lineItems = checkout.lineItems const ItemSkus = lineItems.map((item, index) => { return { item_sku: item.variant.id //Good } });
And then you could use the ItemSkus which would return an array of SKU objects
It is working, thanks a lot