I’m working with a platform that needs additional product identifiers included for its pixel. Specifically, they need a GTIN (variant barcode) and an MPN (variant metafield).
The event.data available with the checkout_completed event contains a very limited set of product data.
Is there any way to access additional product data within a custom web pixel? Specifically, product tags, variant barcodes, and variant metafields.
Here’s a snippet that demonstrates what I’m trying to accomplish.
analytics.subscribe('checkout_completed', (event) => {
// 1. Check product tags to filter line items.
const lineItems = event.data.checkout.lineItems.filter((item) => {
const product = item.variant.product;
return product.tags.indexOf('tagName') > -1; // Tags not actually available
});
// 2. Gather important identifiers from line items.
payload = lineItems.map((item) => {
const variant = item.variant;
return {
sku: variant.sku,
gtin: variant.barcode, // Barcode not actually available
mpn: variant.metafields.custom.mpn // Metafields not actually available
}
});
fetch('https://example.com/pixel', {
method: 'POST',
body: JSON.stringify(payload),
keepalive: true,
});
});
I’m usually a big advocate for “Liquid over JS”-solutions due to performance, however, specifically regarding this case of tracking, this makes way better sense than cluttering the line item properties and HTML with extra data.