加強型電子商務追蹤

本文將概略介紹如何使用 Android 專用的 Google Analytics (分析) SDK v4,評估應用程式內電子商務相關動作和曝光。

總覽

「加強型電子商務」可用於評估使用者在購物體驗中與產品的互動,包括產品曝光、產品點擊、查看產品詳細資料、將產品加入購物車、啟動結帳程序、交易和退款。

導入作業

若要進行加強型電子商務評估,您必須使用 HitBuilder 類別及其一組方法,才能傳送產品、曝光次數和促銷活動的電子商務資料。此外,我們還提供一組 Google Analytics (分析) 電子商務類別,可用於建構電子商務相關資訊。

透過加強型電子商務,您可以:

評估電子商務活動

採用常見加強型電子商務導入方式會評估產品曝光次數和下列任何一種動作:

  • 選取產品。
  • 查看產品詳細資料。
  • 曝光及選擇內部宣傳活動。
  • 加入 / 移除購物車中的產品。
  • 啟動產品的結帳程序。
  • 購買和退款。

評估曝光次數

如要評估產品曝光,請建構 Product 物件,並使用 addImpression 方法隨命中傳送。Product 必須有名稱或 ID 值。所有其他值則為選用值,您不需要設定。

Product product = new Product()
    .setId("P12345")
    .setName("Android Warhol T-Shirt")
    .setCategory("Apparel/T-Shirts")
    .setBrand("Google")
    .setVariant("Black")
    .setPosition(1)
    .setCustomDimension(1, "Member");
HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder()
    .addImpression(product, "Search Results");

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
t.setScreenName("searchResults");
t.send(builder.build());

如要進一步瞭解 getTracker 方法,請參閱「 進階設定」。

評估動作

使用 addProduct 方法搭配 Product 物件新增產品詳細資料,並使用 setProductAction 方法搭配 ProductAction 物件指定正在執行的動作,藉此評估動作。

例如,以下程式碼會測量在搜尋結果清單中顯示的產品選取項目:

Product product =  new Product()
    .setId("P12345")
    .setName("Android Warhol T-Shirt")
    .setCategory("Apparel/T-Shirts")
    .setBrand("Google")
    .setVariant("Black")
    .setPosition(1)
    .setCustomDimension(1, "Member");
ProductAction productAction = new ProductAction(ProductAction.ACTION_CLICK)
    .setProductActionList("Search Results");
HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder()
    .addProduct(product)
    .setProductAction(productAction);

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
t.setScreenName("searchResults");
t.send(builder.build());

結合曝光與動作

如果同時有產品曝光和一項動作,可以在單一命中中結合並評估這一點。

以下範例說明如何評估含相關產品區段的產品詳細資料檢視畫面:

// The product from a related products section.
Product relatedProduct =  new Product()
    .setId("P12346")
    .setName("Android Warhol T-Shirt")
    .setCategory("Apparel/T-Shirts")
    .setBrand("Google")
    .setVariant("White")
    .setPosition(1);

// The product being viewed.
Product viewedProduct =  new Product()
    .setId("P12345")
    .setName("Android Warhol T-Shirt")
    .setCategory("Apparel/T-Shirts")
    .setBrand("Google")
    .setVariant("Black")
    .setPosition(1);

ProductAction productAction = new ProductAction(ProductAction.ACTION_DETAIL);
HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder()
    .addImpression(relatedProduct, "Related Products")
    .addProduct(viewedProduct)
    .setProductAction(productAction);

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
t.setScreenName("product");
t.send(builder.build());

評估交易

使用 addProduct 方法搭配 Product 物件新增產品詳細資料,並使用 setProductAction 方法搭配 ProductAction 物件指定購買動作,即可評估交易。總收益、稅金和運費等交易層級詳細資料會顯示在 ProductAction 物件中。

Product product =  new Product()
    .setId("P12345")
    .setName("Android Warhol T-Shirt")
    .setCategory("Apparel/T-Shirts")
    .setBrand("Google")
    .setVariant("black")
    .setPrice(29.20)
    .setCouponCode("APPARELSALE")
    .setQuantity(1);
