文章目录[隐藏]
更新时间:2025年6月18号
本文介绍如何通过gtag方法布署GA4电商跟踪,如果你是使用GTM,这篇内容不适合你,请看:详解Google Tag Manager布署GA4电商跟踪指南
GA4电商布署方式
根据网站类型和安装方式,GA4电商布署主要有三种:
- SAAS系统插件:适合无源码权限的建站平台,只能通过系统插件实现
- gtag方式布署:如果没有使用GTM安装GA4,直接布署GA4的方式,本篇重点介绍此方法
- GTM布署方式(推荐):如果使用GTM安装GA4
GA4电商事件概览
GA4电商事件覆盖了产品展示 →用户浏览 →点击→查看→ 选择 → 加入购物车 → 结账 → 支付 → 退款的整个生命周期。
每一步(也称为事件),都需要前端通过gtag去发送特定结构的数据,GA4报告就会有数据。
下面以为view_item_list作为例子讲解前端的发送时机,数据结构。
示例:view_item_list布署
view_item_list是产品展示的意思,页面打开,产品展示出来,前端就通过gtag发送电商数据。
gtag页面发送示例
前端通过gtag发送如下数据结构:
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'
});
items表示产品,里面可以包含多个产品,建议是一次发送多个产品,不要每个产品单独发送。
items参数解析
items里有很多的参数,详细如下:
| 名称 | 类型 | 是否必须提供 | 示例值 | 说明 |
|---|---|---|---|---|
item_ |
string |
是* | SKU_12345 | 商品的 ID。 *必须提供 item_id 或 item_name 中的一个。 |
item_ |
string |
是* | Stan 和 Friends Tee | 商品的名称。 *必须提供 item_id 或 item_name 中的一个。 |
affiliation |
string |
否 | Google 商店 | 用于指定供应公司或实体店位置的商品关联商户。 事件级和商品级 affiliation 参数彼此独立。 |
coupon |
string |
否 | SUMMER_FUN | 与商品相关的优惠券名称/代码。 事件级和商品级 coupon 参数彼此独立。 |
currency |
string |
否 | USD | 币种(采用由 3 个字母表示的 ISO 4217 格式)。 如果设置此参数,系统会忽略事件级 currency。不支持为每个事件设置多种币种。应为每件商品设置同一币种。 |
creative_ |
string |
否 | summer_banner2 | 促销广告素材的名称。 如果设置此参数,系统会忽略事件级 creative_。如果未设置此参数,系统会使用事件级 creative_(如果存在)。 |
creative_ |
string |
否 | featured_app_1 | 与商品相关的促销广告素材投放到的广告位的名称。 如果设置此参数,系统会忽略事件级 creative_。如果未设置此参数,系统会使用事件级 creative_(如果存在)。 |
discount |
number |
否 | 2.22 | 与商品相关的折扣货币价值。 |
index |
number |
否 | 5 | 列表中商品的索引/商品在列表中的位置。 |
item_ |
string |
否 | 商品所属品牌。 | |
item_ |
string |
否 | 服饰 | 商品所属类别。如果将其用作类别层次结构或类目的一部分,则为第一个类别。 |
item_ |
string |
否 | 成人 | 商品的第二类层次结构或其他类目。 |
item_ |
string |
否 | 衬衫 | 商品的第三类层次结构或其他类目。 |
item_ |
string |
否 | 圆领 | 商品的第四类层次结构或其他类目。 |
item_ |
string |
否 | 短袖 | 商品的第五类层次结构或其他类目。 |
item_ |
string |
否 | related_products | 商品向用户展示时所在列表的 ID。 如果设置此参数,系统会忽略事件级 item_。如果未设置此参数,系统会使用事件级 item_(如果存在)。 |
item_ |
string |
否 | 相关商品 | 商品向用户展示时所在列表的名称。 如果设置此参数,系统会忽略事件级 item_。如果未设置此参数,系统会使用事件级 item_(如果存在)。 |
item_ |
string |
否 | 绿色 | 用于提供其他商品详情/选项的商品款式/规格、唯一代码或说明。 |
location_ |
string |
否 | L_12345 | 与商品相关的地理位置。建议使用与相关商品对应的 Google 地点 ID,也可使用自定义地理位置 ID。</span 如果设置此参数,系统会忽略事件级 location_。如果未设置此参数,系统会使用事件级 location_(如果存在)。 |
price |
number |
否 | 9.99 | 商品的货币价格(以指定的 currency 参数为单位)。 |
promotion_ |
string |
否 | P_12345 | 与商品相关的促销活动的 ID。 如果设置此参数,系统会忽略事件级 promotion_。如果未设置此参数,系统会使用事件级 promotion_(如果存在)。 |
promotion_ |
string |
否 | 夏季促销 | 与商品相关的促销活动的名称。 如果设置此参数,系统会忽略事件级 promotion_。如果未设置此参数,系统会使用事件级 promotion_(如果存在)。 |
quantity |
number |
否 | 1 | 商品数量。 |
这一步有几个注意点:
- GA4里的items里是产品数组,所有的产品信息都在里面
- item里面的item_id和item_name是必须字段,其他都是可选。
- 产品不同位置是通过item_list_id和item_list_name去区分,一般是必须参数,才可以知道展示的位置
整站gtag布署电商示例
普通产品
- 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_
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
});
注意点
- 同个页面有多个电商事件类型的时候,尽量同一次发送出去,也就是一个发送多个产品,如一个页面有5个产品展示,在一个gtag就发送出去
- 金额不同,如price发送的是35,但报告显示的是35.04,这是因为货币会先换算为美元,再换算为你设置的币种。
- DebugView里的价格显示错误:如果你用DebugView去调试电商跟踪,那么你可能会看到价格显示一样,实际是250,但显示250000000,这不是bug,这是为了提升数据存储效率与计算性能,GA4在内部会将部分浮点数(如价格、金额)转换为整数形式进行存储与处理,不影响GA4里的数据
- 事件有数据,但电商里没数据,一般是是数据结构不对导致,如revenue是0,通常是货币类型为空导致,view_item是0,通常是items里的数据结构不对导致



