전자상거래 추적 - Android SDK v2 (기존)

이 문서에서는 Android v2용 Google 애널리틱스 SDK를 사용하여 인앱 결제와 수익을 측정하는 방법을 간략하게 설명합니다.

개요

전자상거래 측정을 사용하면 인앱 구매 및 판매를 Google 애널리틱스로 전송할 수 있습니다. Google 애널리틱스의 전자상거래 데이터는 일반적으로 공유된 거래 ID와 관련된 거래와 항목으로 구성됩니다. Android용 Google 애널리틱스 SDK에서는 거래 객체를 만들고 여기에 항목을 추가하여 관계를 설정합니다.

전자상거래 데이터는 다음 보고서에서 기본으로 사용됩니다.

  • 전자상거래 개요
  • 제품 실적
  • 매출 실적
  • 거래
  • 구매까지의 소요 시간

구현

Google 애널리틱스로 거래를 측정하는 3단계는 다음과 같습니다.

  1. 트랜잭션 객체를 빌드합니다.
  2. 항목 객체를 빌드하고 거래 객체에 추가합니다.
  3. sendTransaction(Transaction transObject)를 사용하여 거래를 전송합니다.

다음 예에서는 사용자가 인앱 구매를 완료한 후에 onPurchaseCompleted()가 호출된다고 가정합니다.

/**
 * The purchase was processed. We will send the transaction and its associated line items to Google Analytics,
 * but only if the purchase has been confirmed.
 */
public void onPurchaseCompleted() {
  Transaction myTrans = new Transaction.Builder(
      "0_123456",                                           // (String) Transaction Id, should be unique.
      (long) (2.16 * 1000000))                              // (long) Order total (in micros)
      .setAffiliation("In-App Store")                       // (String) Affiliation
      .setTotalTaxInMicros((long) (0.17 * 1000000))         // (long) Total tax (in micros)
      .setShippingCostInMicros(0)                           // (long) Total shipping cost (in micros)
      .build();

  myTrans.addItem(new Item.Builder(
      "L_789",                                              // (String) Product SKU
      "Level Pack: Space",                                  // (String) Product name
      (long) (1.99 * 1000000),                              // (long) Product price (in micros)
      (long) 1)                                             // (long) Product quantity
      .setProductCategory("Game expansions")                // (String) Product category
      .build());

    Tracker myTracker = EasyTracker.getTracker(); // Get reference to tracker.
    myTracker.sendTransaction(myTrans); // Send the transaction.
}

통화 유형

Android용 Google 애널리틱스 SDK에서 전자상거래 통화 필드는 마이크로 (단위: 백만분의 일) 단위로 입력해야 합니다.

예를 들어 4.5991의 통화 값을 전송하려면 위의 예와 같이 Google 애널리틱스로 거래를 전송할 때 값을 마이크로 (예: 4599100)로 변환해야 합니다. SDK가 거래를 Google 애널리틱스로 전달하면 이 값은 고정 소수점 십진수 값으로 자동 변환되고 4.5991로 전송됩니다.

전자상거래 코드에 통화 기호를 포함하거나 쉼표를 사용해서는 안 됩니다.

전자상거래 통화 필드는 환불 또는 반품의 경우 필요한 음의 통화 값도 지원합니다.

통화 지정

기본적으로 거래 금액은 보고되는 보기 (프로필)의 통화로 간주됩니다.

거래의 현지 통화를 재정의하려면 다음 예와 같이 Transaction를 빌드할 때 setCurrencyCode를 호출합니다.

/**
 * In this example, the currency of the transaction is set to Euros. The
 * currency values will appear in reports using the global currency
 * type of the view (profile).
 */
public void onPurchaseCompleted() {
  Transaction myTrans = new Transaction.Builder(
      "0_123456",
      (long) (1.59 * 1000000))
      .setAffiliation("In-App Store")
      .setTotalTaxInMicros((long) (0.13 * 1000000))
      .setShippingCostInMicros(0)
      .setCurrencyCode("EUR")                               // (String) Set currency code to Euros.
      .build();

    Tracker myTracker = EasyTracker.getTracker();
    myTracker.sendTransaction(myTrans);
}

지원되는 통화 및 통화 코드의 전체 목록은 지원되는 통화 참조를 참고하세요.