Google Analytics supports enhanced ecommerce in Universal Analytics properties. Enhanced ecommerce enables measurement of user interactions with products across the user's shopping experience. This can include promotion impressions, promotion clicks, product impressions, product clicks, views of product details, adding items to a shopping cart, removing items from a shopping cart, initiating checkouts, transactions, and refunds.
The latest versions of Google Tag Manager and Google Analytics for mobile apps work in conjunction with Firebase, Google’s mobile app platform. When measuring apps with the Firebase SDK, you’ll have access to a host of automatically generated mobile app reports, which can be further customized and supplemented by in-app code. These reports will automatically include data on in-app purchases processed by the App Store on iTunes and Google Play. Additional ecommerce-related reports can be generated by implementing suggested events for ecommerce apps. In-depth reports on shopping behavior (i.e. enhanced ecommerce) are currently only available in Universal Analytics properties.
This document describes how to use Tag Manager for mobile apps with the Firebase SDK to send enhanced ecommerce data to Universal Analytics properties.
First steps
Before getting started, set up the following prerequisites for your app:
- Install and configure Firebase and Google Tag Manager in your app. Ensure that you are using version 11 or higher of the Firebase SDK for Android.
Import these two packages:
import com.google.firebase.analytics.FirebaseAnalytics.Event;
import com.google.firebase.analytics.FirebaseAnalytics.Param;
In your Tag Manager container, create a user-defined variable called "promotions" with the following settings:
- Event Type: Custom Parameter
- Event Parameter Key: promotions
- Default Value: undefined
Implementation
The following sections demonstrate how to log events with the parameters necessary to measure enhanced ecommerce activities such as:
- Product impressions
- Product clicks/selections
- Product detail views
- Additions to cart
- Removals from cart
- Promotion impressions
- Promotion clicks/selections
- Checkout process
- Purchases
- Refunds
Product Impressions
Measure product impressions by logging event with an ITEM_LIST
parameter and
one or more items (i.e. products) defined with the relevant fields.
// Define products with relevant parameters
Bundle product1 = new Bundle();
product1.putString( Param.ITEM_ID, "sku1234"); // ITEM_ID or ITEM_NAME is required
product1.putString( Param.ITEM_NAME, "Donut Friday Scented T-Shirt");
product1.putString( Param.ITEM_CATEGORY, "Apparel/Men/Shirts");
product1.putString( Param.ITEM_VARIANT, "Blue");
product1.putString( Param.ITEM_BRAND, "Google");
product1.putDouble( Param.PRICE, 29.99 );
product1.putString( Param.CURRENCY, "USD" );
product1.putLong( Param.INDEX, 1 ); // Position of the item in the list
Bundle product2 = new Bundle();
product2.putString( Param.ITEM_ID, "sku5678");
product2.putString( Param.ITEM_NAME, "Android Workout Capris");
product2.putString( Param.ITEM_CATEGORY, "Apparel/Women/Pants");
product2.putString( Param.ITEM_VARIANT, "Black");
product2.putString( Param.ITEM_BRAND, "Google");
product2.putDouble( Param.PRICE, 39.99 );
product2.putString( Param.CURRENCY, "USD" );
product2.putLong( Param.INDEX, 2 );
// Prepare ecommerce bundle
ArrayList <bundle>items = new ArrayList<bundle>();
items.add(product1);
items.add(product2);
Bundle ecommerceBundle = new Bundle();
ecommerceBundle.putParcelableArrayList( "items", items );
// Set relevant bundle-level parameters
ecommerceBundle.putString( Param.ITEM_LIST, "Search Results" ); // List name
// Log view_search_results or view_item_list event with ecommerce bundle
mFirebaseAnalytics.logEvent( Event.VIEW_SEARCH_RESULTS, ecommerceBundle );
See the tag configuration for this example:
- Tag Type: Universal Analytics
- Track Type: Screen View
- Fields to Set: (Field Name) screenName (value, e.g.) Search Results Screen
- Enable Enhanced Ecommerce Features: True
- Read data from: Firebase Event
- Trigger, e.g.: (Custom > Some Events) Event Name equals view_search_results
Product clicks/selections
Measure product clicks by logging a SELECT_CONTENT
event with an item (i.e.
product) defined with the relevant fields:
// Define product with relevant parameters
Bundle product1 = new Bundle();
product1.putString( Param.ITEM_ID, "sku1234"); // ITEM_ID or ITEM_NAME is required
product1.putString( Param.ITEM_NAME, "Donut Friday Scented T-Shirt");
product1.putString( Param.ITEM_CATEGORY, "Apparel/Men/Shirts");
product1.putString( Param.ITEM_VARIANT, "Blue");
product1.putString( Param.ITEM_BRAND, "Google");
product1.putDouble( Param.PRICE, 29.99 );
product1.putString( Param.CURRENCY, "USD" ); // Item-level currency unused today
product1.putLong( Param.INDEX, 1 ); // Position of the item in the list
// Prepare ecommerce bundle
Bundle ecommerceBundle = new Bundle();
ecommerceBundle.putBundle( "items", product1 );
// Set relevant action-level parameters
ecommerceBundle.putString( Param.ITEM_LIST, "Search Results" ); // Optional list name
// Log select_content event with ecommerce bundle
mFirebaseAnalytics.logEvent( Event.SELECT_CONTENT, ecommerceBundle );
See the tag configuration for this example:
- Tag Type: Universal Analytics
- Track Type: Event
- Event Category, e.g.: Ecommerce
- Event Action, e.g. : Product Click
- Enable Enhanced Ecommerce Features: True
- Read data from: Firebase Event
- Trigger, e.g.: (Custom > Some Events) Event Name equals select_content AND {{promotions}} equals undefined
Product detail views
Measure product detail views by logging a VIEW_ITEM
event with an item (i.e.
product) defined with the relevant fields:
// Define product with relevant parameters
Bundle product1 = new Bundle();
product1.putString( Param.ITEM_ID, "sku1234"); // ITEM_ID or ITEM_NAME is required
product1.putString( Param.ITEM_NAME, "Donut Friday Scented T-Shirt");
product1.putString( Param.ITEM_CATEGORY, "Apparel/Men/Shirts");
product1.putString( Param.ITEM_VARIANT, "Blue");
product1.putString( Param.ITEM_BRAND, "Google");
product1.putDouble( Param.PRICE, 29.99 );
product1.putString( Param.CURRENCY, "USD" ); // Item-level currency unused today
// Prepare ecommerce bundle
Bundle ecommerceBundle = new Bundle();
ecommerceBundle.putBundle( "items", product1 );
// Log view_item event with ecommerce bundle
mFirebaseAnalytics.logEvent( Event.VIEW_ITEM, ecommerceBundle );
See the tag configuration for this example:
- Tag Type: Universal Analytics
- Track Type: Screen View
- Fields to Set: (Field Name) screenName (value, e.g.) Product Details Screen
- Enable Enhanced Ecommerce Features: True
- Read data from: Firebase Event
- Trigger, e.g.: (Custom > Some Events) Event Name equals view_item AND
- {{promotions}} equals undefined
Additions to cart
Measure a product being added to a shopping cart by logging an ADD_TO_CART
event with an item (i.e. product) defined with the relevant fields:
// Define product with relevant parameters
Bundle product1 = new Bundle();
product1.putString( Param.ITEM_ID, "sku1234"); // ITEM_ID or ITEM_NAME is required
product1.putString( Param.ITEM_NAME, "Donut Friday Scented T-Shirt");
product1.putString( Param.ITEM_CATEGORY, "Apparel/Men/Shirts");
product1.putString( Param.ITEM_VARIANT, "Blue");
product1.putString( Param.ITEM_BRAND, "Google");
product1.putDouble( Param.PRICE, 29.99 );
product1.putString( Param.CURRENCY, "USD" ); // Item-level currency unused today
product1.putLong( Param.QUANTITY, 1 );
// Prepare ecommerce bundle
Bundle ecommerceBundle = new Bundle();
ecommerceBundle.putBundle( "items", product1 );
// Log add_to_cart event with ecommerce bundle
mFirebaseAnalytics.logEvent( Event.ADD_TO_CART, ecommerceBundle );
See the tag configuration for this example:
- Tag Type: Universal Analytics
- Track Type: Event
- Event Category, e.g.: Ecommerce
- Event Action, e.g. : Add to Cart
- Enable Enhanced Ecommerce Features: True
- Read data from: Firebase Event
- Trigger, e.g.: (Custom > Some Events) Event Name equals add_to_cart
Removals from cart
Measure a product being removed from a shopping cart by logging a
REMOVE_FROM_CART
event with an item (i.e. product) defined with the relevant
fields:
// Define product with relevant parameters
Bundle product1 = new Bundle();
product1.putString( Param.ITEM_ID, "sku1234"); // ITEM_ID or ITEM_NAME is required
product1.putString( Param.ITEM_NAME, "Donut Friday Scented T-Shirt");
product1.putString( Param.ITEM_CATEGORY, "Apparel/Men/Shirts");
product1.putString( Param.ITEM_VARIANT, "Blue");
product1.putString( Param.ITEM_BRAND, "Google");
product1.putDouble( Param.PRICE, 29.99 );
product1.putString( Param.CURRENCY, "USD" ); // Item-level currency unused today
product1.putLong( Param.QUANTITY, 1 );
// Prepare ecommerce bundle
Bundle ecommerceBundle = new Bundle();
ecommerceBundle.putBundle( "items", product1 );
// Log remove_from_cart event with ecommerce bundle
mFirebaseAnalytics.logEvent( Event.REMOVE_FROM_CART, ecommerceBundle );
See the tag configuration for this example:
- Tag Type: Universal Analytics
- Track Type: Event
- Event Category, e.g.: Ecommerce
- Event Action, e.g. : Remove from Cart
- Enable Enhanced Ecommerce Features: True
- Read data from: Firebase Event
- Trigger, e.g.: (Custom > Some Events) Event Name equals remove_from_cart
Promotion impressions
Measure promotion impressions by logging a VIEW_ITEM
, VIEW_ITEM_LIST
, or
VIEW_SEARCH_RESULTS
event with a promotion item defined with the relevant
fields:
// Define promotion with relevant parameters
Bundle promotion = new Bundle();
promotion.putString( Param.ITEM_ID, "PROMO_1234" ); // promotion ID; either ITEM_ID or ITEM_NAME is required
promotion.putString( Param.ITEM_NAME, "Summer Sale" ); // promotion name
promotion.putString( Param.CREATIVE_NAME, "summer_banner2" );
promotion.putString( Param.CREATIVE_SLOT, "banner_slot1" );
// Prepare ecommerce bundle
ArrayList <bundle>promotions = new ArrayList<bundle>();
promotions.add(promotion);
Bundle ecommerceBundle = new Bundle();
ecommerceBundle.putParcelableArrayList("promotions", promotions );
// Log view_item, view_item_list, or view_search_results event with ecommerce bundle
mFirebaseAnalytics.logEvent(Event.VIEW_ITEM, ecommerceBundle );
See the tag configuration for this example:
- Tag Type: Universal Analytics
- Track Type: Event
- Event Category, e.g.: Internal Promotion
- Event Action, e.g.: Impression
- Non-Interaction Hit: True
- Enable Enhanced Ecommerce Features: True
- Read data from: Firebase Event
- Trigger, e.g.: (Custom > Some Events) Event Name equals view_item AND
- {{promotions}} does not equal undefined
Promotion clicks/selections
Measure promotion clicks by logging a SELECT_CONTENT
event with a promotion
defined with the relevant fields:
// Define promotion with relevant parameters
Bundle promotion = new Bundle();
promotion.putString( Param.ITEM_ID, "PROMO_1234"); // promotion ID; either ITEM_ID or ITEM_NAME is required
promotion.putString( Param.ITEM_NAME, "Summer Sale"); // promotion name
promotion.putString( Param.CREATIVE_NAME, "summer_banner2");
promotion.putString( Param.CREATIVE_SLOT, "banner_slot1");
// Prepare ecommerce bundle
ArrayList <bundle>promotions = new ArrayList<bundle>();
promotions.add(promotion);
Bundle ecommerceBundle = new Bundle();
ecommerceBundle.putParcelableArrayList("promotions", promotions );
// Set properties for the event to be shown in the Google Analytics (Firebase) reports.
// These properties will not impact the Universal Analytics reporting.
ecommerceBundle.putString( Param.CONTENT_TYPE, “Internal Promotions” );
ecommerceBundle.putString( Param.ITEM_ID, "PROMO_1234" );
// Log select_content, view_item_list, or view_search_results event with ecommerce bundle
mFirebaseAnalytics.logEvent( Event.SELECT_CONTENT, ecommerceBundle );
See the tag configuration for this example:
- Tag Type: Universal Analytics
- Track Type: Event
- Event Category, e.g.: Internal Promotion
- Event Action, e.g. : Click
- Enable Enhanced Ecommerce Features: True
- Read data from: Firebase Event
- Trigger, e.g.: (Custom > Some Events) Event Name equals select_content AND {{promotions}} does not equal undefined
Checkout process
Begin checkout
Measure the first step in a checkout process by logging a BEGIN_CHECKOUT
event
with one or more items (i.e. products) defined with the relevant fields:
// Define products with relevant parameters
Bundle product1 = new Bundle();
product1.putString( Param.ITEM_ID, "sku1234"); // ITEM_ID or ITEM_NAME is required
product1.putString( Param.ITEM_NAME, "Donut Friday Scented T-Shirt");
product1.putString( Param.ITEM_CATEGORY, "Apparel/Men/Shirts");
product1.putString( Param.ITEM_VARIANT, "Blue");
product1.putString( Param.ITEM_BRAND, "Google");
product1.putDouble( Param.PRICE, 29.99 );
product1.putString( Param.CURRENCY, "USD" ); // Item-level currency unused today
product1.putLong( Param.QUANTITY, 1 );
// Prepare ecommerce bundle
ArrayList <bundle>items = new ArrayList<bundle>();
items.add(product1);
Bundle ecommerceBundle = new Bundle();
ecommerceBundle.putParcelableArrayList( "items", items );
// Set checkout step and optional checkout option
ecommerceBundle.putLong( Param.CHECKOUT_STEP, 1 ); // Optional for first step
ecommerceBundle.putString( Param.CHECKOUT_OPTION, "Visa" ); // Optional
// Log BEGIN_CHECKOUT event with ecommerce bundle
mFirebaseAnalytics.logEvent( Event.BEGIN_CHECKOUT, ecommerceBundle );
See the tag configuration for this example:
- Tag Type: Universal Analytics
- Track Type: Screen View
- Fields to Set: (Field Name) screenName (value, e.g.) Cart Screen
- Enable Enhanced Ecommerce Features: True
- Read data from: Firebase Event
- Trigger, e.g.: (Custom > Some Events) Event Name equals begin_checkout
Additional checkout steps
Measure additional steps in a checkout process by logging a CHECKOUT_PROGRESS
event with one or more items (i.e. products) defined with the relevant fields:
// Define products with relevant parameters
Bundle product1 = new Bundle();
product1.putString( Param.ITEM_ID, "sku1234"); // ITEM_ID or ITEM_NAME is required
product1.putString( Param.ITEM_NAME, "Donut Friday Scented T-Shirt");
product1.putString( Param.ITEM_CATEGORY, "Apparel/Men/Shirts");
product1.putString( Param.ITEM_VARIANT, "Blue");
product1.putString( Param.ITEM_BRAND, "Google");
product1.putDouble( Param.PRICE, 29.99 );
product1.putString( Param.CURRENCY, "USD" ); // Item-level currency unused today
product1.putLong( Param.QUANTITY, 1 );
// Prepare ecommerce bundle
ArrayList <bundle>items = new ArrayList<bundle>();
items.add(product1);
Bundle ecommerceBundle = new Bundle();
ecommerceBundle.putParcelableArrayList( "items", items );
// Set checkout step and optional checkout option
ecommerceBundle.putLong( Param.CHECKOUT_STEP, 2 );
ecommerceBundle.putString( Param.CHECKOUT_OPTION, "Visa" ); // Optional
// Log CHECKOUT_PROGRESS event with ecommerce bundle
mFirebaseAnalytics.logEvent( Event.CHECKOUT_PROGRESS, ecommerceBundle );
See the tag configuration for this example:
- Tag Type: Universal Analytics
- Track Type: Screen View
- Fields to Set: (Field Name) screenName (value, e.g.) Checkout Step 2 Screen
- Enable Enhanced Ecommerce Features: True
- Read data from: Firebase Event
- Trigger, e.g.: (Custom > Some Events) Event Name equals checkout_progress
Checkout options
Checkout options allow you to measure additional information about the state of the checkout process. You can either measure checkout options either as part of a checkout step event (as shown above) or upon a user selecting an option after the event for a given checkout step has already been logged.
Measure checkout options after a checkout step by logging a
SET_CHECKOUT_OPTION
event with the corresponding CHECKOUT_STEP
and
CHECKOUT_OPTION
parameters:
Bundle ecommerceBundle = new Bundle();
ecommerceBundle.putLong( Param.CHECKOUT_STEP, 2 );
ecommerceBundle.putString( Param.CHECKOUT_OPTION, "Mastercard" );
mFirebaseAnalytics.logEvent( Event.SET_CHECKOUT_OPTION, ecommerceBundle );
See the tag configuration for this example:
- Tag Type: Universal Analytics
- Track Type: Event
- Event Category, e.g.: Ecommerce
- Event Action, e.g. : Set Checkout Option
- Enable Enhanced Ecommerce Features: True
- Read data from: Firebase Event
- Trigger, e.g.: (Custom > Some Events) Event Name equals set_checkout_option
Purchases
Measure purchases by logging an ECOMMERCE_PURCHASE
event with one or more
items (i.e. products) defined with the relevant fields:
// Define product with relevant parameters
Bundle product1 = new Bundle();
product1.putString( Param.ITEM_ID, "sku1234"); // ITEM_ID or ITEM_NAME is required
product1.putString( Param.ITEM_NAME, "Donut Friday Scented T-Shirt");
product1.putString( Param.ITEM_CATEGORY, "Apparel/Men/Shirts");
product1.putString( Param.ITEM_VARIANT, "Blue");
product1.putString( Param.ITEM_BRAND, "Google");
product1.putDouble( Param.PRICE, 29.99 );
product1.putString( Param.CURRENCY, "USD" ); // Item-level currency unused today
product1.putLong( Param.QUANTITY, 1 );
Bundle product2 = new Bundle();
product2.putString( Param.ITEM_ID, "sku5678");
product2.putString( Param.ITEM_NAME, "Android Workout Capris");
product2.putString( Param.ITEM_CATEGORY, "Apparel/Women/Pants");
product2.putString( Param.ITEM_VARIANT, "Black");
product2.putString( Param.ITEM_BRAND, "Google");
product2.putDouble( Param.PRICE, 39.99 );
product2.putString( Param.CURRENCY, "USD" ); // Item-level currency unused today
product2.putLong( Param.QUANTITY, 1 );
// Prepare ecommerce bundle
ArrayList <bundle>items = new ArrayList<bundle>();
items.add(product1);
items.add(product2);
Bundle ecommerceBundle = new Bundle();
ecommerceBundle.putParcelableArrayList( "items", items );
// Set relevant transaction-level parameters
ecommerceBundle.putString( Param.TRANSACTION_ID, "T12345" );
ecommerceBundle.putString( Param.AFFILIATION, "Google Store - Online" );
ecommerceBundle.putDouble( Param.VALUE, 37.39 ); // Revenue
ecommerceBundle.putDouble( Param.TAX, 2.85 );
ecommerceBundle.putDouble( Param.SHIPPING, 5.34 );
ecommerceBundle.putString( Param.CURRENCY, "USD" );
ecommerceBundle.putString( Param.COUPON, "SUMMER2017" );
// Log ecommerce_purchase event with ecommerce bundle
mFirebaseAnalytics.logEvent( Event.ECOMMERCE_PURCHASE, ecommerceBundle );
See the tag configuration for this example:
- Tag Type: Universal Analytics
- Track Type: Screen View
- Fields to Set: (Field Name) screenName (value, e.g.) Thank You Screen
- Enable Enhanced Ecommerce Features: True
- Read data from: Firebase Event
- Trigger, e.g.: (Custom > Some Events) Event Name equals ecommerce_purchase
Refunds
Measure refunds by logging a PURCHASE_REFUND
event with the relevant
transaction ID specified, and optionally (for partial refunds) one or more items
(i.e. products) defined with item IDs and quantities:
// Prepare ecommerce bundle with transaction ID to be refunded
Bundle ecommerceBundle = new Bundle();
ecommerceBundle.putString( Param.TRANSACTION_ID, "T12345" ); // Required
ecommerceBundle.putDouble( Param.VALUE, 37.39 ); // Optional in Universal Analytics
// (OPTIONAL) For partial refunds, define the item IDs and quantities of products being refunded
Bundle refundedProduct = new Bundle();
refundedProduct.putString( Param.ITEM_ID, "sku1234" ); // Required for partial refund
refundedProduct.putLong( Param.QUANTITY, 1 ); // Required for partial refund
ArrayList <bundle>items = new ArrayList<bundle>();
items.add(refundedProduct);
ecommerceBundle.putParcelableArrayList( "items", items );
// Log purchase_refund event with ecommerce bundle
mFirebaseAnalytics.logEvent( Event.PURCHASE_REFUND, ecommerceBundle );
See the tag configuration for this example:
- Tag Type: Universal Analytics
- Track Type: Event
- Event Category, e.g.: Ecommerce
- Event Action, e.g. : Refund
- Enable Enhanced Ecommerce Features: True
- Read data from: Firebase Event
- Trigger, e.g.: (Custom > Some Events) Event Name equals purchase_refund