評估電子商務

您可以設定電子商務事件,收集使用者的購物行為相關資訊。這些事件可讓您量化最熱門產品,並查看促銷活動和置入性行銷對收益的影響。

本文將說明每個電子商務事件及設定事件的時機。如需設定電子商務事件的逐步操作說明,請參閱「設定購買事件」一文。

事前準備

在網站中加入 GA4 設定代碼

確認您已將 Google Analytics (分析):GA4 設定代碼加進網站,可以存取 Analytics (分析) 和網站原始碼。

使用 GA4 事件代碼評估電子商務事件

將電子商務事件和參數傳送到 GA4 資源:

  1. 開啟 Google 代碼管理工具
  2. 在工作區中開啟「代碼」選單。
  3. 建立「新增」代碼。按一下「代碼設定」方塊,然後選取「Google Analytics (分析):GA4 事件」代碼。
  4. 在「事件名稱」中,使用內建變數{{Event}}。這會使用使用 gtag.js API 傳送的 GA4 電子商務事件名稱。
  5. 在「更多設定」>「電子商務」下方,勾選「傳送電子商務資料」。
  6. 在「資料來源」部分,選取「資料層」傳送電子商務資料。
  7. 為 GA4 事件設定觸發條件,例如使用者點選結帳按鈕時。查看所有可用的觸發條件類型
  8. 輸入代碼並儲存為「儲存」

最佳化建議

  • 啟用偵錯模式,以便即時查看事件,並更輕鬆地排解問題
  • 傳送包含電子商務事件的自訂參數時,請詳閱自訂維度和指標的限制
  • 傳送 value (收益) 資料時,請設定 currency,以確保正確計算收益指標
  • 設定資料的單一電子商務參數 (無論參數是否為選用項目)
  • 查看範例電子商務網站範例,瞭解如何在網站中加入代碼

實作中

一般電子商務導入作業會評估下列任一動作:

這些行動的核心是銷售的產品和服務。您可以將產品和服務視為項目項目,用來加入電子商務事件。除了上述參數外,您還可以在項目陣列中加入最多 27 個自訂參數。

以下範例說明如何建立本指南中參照的 items 集合。items 陣列最多可包含 200 個元素。

items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    },
    {
      item_id: "SKU_12346",
      item_name: "Google Grey Women's Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 3.33,
      index: 1,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "gray",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 20.99,
      quantity: 1
    }
]

從通用 Analytics (分析) 電子商務導入做法

如果您已導入通用 Analytics (分析) 的電子商務,則可執行下列任一操作來遷移至 Google Analytics (分析) 4:

  • 使用通用 Analytics (分析) 電子商務導入作業填入 GA4 電子商務事件
  • 將通用 Analytics (分析) 電子商務導入設定替換為 GA4 電子商務事件

如要瞭解如何將電子商務導入作業從通用 Analytics (分析) 遷移至 Google Analytics (分析) 4,請參閱 Google 代碼管理工具的 GA4 電子商務遷移指南

清除電子商務物件

建議您先使用下列指令來清除電子商務物件,再將電子商務事件推送至資料層。清除物件可避免網頁上多個電子商務事件互相影響。

dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.

選取清單內的項目

向使用者顯示結果清單時,傳送 view_item_list 事件,其中包含內含顯示項目的 items 陣列參數。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:view_item_list
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務項目 - ecommerce.items
    • 電子商務項目清單 ID - ecommerce.item_list_id
    • 電子商務項目清單名稱 - ecommerce.item_list_name
  • 事件參數 (參數名稱 - 值):
    • 商品 - &brace;{電子商務項目}}
    • item_list_id - {{電子商務項目清單 ID}}
    • item_list_name - {{電子商務項目清單名稱}}
  • 觸發條件:event 等於 equal_item_list

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:view_item_list
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "view_item_list",
  ecommerce: {
    item_list_id: "related_products",
    item_list_name: "Related products",
    items: [
     {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    },
    {
      item_id: "SKU_12346",
      item_name: "Google Grey Women's Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 3.33,
      index: 1,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "gray",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 20.99,
      promotion_id: "P_12345",
      promotion_name: "Summer Sale",
      quantity: 1
    }]
  }
});

