Google Analytics

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.

  1. Overview
  2. Implementation
    1. Specifying Currency
  • Related Documents

  • Platform

  • Reference: Ecommerce Learn about the ecommerce data model, measurement, and reporting options.
  • Collection

  • Web Tracking: analytics.js Using custom dimensions and metrics on the web with the analytics.js library.
  • Android SDK Measuring in-app payments and ecommerce in native Android apps with the Google Analytics SDK for Android.
  • iOS SDK Measuring in-app payments and ecommerce in native Android apps with the Google Analytics SDK for iOS.
  • Measurement Protocol Measuring ecommerce activity in almost any environment using the measurement protocol.
  • Configuration

  • Setting Global Currency (Help Center) Learn how to set the global currency of a view (profile).
  • Related Topics

  • Supported Currency Codes Learn which currency codes are supported for measuring local currencies."
More

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 Tracker Field Type Required Description
Transaction ID Fields.TRANSACTION_ID String Yes A unique ID representing the transaction. This ID should not collide with other transaction IDs.
Affiliation Fields.TRANSACTION_AFFILIATION String Yes An entity with which the transaction should be affiliated (e.g. a particular store)
Revenue Fields.TRANSACTION_REVENUE Double Yes The total revenue of a transaction, including tax and shipping
Tax Fields.TRANSACTION_TAX Double Yes The total tax for a transaction
Shipping Fields.TRANSACTION_SHIPPING Double Yes The total cost of shipping for a transaction
Currency code Fields.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 Tracker Field Type Required Description
Transaction ID Fields.TRANSACTION_ID String Yes The transaction ID with which the item should be associated
Name Fields.ITEM_NAME String Yes The name of the product
SKU Fields.ITEM_SKU String Yes The SKU of a product
Category Fields.ITEM_CATEGORY String No A category to which the product belongs
Price Fields.ITEM_PRICE Double Yes The price of a product
Quantity Fields.ITEM_QUANTITY Long Yes The quantity of a product
Currency code Fields.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.

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.