작업은 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 애널리틱스 관리 웹 인터페이스를 통해 모든 거래
및 상품에 대해 공통된 전체 통화를 구성할 수 있습니다.
현지 통화는 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. 결제 단계 측정
결제 절차의 각 단계에 대해 해당하는 추적 코드를 구현하여 Google 애널리틱스로 데이터를 전송해야 합니다.
Step 필드
측정하는 각 결제 단계에 대해 step 값을 포함해야 합니다. 이 값은 결제 작업을 전자상거래 설정의 각 단계에
대해 구성한 라벨에 매핑하는 데 사용됩니다.
Option 필드
단계가 측정되는 시점에 지정된 결제 단계에 대한
추가 정보가 있는 경우 checkout 작업으로 option
필드를 설정하여 이 정보를 캡처할 수 있습니다. 예를 들어 사용자의 기본 결제 유형 (예: 'Visa')이 있습니다.
결제 단계 측정
결제 단계를 측정하려면 addProduct 메서드를 Product 객체와 함께 사용하여
setProductAction 메서드를 ProductAction 객체와 함께 추가하고
결제 작업을 나타냅니다. 해당하는 경우 결제 시 step 및 option를
설정할 수도 있습니다.
다음 예에서는 단일 제품으로
결제 절차의 첫 번째 단계를 측정하는 방법 및 결제 유형에 대한
추가 정보를 보여줍니다.
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 애널리틱스 웹 인터페이스의
관리 섹션으로 이동하여 보기 (프로필)를 선택하고
전자상거래 설정을 클릭합니다. 전자상거래 설정 안내에 따라 추적할 각 결제 단계에 라벨을 지정합니다.
그림 1: 전자상거래 설정 - 결제 유입경로
내부 프로모션 측정
향상된 전자상거래에는 판매를 촉진하기 위해 표시되는 배너와 같은 내부 프로모션의 노출수와 클릭수를 측정하는 기능이 포함됩니다.
프로모션 노출수
내부 프로모션 노출수는 일반적으로 Promotion 객체와 함께 addPromotion 메서드를 사용하여 프로모션 세부정보를 지정하기 위해 초기 화면 조회수로 측정됩니다. 예를 들면 다음과 같습니다.
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());
프로모션 클릭수
내부 프로모션 클릭수는 Promotion
객체와 함께 addPromotion 메서드를 사용하고
setPromotionAction 메서드를 Promotion.ACTION_CLICK 또는 Promotion.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());
샘플 애플리케이션의 코드 스니펫 보기
다음 스니펫은 향상된 전자상거래의 전체 예시를 보여줍니다.
package com.google.android.apps.mobileplayground;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import com.google.android.apps.mobileplayground.AnalyticsSampleApp.TrackerName;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import com.google.android.gms.analytics.ecommerce.Product;
import com.google.android.gms.analytics.ecommerce.ProductAction;
import com.google.android.gms.analytics.ecommerce.Promotion;
/**
* Class to exercise Enhanced Ecommerce hits.
*/
public class EnhancedEcommerceFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = inflater.inflate(R.layout.enhanced_ecommerce, container, false);
Button button = (Button) view.findViewById(R.id.enhancedEcommerceImpression);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
measureImpression();
}
});
button = (Button) view.findViewById(R.id.enhancedEcommerceAction);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
measureAction();
}
});
button = (Button) view.findViewById(R.id.enhancedEcommerceImpressionAndAction);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
measureImpressionAndAction();
}
});
button = (Button) view.findViewById(R.id.enhancedEcommerceTransaction);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
measureTransaction();
}
});
button = (Button) view.findViewById(R.id.enhancedEcommerceRefundTransaction);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
measureRefundTransaction();
}
});
button = (Button) view.findViewById(R.id.enhancedEcommerceRefundProduct);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
measureRefundProduct();
}
});
button = (Button) view.findViewById(R.id.enhancedEcommerceRefundNonInteraction);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
measureRefundNonInteraction();
}
});
button = (Button) view.findViewById(R.id.enhancedEcommerceCheckoutStep);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
measureCheckoutStep();
}
});
button = (Button) view.findViewById(R.id.enhancedEcommerceCheckoutOption);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
measureCheckoutOption();
}
});
button = (Button) view.findViewById(R.id.enhancedEcommercePromotionImpression);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
measurePromotionImpression();
}
});
button = (Button) view.findViewById(R.id.enhancedEcommercePromotionClick);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
measurePromotionClick();
}
});
return view;
}
private void measureImpression() {
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());
}
private void measureAction() {
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());
}
private void measureImpressionAndAction() {
// 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());
}
private void measureTransaction() {
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());
}
private void measureRefundTransaction() {
// 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());
}
private void measureRefundProduct() {
// 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());
}
private void measureRefundNonInteraction() {
// 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());
}
private void measureCheckoutStep() {
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());
}
private void measureCheckoutOption() {
// (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.
}
private void measurePromotionImpression() {
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());
}
private void measurePromotionClick() {
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());
}
}