本頁將說明如何使用 gtag.js 收集加強型電子商務資料。如果您已在 gtag.js 中設定 Google Analytics (分析),並且在 Google Analytics (分析) 中啟用加強型電子商務,就可以使用 gtag.js 將曝光資料、產品資料、促銷活動資料和動作資料傳送至 Google Analytics (分析)。
加強型電子商務資料類型和動作
您可以選擇傳送多種類型的電子商務資料:
曝光資料
代表使用者查看過的產品相關資訊。稱為 impressionFieldObject
,其中包含下列值:
鍵 | 值類型 | 必要 | 說明 |
---|---|---|---|
id |
text | *是 |
產品 ID 或 SKU (例如 P67890)。
* 必須設定 |
name |
text | *是 |
產品名稱 (例如 Android T 恤)。
* 必須設定 |
list |
text | 否 | 產品所屬的清單或集合 (例如搜尋結果) |
list_name |
text | 否 | 產品所屬的清單或集合 (例如搜尋結果) |
brand |
text | 否 | 與產品相關聯的品牌 (例如 Google)。 |
category |
text | 否 |
產品所屬的類別 (例如服飾)。使用 / 做為分隔符號,即可指定最多 5 層階層 (例如服飾/男性/T 恤)。 |
variant |
text | 否 | 產品的子類 (例如黑色)。 |
position |
整數 | 否 | 產品在清單或集合中的位置 (例如 2)。 |
list_position |
整數 | 否 | 產品在清單或集合中的位置 (例如 2)。 |
price |
號碼 | 否 | 產品的價格 (例如 29.20)。 |
產品資料
產品資料代表瀏覽、加入購物車等的個別產品。稱為 productFieldObject
,其中包含下列值:
鍵 | 值類型 | 必要 | 說明 |
---|---|---|---|
id |
text | *是 |
產品 ID 或 SKU (例如 P67890)。
* 必須設定其中一個 ID 或 |
name |
text | *是 |
產品名稱 (例如 Android T 恤)。
* 必須設定其中一個 ID 或 |
brand |
text | 否 | 與產品相關聯的品牌 (例如 Google)。 |
category |
text | 否 | 產品所屬的類別 (例如服飾)。使用 / 做為分隔符號,最多可指定 5 層階層 (例如「服飾/男性/T 恤」)。 |
variant |
text | 否 | 產品的子類 (例如黑色)。 |
price |
號碼 | 否 | 產品的價格 (例如 29.20)。 |
quantity |
整數 | 否 | 產品數量 (例如 2)。 |
coupon |
text | 否 | 與產品 (例如 SUMMER_SALE13) 相關聯的優待券代碼。 |
position |
整數 | 否 | 產品在清單或集合中的位置 (例如 2)。 |
list_position |
整數 | 否 | 產品在清單或集合中的位置 (例如 2)。 |
促銷活動資料
代表已查看的促銷活動相關資訊。稱為 promoFieldObject
,其中包含下列值:
鍵 | 值類型 | 必要 | 說明 |
---|---|---|---|
id |
text | *是 |
促銷 ID (例如 PROMO_1234)。
* 必須設定 |
name |
text | *是 |
促銷活動名稱 (例如夏季特賣)。
* 必須設定 |
creative |
text | 否 | 與宣傳活動相關聯的廣告素材 (例如 Summer_banner2)。 |
creative_name |
text | 否 | 廣告素材的名稱 (例如 Summer_banner2)。 |
position |
text | 否 | 廣告素材的位置 (例如 watch_slot_1)。 |
creative_slot |
text | 否 | 廣告素材版位名稱 (例如 watch_slot_1)。 |
動作資料
代表發生的電子商務相關動作資訊。
稱為 actionFieldObject
,其中包含下列值:
鍵 | 值類型 | 必要 | 說明 |
---|---|---|---|
id |
text | *是 |
交易 ID (例如 T1234)。
* 如果動作類型為 |
affiliation |
text | 否 | 進行這筆交易的商店或聯盟 (例如 Google 商店)。 |
revenue |
號碼 | 否 |
指定與交易相關的總收益或總和 (例如 11.99)。這個值可能包含運費、稅金或其他收益調整項,您可以在計算收益時納入這些調整。 |
值 | 號碼 | 否 | 與事件相關聯的值 (亦即收益)。 |
tax |
號碼 | 否 | 與交易相關的稅金總額。 |
shipping |
號碼 | 否 | 與交易相關聯的運費。 |
coupon |
text | 否 | 交易兌換優待券。 |
list |
text | 否 | 相關聯產品所屬的清單。選用。 |
items |
陣列 | 否 | 包含相關產品的陣列。 |
step |
整數 | 否 | 代表結帳流程步驟的數字。「結帳」動作的選用項目。 |
checkout_step |
整數 | 否 | 代表結帳流程步驟的數字。 |
option |
text | 否 |
額外的 checkout 和 checkout_option 動作欄位,用於說明結帳頁面中的選項資訊,例如選取的付款方式。 |
checkout_option |
text | 否 | 結帳選項 (即已選取的付款方式)。 |
鍵 | 值類型 | 必要 | 說明 |
---|---|---|---|
coupon |
字串 | 否 | 可購買商品的優待券代碼。 |
產品和促銷活動動作
動作可指定如何解讀您傳送至 Google Analytics (分析) 的產品和促銷活動資料。
操作 | 活動 | 說明 |
---|---|---|
click |
點擊一或多項產品的產品或產品連結。 | |
detail |
產品詳細資料的檢視畫面。 | |
add |
將一或多項產品加入購物車。 | |
remove |
從購物車中移除一或多項產品。 | |
checkout |
正在啟動一或多項產品的結帳流程。 | |
checkout_option |
傳送指定結帳步驟的選項值。 | |
purchase |
銷售一或多項產品。 | |
refund |
一或多項產品的退款。 | |
promo_click |
點擊內部宣傳活動。 | |
add_to_cart |
使用者將一或多項產品加入購物車。 | |
begin_checkout |
使用者展開一或多項產品的結帳流程。 | |
checkout_progress |
使用者在第一個結帳步驟後完成結帳步驟。 | |
purchase |
使用者完成購買。 | |
refund |
使用者收到一或多項產品的退款。 | |
remove_from_cart |
使用者從購物車中移除一或多項產品。 | |
select_content |
使用者按下產品或產品連結。 | |
set_checkout_option |
使用者完成的結帳步驟。 | |
view_item |
使用者查看產品詳細資料。 | |
view_item_list |
使用者查看一或多項產品的清單。 | |
view_promotion |
使用者按下內部促銷活動。 | |
view_refund |
使用者查看一或多項產品的退款。 |
示例
評估產品曝光次數
如要評估產品曝光次數,請傳送包含產品資訊的 view_item_list
:
gtag('event', 'view_item_list', {
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Apparel/T-Shirts",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": 2
},
{
"id": "P67890",
"name": "Flame challenge TShirt",
"list_name": "Search Results",
"brand": "MyBrand",
"category": "Apparel/T-Shirts",
"variant": "Red",
"list_position": 2,
"quantity": 1,
"price": 3
}
]
});
評估產品點擊次數
如要評估產品點擊,請傳送 select_content
事件,將 product
指定為 content_type
,並提供產品資訊:
gtag('event', 'select_content', {
"content_type": "product",
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Apparel/T-Shirts",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": 2
}
]
});
評估產品詳細資料瀏覽次數
使用者點選產品資訊後,可能會看到產品詳細資料頁面。如要評估產品詳細資料的檢視畫面,請傳送含有產品詳細資料的 view_item
事件:
gtag('event', 'view_item', {
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Apparel/T-Shirts",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": '2.0'
}
]
});
評估購物車新增和移除的次數
如要評估將產品加入購物車的情況,請傳送含有產品資訊的 add_to_cart
事件:
gtag('event', 'add_to_cart', {
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Apparel/T-Shirts",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": '2.0'
}
]
});
如要評估將產品從購物車中移除的情形,請傳送含有產品資訊的 remove_from_cart
事件:
gtag('event', 'remove_from_cart', {
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Apparel/T-Shirts",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": '2.0'
}
]
});
評估結帳次數
如要評估結帳程序的每個步驟:
- 加入評估程式碼,評估結帳程序的每個步驟。
- 如果適用,請加入評估程式碼來記錄結帳選項。
1. 評估結帳步驟
如要評估第一個結帳步驟,請傳送含有結帳項目的 begin_checkout
事件:
gtag('event', 'begin_checkout', {
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Apparel/T-Shirts",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": '2.0'
}
],
"coupon": ""
});
如要評估每個後續的結帳步驟,請傳送含有結帳項目的 checkout_progress
事件:
gtag('event', 'checkout_progress', {
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Apparel/T-Shirts",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": '2.0'
}
],
"coupon": "SUMMER_DISCOUNT"
});
2. 評估結帳選項
如要評估結帳選項,請傳送包含結帳選項的 set_checkout_option
事件:
gtag('event', 'set_checkout_option', {
"checkout_step": 1,
"checkout_option": "shipping method",
"value": 3
});
評估宣傳活動曝光次數
如要評估促銷活動曝光次數,請傳送含有促銷資訊的 view_promotion
事件:
gtag('event', 'view_promotion', {
"promotions": [
{
"id": "abc123",
"name": "summer_promo"
},
{
"id": "xyz987",
"name": "spring savings"
}
]
});
評估宣傳活動點擊次數
如要評估促銷資訊點擊,請傳送 select_content
事件並提供促銷活動:
gtag('event', 'select_content', {
"promotions": [
{
"id": "abc123",
"name": "summer_promo"
}
]
});
評估購買情形
如要評估交易,請傳送含有交易項目的 purchase
事件:
gtag('event', 'purchase', {
"transaction_id": "24.031608523954162",
"affiliation": "Google online store",
"value": 23.07,
"currency": "USD",
"tax": 1.24,
"shipping": 0,
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Apparel/T-Shirts",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": '2.0'
},
{
"id": "P67890",
"name": "Flame challenge TShirt",
"list_name": "Search Results",
"brand": "MyBrand",
"category": "Apparel/T-Shirts",
"variant": "Red",
"list_position": 2,
"quantity": 1,
"price": '3.0'
}
]
});
評估退款情況
如要評估交易的完整退款,請傳送含有交易 ID 的 refund
事件:
gtag('event', 'refund', { "transaction_id": "T12345" })
如要評估部分退款,請傳送包含交易 ID 和要退款項目的 refund
事件:
gtag('event', 'refund', {
"transaction_id": "79.18502354114992",
"affiliation": "Google online store",
"value": 23.07,
"currency": "USD",
"tax": 1.24,
"shipping": 0,
"items": [
{
"id": "P12345",
"name": "Android Warhol T-Shirt",
"list_name": "Search Results",
"brand": "Google",
"category": "Apparel/T-Shirts",
"variant": "Black",
"list_position": 1,
"quantity": 2,
"price": '2.0'
},
{
"id": "P67890",
"name": "Flame challenge TShirt",
"list_name": "Search Results",
"brand": "MyBrand",
"category": "Apparel/T-Shirts",
"variant": "Red",
"list_position": 2,
"quantity": 1,
"price": '3.0'
}
]
});