Ecommerce Tracking - iOS SDK

This document provides an overview of how to measure in-app payments and revenue using the Google Analytics SDK for iOS 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 iOS, 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:.

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

- (void)onPurchaseCompleted {
  GAITransaction *transaction =
      [GAITransaction transactionWithId:@"0_123456"            // (NSString) Transaction ID, should be unique.
                        withAffiliation:@"In-App Store"];      // (NSString) Affiliation
  transaction.taxMicros = (int64_t)(0.17 * 1000000);           // (int64_t) Total tax (in micros)
  transaction.shippingMicros = (int64_t)(0);                   // (int64_t) Total shipping (in micros)
  transaction.revenueMicros = (int64_t)(2.16 * 1000000);       // (int64_t) Total revenue (in micros)

  [transaction addItemWithSKU:@"L_789"                         // (NSString) Product SKU
                         name:@"Level Pack: Space"             // (NSString) Product name
                     category:@"Game expansions"               // (NSString) Product category
                  priceMicros:(int64_t)(1.99 * 1000000)        // (int64_t)  Product price (in micros)
                     quantity:1];                              // (NSInteger)  Product quantity

  [[GAI sharedInstance].defaultTracker sendTransaction:transaction]; // Send the transaction.

Currency Types

In the Google Analytics SDK for iOS, 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.