Google Analytics 4 布署电子商务

Google Analytics 4 黄业忠 6个月前 (06-01) 1742次浏览 34个评论

如果你是用GTM安裝GA4的方式,可以参考:Google Analytics 4 :Google Tag Manager电商配置指南

布署的过程中可能会遇到一些问题,可以参考:Google Analytics 4 电子商务跟踪常见问题

这一节我们来介绍,如果你不用Google Tag Manager去安装Google Analytics44,而是通过直接安装gtag.js追踪码的方式,看如何实现电子商务的设置。

由于没有使用Google Tag Manager,所以需要开发通过代码直接实现电子商务事件,它直接就能够将事件发送给GA4,接下来,我们来看不同电商位置需要布署的示例代码:

 

普通产品

  • view_item_list :产品展示
  • view_item:查看产品
  • select_item:点击产品

 

view_item_list :产品展示

gtag('event', 'view_item_list', {
  items: [{
    item_id: 'SKU_12345',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    index: 5,
    item_list_name: 'Related Products',
    item_list_id: 'related_products',
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'black',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }],
  item_list_name: 'Related products',
  item_list_id: 'related_products'
});

 

注意item_list_name 或 item_list_id 的值必須保持固定。对于给定的列表,这些值始终是相同的。

view_item:查看产品

gtag('event', 'view_item', {
  currency: 'USD',
  items: [{
    item_id: 'SKU_12345',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'black',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }],
  value: 9.99
});

 

 

select_item:点击产品

gtag('event', 'select_item', {
  items: [{
    item_id: 'SKU_12345',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    index: 5,
    item_list_name: 'Related Products',
    item_list_id: 'related_products',
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'black',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }],
  item_list_name: 'Related products',
  item_list_id: 'related_products'
});

 

 

促销产品

  • view_promotion:促销产品展示
  • select_promotion:点击促销产品

 

view_promotion:促销产品展示

gtag('event', 'view_promotion', {
  items: [{
    item_id: 'SKU_12345',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    promotion_id: 'P_12345',
    promotion_name: 'Summer Sale',
    creative_slot: 'featured_app_1',
    location_id: 'L_12345',
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'Black',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }],
  location_id: 'L_12345'
});

 

select_promotion:点击促销产品

gtag('event', 'select_promotion', {
  items: [{
    item_id: 'SKU_12345',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    promotion_id: 'P_12345',
    promotion_name: 'Summer Sale',
    creative_name: 'Summer Banner',
    creative_slot: 'featured_app_1',
    location_id: 'L_12345',
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'Black',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }],
  location_id: 'L_12345'
});

 

购物车

  • add_to_cart:将产品添加到购物车
  • remove_from_cart:将产品从购物车中移除

购物车中currency和value是必须字段。

 

add_to_cart:将产品添加到购物车

gtag('event', 'add_to_cart', {
  currency: 'USD',
  items: [{
    item_id: 'SKU_12345',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'black',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }],
  value: 7.77
});

 

 

remove_from_cart:将产品从购物车中移除

gtag('event', 'remove_from_cart', {
  currency: 'USD',
  items: [{
    item_id: 'SKU_12345',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'black',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }],
  value: 7.77
});

 

结算流程

  • begin_checkout:开始结算
  • add_payment_info:添加支付信息
  • add_shipping_info:添加地址信息
  • purchase:购买成功
  • refund:退款

currency和value是必须字段,购买成功和退款中transaction_id是必须字段。

begin_checkout:开始结算

gtag('event', 'begin_checkout', {
  coupon: 'SUMMER_FUN',
  currency: 'USD',
  items: [{
    item_id: 'SKU_12345',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'black',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }],
  value: 7.77
});

 

add_payment_info:添加支付信息

gtag('event', 'add_payment_info', {
  coupon: 'SUMMER_FUN',
  currency: 'USD',
  items: [{
    item_id: 'SKU_12345',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'black',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }],
  payment_type: 'Credit Card',
  value: 9.99
});

 

add_shipping_info:添加地址信息

gtag('event', 'add_shipping_info', {
  coupon: 'SUMMER_FUN',
  currency: 'USD',
  items: [{
    item_id: 'SKU_12345',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'Black',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }],
  shipping_tier: 'Ground',
  value: 7.77
});

 

purchase:购买成功

gtag('event', 'purchase', {
  affiliation: 'Google Store',
  coupon: 'SUMMER_FUN',
  currency: 'USD',
  items: [{
    item_id: 'SKU_12345',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'black',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }, {
    item_id: 'SKU_12346',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'gray',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }],
  transaction_id: 'T_12345',
  shipping: 3.33,
  value: 21.09,
  tax: 2.22
})

 

refund:退款

退款分为全額退款和部分退款

全额退款

gtag('event', 'refund', {
  affiliation: 'Google Store',
  coupon: 'SUMMER_FUN',
  currency: 'USD',
  transaction_id: 'T_12345',
  shipping: 3.33,
  value: 12.21,
  tax: 1.11
});

 

部分退款

gtag('event', 'refund', {
  affiliation: 'Google Store',
  coupon: 'SUMMER_FUN',
  currency: 'USD',
  items: [{
    item_id: 'SKU_12345',
    item_name: 'jeggings',
    coupon: 'SUMMER_FUN',
    discount: 2.22,
    affiliation: 'Google Store',
    item_brand: 'Gucci',
    item_category: 'pants',
    item_variant: 'black',
    price: 9.99,
    currency: 'USD',
    quantity: 1
  }],
  transaction_id: 'T_12345',
  shipping: 3.33,
  value: 12.21,
  tax: 1.11
});

 

 


GA小站, 版权所有丨如未注明 , 均为原创

转载请注明标题:Google Analytics 4 布署电子商务
链接:https://www.ichdata.com/google-analytics-4-implements-e-commerce-event-setup.html

喜欢 (3)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(34)个小伙伴在吐槽
  1. 站长您好,GA4的purchase事件抓不全是怎么回事啊,经常有很多抓取不到,但是又有一部分能抓取到,部署应该没问题吧?
    红枫+2022-12-03 11:38 (7天前)回复 Windows 10 | Chrome 106.0.0.0
  2. 站长您好,这里面的价格和订单金额的数值类型是字符串类型还是浮点类型?google帮助文档里面都是字符串类型,我用的字符串类型,有很大一部分没法抓到,是怎么回事?
    红枫+2022-11-08 10:25 回复 Windows 10 | Chrome 106.0.0.0
    • 黄业忠
      价格是和金额是浮点,数量是整型,文档里都是没有'',是数字,不需要''就可以
      黄业忠2022-11-08 11:18 回复 Mac OS X | Chrome 107.0.0.0
1 2