简体   繁体   中英

Can ecommerce item for GA4 add_to_cart event have custom parameters?

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
    }
  ]

I think you can create a Custom JavaScript Variable in your GTM. 在此处输入图像描述

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

在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM