Ecommerce Tracking - Android SDK v2 (Legacy)

This document provides an overview of how to measure in-app payments and revenue using the Google Analytics SDK for Android v2.


Ecommerce measurement allows you to send in-app purchases and sales to Google Analytics. Ecommerce data in Google Analytics is generally comprised of transactions and items, related by a shared transacation ID. In the Google Analytics SDK for Android , that relationship is established by creating a transaction object and adding items to it.

Ecommerce data is used primary in the following reports:

  • Ecommerce Overview
  • Product Performance
  • Sales Performance
  • Transactions
  • Time to Purchase


There are three steps to measure a transaction with Google Analytics:

  1. Build a transaction object.
  2. Build item objects and add them to the transaction object.
  3. Send the transaction using sendTransaction(Transaction transObject) .

In the following example, we assume that onPurchaseCompleted() is called after the user has completed an in-app purchase.

 * 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)

  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

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

Currency Types

In the Google Analytics SDK for Android , Ecommerce currency fields must be in micros (millionths of currency).

For example, to send a currency value of 4.5991, you should convert that value to micros (i.e. 4599100) when you send the transaction to Google Analytics, as in the examples above. When the SDK dispatches that transaction to Google Analytics, that value is automatically converted into a fixed-point decimal value and sent as 4.5991.

Currency symbols should not be included in your Ecommerce code, nor should commas be used.

Ecommerce currency fields also support negative currency values, as may be necessary in the case of refunds or returns.

Specifying Currencies

By default, transaction values are assumed to be in the currency of the view (profile) in which they are reported.

To override the local currency of a transaction, call setCurrencyCode when building a Transaction as in the following example:

 * 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(
      (long) (1.59 * 1000000))
      .setAffiliation("In-App Store")
      .setTotalTaxInMicros((long) (0.13 * 1000000))
      .setCurrencyCode("EUR")                               // (String) Set currency code to Euros.

    Tracker myTracker = EasyTracker.getTracker();

For the complete list of supported currencies and currency codes, see the Supported Currencies Reference.