79284575

Date: 2024-12-16 11:56:35
Score: 1
Natty:
Report link

See if this can be helpful:

dataLayer.push({
  event: 'view_item',
  ecommerce: {
    currency: 'USD',
    items: [{
      item_id: 'SKU123',  // What we're extracting
      item_name: 'Cool Product',
      price: 29.99
      // ... other product data
    }]
  }
});

Once you create this variable then you should create a new Custom Javascript variable and use this code (in this example we want to fetch the item_id of the first product)

function() {
  var ecomm = {{ecommerce}};
  if (!ecomm || !ecomm.items || !ecomm.items.length) {
    return undefined;
  }
  return ecomm.items[0].item_id || '';
}

In this way if you use GTM preview and select the DL Push which is supposed to have your eventModel and look into variables you should get the variable and not undefined

Let me know if this works, otherwise let's debug this, maybe you could share your eventModel DataLayer Push?

fetch_item_id

this is better explained in this article: https://blog.assertionhub.com/articles/extract-first-product-id-from-ga4-ecommerce-data-layer

Reasons:
  • Blacklisted phrase (1): this article
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Ivan Maddaluno