Click here to see your recently viewed pages and most viewed pages.
Hide

Ecommerce Tracking - Android SDK v4

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

Overview

Ecommerce measurement allows you to send in-app purchases and sales to Google Analytics. Ecommerce data in Google Analytics is comprised of transaction and item hits, related by a shared transacation ID.

Transactions have the following fields:

Field Name Type Required Description
Transaction ID String Yes A unique ID representing the transaction. This ID should not collide with other transaction IDs.
Affiliation String Yes An entity with which the transaction should be affiliated (e.g. a particular store)
Revenue Double Yes The total revenue of a transaction, including tax and shipping
Tax Double Yes The total tax for a transaction
Shipping Double Yes The total cost of shipping for a transaction
Currency code String No The local currency of a transaction. Defaults to the currency of the view (profile) in which the transactions are being viewed.

Items have the following fields:

Field Name Type Required Description
Transaction ID String Yes The transaction ID with which the item should be associated
Name String Yes The name of the product
SKU String Yes The SKU of a product
Category String No A category to which the product belongs
Price Double Yes The price of a product
Quantity Long Yes The quantity of a product
Currency code String No The local currency of a transaction. Defaults to the currency of the view (profile) in which the transactions are reported

Ecommerce data is used primary in the following standard reports:

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

Implementation

The TransactionBuilder and ItemBuilder is used to send transaction and item data to Google Analytics. Each ecommerce field is set using helper methods. For example:

// Build the transaction.
sendDataToTwoTrackers(new HitBuilders.TransactionBuilder()
    .setTransactionId(getOrderId())
    .setAffiliation(getStoreName())
    .setRevenue(getTotalOrder())
    .setTax(getTotalTax())
    .setShipping(getShippingCost())
    .setCurrencyCode("USD")
    .build());

// Build an item.
sendDataToTwoTrackers(new HitBuilders.ItemBuilder()
    .setTransactionId(getOrderId())
    .setName(getItemName(1))
    .setSku(getItemSku(1))
    .setCategory(getItemCategory(1))
    .setPrice(getItemPrice(getView(), 1))
    .setQuantity(getItemQuantity(getView(), 1))
    .setCurrencyCode("USD")
    .build());


// Sends the ecommerce data.
private void sendDataToTwoTrackers(Map<String, String> params) {
  AnalyticsSampleApp app = ((AnalyticsSampleApp) getActivity().getApplication());
  Tracker appTracker = app.getTracker(TrackerName.APP_TRACKER);
  Tracker ecommerceTracker = app.getTracker(TrackerName.ECOMMERCE_TRACKER);
  appTracker.send(params);
  ecommerceTracker.send(params);
}

See Advanced Configuration for details on the getTracker method.

Ecommerce currency fields 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 and any associated products, set the currency code field of the transaction and item hits with the new currency code. For the complete list of supported currencies and currency codes, see the Supported Currencies Reference.