ProductAction productAction = new ProductAction(ProductAction.ACTION_PURCHASE)
    .setTransactionId("T12345")
    .setTransactionAffiliation("Google Store - Online")
    .setTransactionRevenue(37.39)
    .setTransactionTax(2.85)
    .setTransactionShipping(5.34)
    .setTransactionCouponCode("SUMMER2013");
HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder()
    .addProduct(product)
    .setProductAction(productAction);

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
t.setScreenName("transaction");
t.send(builder.build());

指定貨幣

根據預設,您可以透過 Google Analytics (分析) 管理網頁介面,為所有交易和項目設定通用的通用貨幣。

指定當地幣別時必須遵守 ISO 4217 標準。如需支援的轉換貨幣完整清單,請參閱貨幣代碼參考資料

系統會使用 currencyCode 追蹤器屬性指定當地幣別。舉例來說,這個追蹤器會傳送歐元值做為歐元:

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
t.setScreenName("transaction");
t.set("&cu", "EUR");  // Set tracker currency to Euros.
t.send(builder.build());

評估退款金額

如要退還整個交易的款項,請使用 setProductAction 方法搭配 ProductAction 物件,指定交易 ID 和退款動作類型:

// Refund an entire transaction.
ProductAction productAction = new ProductAction(ProductAction.ACTION_REFUND)
    .setTransactionId("T12345");  // Transaction ID is only required field for a full refund.
HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder()
    .setProductAction(productAction);

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
t.setScreenName("refund");
t.send(builder.build());

如果系統找不到相符的交易,就不會處理退款。

如要評估部分退款,請使用 setProductAction 方法搭配 ProductAction 物件,指定要退款的交易 ID、產品 ID 和產品數量:

// Refund a single product.
Product product =  new Product()
    .setId("P12345")  // Product ID is required for partial refund.
    .setQuantity(1);  // Quanity is required for partial refund.
ProductAction productAction = new ProductAction(ProductAction.ACTION_REFUND)
    .setTransactionId("T12345");  // Transaction ID is required for partial refund.
HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder()
    .addProduct(product)
    .setProductAction(productAction);

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
t.setScreenName("refundProduct");
t.send(builder.build());

使用非互動事件退款

如果您需要使用事件傳送退款資料,且該事件不屬於一般測量的使用者行為 (也就是使用者不啟動),建議您傳送 非互動事件。這樣可以避免特定指標受到事件影響。例如:

// Refund an entire transaction.
ProductAction productAction = new ProductAction(ProductAction.ACTION_REFUND)
    .setTransactionId("T12345");
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
    .setProductAction(productAction)
    .setNonInteraction(true)
    .setCategory("Ecommerce")
    .setAction("Refund");

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
t.send(builder.build());

評估結帳程序

如要評估結帳程序的每個步驟:

  1. 加入追蹤程式碼,評估結帳程序的每個步驟。
  2. 如果適用,請加入追蹤程式碼來評估結帳選項。
  3. 您可以選擇在網頁介面的「管理」部分中設定「電子商務設定」,為結帳程序報表設定容易理解的步驟名稱。

1. 評估結帳步驟

您必須為結帳程序中的每個步驟導入對應的追蹤程式碼,才能將資料傳送至 Google Analytics (分析)。

Step 欄位

您應該在評估的每個結帳步驟中加入 step 值。系統會使用這個值,將結帳動作對應至您在「電子商務設定」中為每個步驟指定的標籤。

Option 欄位

如要在評估步驟時,取得該結帳步驟的其他資訊,您可以使用 checkout 動作設定 option 欄位,藉此擷取這項資訊。例如使用者的預設付款方式 (例如「Visa」)。

評估結帳步驟

如要評估結帳步驟,請使用含有 Product 物件的 addProduct 方法新增產品詳細資料,並搭配 ProductAction 物件使用 setProductAction 方法來表示結帳動作。在適用情況下,您也可以在結帳時設定 stepoption

以下範例說明如何使用單一產品評估結帳程序的第一個步驟,以及部分付款類型的相關資訊:

Product product =  new Product()
    .setId("P12345")
    .setName("Android Warhol T-Shirt")
    .setCategory("Apparel/T-Shirts")
    .setBrand("Google")
    .setVariant("black")
    .setPrice(29.20)
    .setQuantity(1);
// Add the step number and additional info about the checkout to the action.
ProductAction productAction = new ProductAction(ProductAction.ACTION_CHECKOUT)
    .setCheckoutStep(1)
    .setCheckoutOptions("Visa");
HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder()
    .addProduct(product)
    .setProductAction(productAction);

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
t.setScreenName("checkoutStep1");
t.send(builder.build());

2. 評估結帳選項

結帳選項可讓您評估有關結帳狀態的其他資訊。若您評估了結帳步驟,但系統顯示使用者選取的選項後,系統會顯示相同結帳步驟的其他資訊,此時這個做法就非常實用。例如,使用者選取運送方式。

如要評估結帳選項,請使用 setAction 來表示結帳選項,並加入步驟號碼和選項說明。

當使用者執行特定動作前往結帳程序的下一個步驟後,建議您評估這項動作。例如:

// (On "Next" button click.)
ProductAction productAction = new ProductAction(ProductAction.ACTION_CHECKOUT_OPTIONS)
    .setCheckoutStep(1)
    .setCheckoutOptions("FedEx");
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
    .setProductAction(productAction)
    .setCategory("Checkout")
    .setAction("Option");

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
t.send(builder.build());

// Advance to next page.

3. 結帳漏斗設定

您可以為結帳程序中的每個步驟指定用於報表的描述性名稱。如要設定這些名稱,請前往 Google Analytics (分析) 網頁介面的「管理」部分,選取資料檢視 (設定檔),然後按一下「電子商務設定」。請按照電子商務設定操作說明,為每個您想追蹤的結帳步驟加上標籤。

Google Analytics (分析) 網頁介面上「管理」區段中的「電子商務設定」。電子商務已啟用,並已新增 4 個結帳漏斗步驟標籤:1. 查看購物車,2. 收集付款資訊,3. 確認購買詳細資料,4. 收據
圖 1:電子商務設定 - 結帳漏斗

評估內部促銷活動

加強型電子商務支援評估內部促銷活動 (例如用來宣傳促銷活動的橫幅) 的曝光次數和點擊次數。

促銷活動曝光次數

系統通常會使用初始畫面檢視畫面,評估內部宣傳活動曝光次數,並使用 addPromotion 方法搭配 Promotion 物件指定促銷活動的詳細資料。例如:

Promotion promotion = new Promotion()
    .setId("PROMO_1234")
    .setName("Summer Sale")
    .setCreative("summer_banner2")
    .setPosition("banner_slot1");
HitBuilders.ScreenViewBuilder builder = new HitBuilders.ScreenViewBuilder()
    .addPromotion(promotion);

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
t.setScreenName("promotions");
t.send(builder.build());

促銷活動點擊

使用 addPromotion 方法搭配 Promotion 物件,並將 setPromotionAction 方法設為 Promotion.ACTION_CLICKPromotion.ACTION_VIEW,分別代表促銷活動的點擊或瀏覽,藉此評估內部宣傳活動的點擊次數。例如:

Promotion promotion = new Promotion()
    .setId("PROMO_1234")
    .setName("Summer Sale")
    .setCreative("summer_banner2")
    .setPosition("banner_slot1");
HitBuilders.EventBuilder builder = new HitBuilders.EventBuilder()
    .addPromotion(promotion)
    .setPromotionAction(Promotion.ACTION_CLICK)
    .setCategory("Internal Promotions")
    .setAction("click")
    .setLabel("Summer Sale");

Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
    TrackerName.APP_TRACKER);
t.send(builder.build());