Home > Software engineering >  Can ecommerce item for GA4 add_to_cart event have custom parameters?
Can ecommerce item for GA4 add_to_cart event have custom parameters?

Time:07-26

I am trying to implement GA4 add_to_cart event for e-shop, but product already has same parameters for other services, but they are using different names, can you somehow rename item parameter for GA4?

Or is there some better way for not having duplicate values?

GA4 ecommerce item structure:

items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      currency: "USD",
      item_brand: "Google",
      item_category: "Apparel",
      price: 9.99,
      quantity: 1
    }
  ]

My Structure:

items: [
    {
      id: "SKU_12345",
      name: "Stan and Friends Tee",
      brand: "Google",
      category: "Apparel",
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      item_brand: "Google",
      affiliation: "Google Merchandise Store",
      currency: "USD",
      price: 9.99,
      quantity: 1
    }
  ]

CodePudding user response:

I think you can create a Custom JavaScript Variable in your GTM. enter image description here

Here is the code

function(){
  var yourItem = {{DLV-items}}
  var ga4Item = yourItem.map(function(o){
    return {
      item_id: o.id,
      item_name: o.name,
      affiliation:o.affiliation,
      currency: o.currency,
      item_brand: o.item_brand,
      item_category: o.category,
      price: o.price,
      quantity: o.quantity
    }
  })
  return ga4Item;
}

And the result in GTM preview will be

enter image description here

Blue one is your original item. Red one is the modified item you can use in GA4

  • Related