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 v3.

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 transaction ID.

Transactions have the following fields:

Field Name Tracker Field Type Required Description
Transaction ID kGAITransactionId NSString Yes A unique ID representing the transaction. This ID should not collide with other transaction IDs.
Affiliation kGAITransactionAffiliation NSString Yes An entity with which the transaction should be affiliated (e.g. a particular store)
Revenue kGAITransactionRevenue NSNumber Yes The total revenue of a transaction, including tax and shipping
Tax kGAITransactionTax NSNumber Yes The total tax for a transaction
Shipping kGAITransactionShipping NSNumber Yes The total cost of shipping for a transaction
Currency code kGAICurrencyCode NSString 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 kGAITransactionId NSString Yes The transaction ID with which the item should be associated
Name kGAIItemName NSString Yes The name of the product
SKU kGAIItemSku NSString Yes The SKU of a product
Category kGAIItemCategory NSString No A category to which the product belongs
Price kGAIItemPrice NSNumber Yes The price of a product
Quantity kGAIItemQuantity NSNumber Yes The quantity of a product
Currency code kGAICurrencyCode NSString 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 primarily in the following standard reports:

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

Implementation

Sending transaction and item data to Google Analytics requires setting the transaction and item field values on the tracker and sending them, one at a time. For example:

/*
 * Called when a purchase is processed and verified.
 */
- (void)onPurchaseCompleted {

  // Assumes a tracker has already been initialized with a property ID, otherwise
  // this call returns null.
  id tracker = [[GAI sharedInstance] defaultTracker];



  [tracker send:[[GAIDictionaryBuilder createTransactionWithId:@"0_123456"             // (NSString) Transaction ID
                                                   affiliation:@"In-app Store"         // (NSString) Affiliation
                                                       revenue:@2.16F                  // (NSNumber) Order revenue (including tax and shipping)
                                                           tax:@0.17F                  // (NSNumber) Tax
                                                      shipping:@0                      // (NSNumber) Shipping
                                                  currencyCode:@"USD"] build]];        // (NSString) Currency code


  [tracker send:[[GAIDictionaryBuilder createItemWithTransactionId:@"0_123456"         // (NSString) Transaction ID
                                                              name:@"Space Expansion"  // (NSString) Product Name
                                                               sku:@"L_789"            // (NSString) Product SKU
                                                          category:@"Game expansions"  // (NSString) Product category
                                                             price:@1.9F               // (NSNumber) Product price
                                                          quantity:@1                  // (NSInteger) Product quantity
                                                      currencyCode:@"USD"] build]];    // (NSString) Currency code

}

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.

/*
 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).
 */
- (void)onPurchaseCompleted {

  // Assumes a tracker has already been initialized with a property ID, otherwise
  // this call returns null.
  id tracker = [[GAI sharedInstance] defaultTracker];

  [tracker send:[[GAIDictionaryBuilder createTransactionWithId:@"0_123456",         // (NSString) Transaction ID, should be unique among transactions.
                                                   affiliation:@"In-app Store",     // (NSString) Affiliation
                                                       revenue:(int64_t) 2.16,      // (int64_t) Order revenue (including tax and shipping)
                                                           tax:(int64_t) 0.17,      // (int64_t) Tax
                                                      shipping:(int64_t) 0,         // (int64_t) Shipping
                                                  currencyCode:@"EUR"] build]];     // (NSString) Currency code
}