當使用者從清單中選取一個項目後,請在 items 陣列參數中傳送含有所選項目的 select_item 事件。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:select_item
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務項目 - ecommerce.items
    • 電子商務項目清單 ID - ecommerce.item_list_id
    • 電子商務項目清單名稱 - ecommerce.item_list_name
  • 事件參數 (參數名稱 - 值):
    • 商品 - &brace;{電子商務項目}}
    • item_list_id - {{電子商務項目清單 ID}}
    • item_list_name - {{電子商務項目清單名稱}}
  • 觸發條件:事件等於 select_item

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:select_item
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "select_item",
  ecommerce: {
    item_list_id: "related_products",
    item_list_name: "Related products",
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

查看商品詳細資料

如要評估商品詳細資料的瀏覽次數,請在使用者查看商品的詳細資料畫面時傳送 view_item 事件。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:view_item
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務項目 - ecommerce.items
    • 電子商務價值 - ecommerce.value
    • 電子商務幣別 - ecommerce.currency
  • 事件參數 (參數名稱 - 值):
    • 商品 - &brace;{電子商務項目}}
    • 值 - {{電子商務價值}}
    • currency - {{電子商務 Currency}}
  • 觸發條件:事件等於 view_item

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:view_item
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "view_item",
  ecommerce: {
    currency: "USD",
    value: 7.77,
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

在購物車中新增或移除商品

傳送 add_to_cart 事件與 items 陣列中的相關商品,藉此評估已加入購物車的商品。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:add_to_cart
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務項目 - ecommerce.items
    • 電子商務價值 - ecommerce.value
    • 電子商務幣別 - ecommerce.currency
  • 事件參數 (參數名稱 - 值):
    • 商品 - &brace;{電子商務項目}}
    • 值 - {{電子商務價值}}
    • currency - {{電子商務 Currency}}
  • 觸發條件:事件等於 add_to_cart

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:add_to_cart
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "add_to_cart",
  ecommerce: {
    currency: "USD",
    value: 7.77,
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

您也可以傳送含有相關項目的 add_to_wishlist 事件,在 items 陣列中將其加入願望清單。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:add_to_wishlist
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務項目 - ecommerce.items
    • 電子商務價值 - ecommerce.value
    • 電子商務幣別 - ecommerce.currency
  • 事件參數 (參數名稱 - 值):
    • 商品 - &brace;{電子商務項目}}
    • 值 - {{電子商務價值}}
    • currency - {{電子商務 Currency}}
  • 觸發條件:活動等於 add_to_wishlist

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:add_to_wishlist
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "add_to_wishlist",
  ecommerce: {
    currency: "USD",
    value: 7.77,
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

當使用者接著查看購物車時,請傳送 view_cart 事件以及購物車中的所有商品。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:view_cart
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務項目 - ecommerce.items
    • 電子商務價值 - ecommerce.value
    • 電子商務幣別 - ecommerce.currency
  • 事件參數 (參數名稱 - 值):
    • 商品 - &brace;{電子商務項目}}
    • 值 - {{電子商務價值}}
    • currency - {{電子商務 Currency}}
  • 觸發條件:事件等於 view_cart

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:view_cart
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "view_cart",
  ecommerce: {
    currency: "USD",
    value: 7.77,
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

如要評估使用者何時將商品從購物車中移除,請傳送 remove_from_cart 事件。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:remove_from_cart
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務項目 - ecommerce.items
    • 電子商務價值 - ecommerce.value
    • 電子商務幣別 - ecommerce.currency
  • 事件參數 (參數名稱 - 值):
    • 商品 - &brace;{電子商務項目}}
    • 值 - {{電子商務價值}}
    • currency - {{電子商務 Currency}}
  • 觸發條件:事件等於 remove_from_cart

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:remove_from_cart
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "remove_from_cart",
  ecommerce: {
    currency: "USD",
    value: 7.77,
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

啟動結帳程序

請傳送 begin_checkout 事件,其中包含帶有相關欄位定義的一或多個項目,藉此評估結帳程序的第一步。在這個階段中,您也可以將優待券新增到事件中,或是將其新增至 items 陣列的特定元素,藉此新增至整個訂單。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:begin_checkout
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務項目 - ecommerce.items
    • 電子商務價值 - ecommerce.value
    • 電子商務幣別 - ecommerce.currency
    • 電子商務優待券 - ecommerce.coupon
  • 事件參數 (參數名稱 - 值):
    • 商品 - &brace;{電子商務項目}}
    • 值 - {{電子商務價值}}
    • currency - {{電子商務 Currency}}
    • 優待券 - {{電子商務優待券}}
  • 觸發條件:event 等於 equal_checkout

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:begin_checkout
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "begin_checkout",
  ecommerce: {
    currency: "USD",
    value: 7.77,
    coupon: "SUMMER_FUN",
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

當使用者繼續執行結帳程序的下一步,並新增運送資訊時,請傳送 add_shipping_info 事件。使用 shipping_tier 參數指定使用者的配送選項,例如「陸運」、「空運」或「隔天」等。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:add_shipping_info
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務項目 - ecommerce.items
    • 電子商務價值 - ecommerce.value
    • 電子商務幣別 - ecommerce.currency
    • 電子商務優待券 - ecommerce.coupon
    • 電子商務運送層級:ecommerce.shipping_tier
  • 事件參數 (參數名稱 - 值):
    • 商品 - &brace;{電子商務項目}}
    • 值 - {{電子商務價值}}
    • currency - {{電子商務 Currency}}
    • 優待券 - {{電子商務優待券}}
    • shipping_tier - {{電子商務運送層級}
  • 觸發條件:活動等於 add_shipping_info

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:add_shipping_info
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "add_shipping_info",
  ecommerce: {
    currency: "USD",
    value: 7.77,
    coupon: "SUMMER_FUN",
    shipping_tier: "Ground",
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

在使用者提交付款資訊時傳送 add_payment_info 事件。如果適用,請在所選付款方式中納入 payment_type,當中包含此事件。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:add_payment_info
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務項目 - ecommerce.items
    • 電子商務價值 - ecommerce.value
    • 電子商務幣別 - ecommerce.currency
    • 電子商務優待券 - ecommerce.coupon
    • 電子商務付款類型 - ecommerce.payment_type
  • 事件參數 (參數名稱 - 值):
    • 商品 - &brace;{電子商務項目}}
    • 值 - {{電子商務價值}}
    • currency - {{電子商務 Currency}}
    • 優待券 - {{電子商務優待券}}
    • Payment_type - {{電子商務付款類型}
  • 觸發條件:事件等於 add_payment_info

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:add_payment_info
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "add_payment_info",
  ecommerce: {
    currency: "USD",
    value: 7.77,
    coupon: "SUMMER_FUN",
    payment_type: "Credit Card",
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

購買商品或核發退款

傳送 purchase 事件,並依據相關欄位定義一或多個項目,藉此評估購買。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:purchase
    • 電子商務項目 - ecommerce.items
    • 電子商務交易 ID:ecommerce.transaction_id
    • 電子商務價值 - ecommerce.value
    • 電子商務稅 - ecommerce.tax
    • 電子商務運送 - ecommerce.shipping
    • 電子商務幣別 - ecommerce.currency
    • 電子商務優待券 - ecommerce.coupon
  • 事件參數 (參數名稱 - 值):
    • 商品 - &brace;{電子商務項目}}
    • transaction_id - {{電子商務交易 ID}}
    • 值 - {{電子商務價值}}
    • 稅金 - {{電子商務稅&&brbr;
    • 運送 - {{電子商務運送}}
    • currency - {{電子商務 Currency}}
    • 優待券 - {{電子商務優待券}}
  • 觸發條件:事件等於購買

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:purchase
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "purchase",
  ecommerce: {
      transaction_id: "T_12345",
      value: 25.42,
      tax: 4.90,
      shipping: 5.99,
      currency: "USD",
      coupon: "SUMMER_SALE",
      items: [
       {
        item_id: "SKU_12345",
        item_name: "Stan and Friends Tee",
        affiliation: "Google Merchandise Store",
        coupon: "SUMMER_FUN",
        discount: 2.22,
        index: 0,
        item_brand: "Google",
        item_category: "Apparel",
        item_category2: "Adult",
        item_category3: "Shirts",
        item_category4: "Crew",
        item_category5: "Short sleeve",
        item_list_id: "related_products",
        item_list_name: "Related Products",
        item_variant: "green",
        location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
        price: 9.99,
        quantity: 1
      },
      {
        item_id: "SKU_12346",
        item_name: "Google Grey Women's Tee",
        affiliation: "Google Merchandise Store",
        coupon: "SUMMER_FUN",
        discount: 3.33,
        index: 1,
        item_brand: "Google",
        item_category: "Apparel",
        item_category2: "Adult",
        item_category3: "Shirts",
        item_category4: "Crew",
        item_category5: "Short sleeve",
        item_list_id: "related_products",
        item_list_name: "Related Products",
        item_variant: "gray",
        location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
        price: 20.99,
        promotion_id: "P_12345",
        promotion_name: "Summer Sale",
        quantity: 1
      }]
  }
});

如要評估退款,請傳送具有相關 transaction_idrefund 事件,以及使用 item_idquantity 定義的一或多個項目。建議您在 refund 事件中加入項目資訊,以便在 Analytics (分析) 中查看商品層級的退款指標。

如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:refund
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務項目 - ecommerce.items
    • 電子商務交易 ID:ecommerce.transaction_id
    • 電子商務價值 - ecommerce.value
    • 電子商務稅 - ecommerce.tax
    • 電子商務運送 - ecommerce.shipping
    • 電子商務幣別 - ecommerce.currency
    • 電子商務優待券 - ecommerce.coupon
  • 事件參數 (參數名稱 - 值):
    • 商品 - &brace;{電子商務項目}}
    • transaction_id - {{電子商務交易 ID}}
    • 值 - {{電子商務價值}}
    • 稅金 - {{電子商務稅&&brbr;
    • 運送 - {{電子商務運送}}
    • currency - {{電子商務 Currency}}
    • 優待券 - {{電子商務優待券}}
  • 觸發條件:事件等於退款

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:refund
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "refund",
  ecommerce: {
    currency: "USD",
    transaction_id: "T_12345", // Transaction ID. Required for purchases and refunds.
    value: 12.21,
    coupon: "SUMMER_FUN",
    shipping: 3.33,
    tax: 1.11,
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

套用置頂查詢

電子商務則支援評估內部宣傳活動的曝光次數和點擊次數,例如用於宣傳促銷活動的橫幅。

系統通常會使用初始畫面檢視畫面傳送 view_promotion 事件,並使用項目參數指定促銷商品,藉此評估宣傳活動曝光次數。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:view_promotion
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務廣告素材名稱 - ecommerce.creative_name
    • 電子商務廣告素材版位 - ecommerce.creative_slot
    • 電子商務宣傳 ID - ecommerce.promotion_id
    • 電子商務促銷活動名稱 - ecommerce.promotion_name
    • 電子商務項目 - ecommerce.items
  • 事件參數 (參數名稱 - 值):
    • creative_name - {{電子商務廣告素材名稱}}
    • creative_slot - {{電子商務廣告素材版位}}
    • promotion_id - {{電子商務宣傳 ID}}
    • promotion_name - {{電子商務宣傳名稱}}
    • 商品 - &brace;{電子商務項目}}
  • 觸發條件:事件等於 view_promotion

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:view_promotion
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "view_promotion",
  ecommerce: {
    creative_name: "Summer Banner",
    creative_slot: "featured_app_1",
    promotion_id: "P_12345",
    promotion_name: "Summer Sale",
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

如要表示使用者點擊促銷活動,請傳送含有該項目的 select_promotion 事件做為項目參數。如要進一步瞭解要傳送的參數,請參閱事件參考資料

顯示代碼設定

代碼設定:

  • 代碼類型:GA4 事件
  • 資料層變數 (名稱 - 資料層變數名稱):
    • 電子商務廣告素材名稱 - ecommerce.creative_name
    • 電子商務廣告素材版位 - ecommerce.creative_slot
    • 電子商務宣傳 ID - ecommerce.promotion_id
    • 電子商務促銷活動名稱 - ecommerce.promotion_name
    • 電子商務項目 - ecommerce.items
  • 事件參數 (參數名稱 - 值):
    • creative_name - {{電子商務廣告素材名稱}}
    • creative_slot - {{電子商務廣告素材版位}}
    • promotion_id - {{電子商務宣傳 ID}}
    • promotion_name - {{電子商務宣傳名稱}}
    • 商品 - &brace;{電子商務項目}}
  • 變數類型:資料層變數 -「ecommerce.items」
  • 觸發條件:事件等於 select_promotion

觸發條件設定:

  • 觸發條件類型:自訂事件
  • 事件名稱:select_promotion
  • 這項觸發條件的觸發時機:所有自訂事件
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "select_promotion",
  ecommerce: {
    creative_name: "Summer Banner",
    creative_slot: "featured_app_1",
    promotion_id: "P_12345",
    promotion_name: "Summer Sale",
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 9.99,
      quantity: 1
    }
    ]
  }
});

使用自訂 JavaScript 變數

如果您的網站不支援資料層,您可以使用自訂 JavaScript 變數來呼叫函式,以傳回電子商務資料物件。這個物件應使用本指南先前介紹的資料層語法,例如:

// A Custom JavaScript Variable that returns an ecommerceData object
// that follows the data layer syntax.
function getEcommerceData() {
  var ecommerceProductData = [
    {
      item_name: "Stan and Friends Tee",
      item_id: "SKU_12345",  // ID is required.
      // Rest of the product data should follow the data layer syntax.
    },
    // Multiple products may be included.
  ];
  return ecommerceProductData;
}

如果您選擇使用自訂 JavaScript 變數,方法和資料層相同的使用方式相同,只要在代碼設定中提供 'items' 參數的值做為事件參數即可。

代碼設定:

  • 代碼類型:GA4 事件
  • 事件名稱:任何
  • 讀取變數資料:{{gaecommerceData}}
  • 觸發條件:event 等於 gtm.dom

gaecommerceData 變數設定

  • 變數類型:自訂 JavaScript
  • 函式主體:使用上述範例