Measure ecommerce

Ecommerce allows measurement of user interactions with products across your users' shopping experiences, including interactions such as product (item) list views, product list clicks, viewing product details, adding a product to a shopping cart, initiating the checkout process, purchases, and refunds.

For details on implementing ecommerce web apps, see Google Analytics Ecommerce.

Before you begin

Make sure that you’ve set up your project and can access Analytics as described in Get Started with Analytics. Ecommerce measurement requires you to link your Firebase project to an Analytics account and to have the Android SDK v17.3.0 or iOS v6.20.0 and up in your app.

Implementation

A typical ecommerce implementation measures any of the following actions:

At the heart of these actions are products. Products can be instrumented as an array of items that can be added to prescribed ecommerce events.

Note the following limits:

  • An array of items can include up to 27 custom parameters, in addition to the prescribed parameters.

  • A single ecommerce event can include up to 200 items. If you try to send more than 200 items, any items beyond this limit will be dropped and not included in the event data.

The following example demonstrates how to create an array of items that is referenced throughout this guide.

Swift

Note: This Firebase product is not available on the macOS target.
// A pair of jeggings
varjeggings:[String:Any]=[
AnalyticsParameterItemID:"SKU_123",
AnalyticsParameterItemName:"jeggings",
AnalyticsParameterItemCategory:"pants",
AnalyticsParameterItemVariant:"black",
AnalyticsParameterItemBrand:"Google",
AnalyticsParameterPrice:9.99,
]
// A pair of boots
varboots:[String:Any]=[
AnalyticsParameterItemID:"SKU_456",
AnalyticsParameterItemName:"boots",
AnalyticsParameterItemCategory:"shoes",
AnalyticsParameterItemVariant:"brown",
AnalyticsParameterItemBrand:"Google",
AnalyticsParameterPrice:24.99,
]
// A pair of socks
varsocks:[String:Any]=[
AnalyticsParameterItemID:"SKU_789",
AnalyticsParameterItemName:"ankle_socks",
AnalyticsParameterItemCategory:"socks",
AnalyticsParameterItemVariant:"red",
AnalyticsParameterItemBrand:"Google",
AnalyticsParameterPrice:5.99,
]

Objective-C

Note: This Firebase product is not available on the macOS target.
// A pair of jeggings
NSMutableDictionary*jeggings=[@{
kFIRParameterItemID:@"SKU_123",
kFIRParameterItemName:@"jeggings",
kFIRParameterItemCategory:@"pants",
kFIRParameterItemVariant:@"black",
kFIRParameterItemBrand:@"Google",
kFIRParameterPrice:@9.99,
}mutableCopy];
// A pair of boots
NSMutableDictionary*boots=[@{
kFIRParameterItemID:@"SKU_456",
kFIRParameterItemName:@"boots",
kFIRParameterItemCategory:@"shoes",
kFIRParameterItemVariant:@"brown",
kFIRParameterItemBrand:@"Google",
kFIRParameterPrice:@24.99,
}mutableCopy];
// A pair of socks
NSMutableDictionary*socks=[@{
kFIRParameterItemID:@"SKU_789",
kFIRParameterItemName:@"ankle_socks",
kFIRParameterItemCategory:@"socks",
kFIRParameterItemVariant:@"red",
kFIRParameterItemBrand:@"Google",
kFIRParameterPrice:@5.99,
}mutableCopy];

Kotlin

valitemJeggings=Bundle().apply{
putString(FirebaseAnalytics.Param.ITEM_ID,"SKU_123")
putString(FirebaseAnalytics.Param.ITEM_NAME,"jeggings")
putString(FirebaseAnalytics.Param.ITEM_CATEGORY,"pants")
putString(FirebaseAnalytics.Param.ITEM_VARIANT,"black")
putString(FirebaseAnalytics.Param.ITEM_BRAND,"Google")
putDouble(FirebaseAnalytics.Param.PRICE,9.99)
}
valitemBoots=Bundle().apply{
putString(FirebaseAnalytics.Param.ITEM_ID,"SKU_456")
putString(FirebaseAnalytics.Param.ITEM_NAME,"boots")
putString(FirebaseAnalytics.Param.ITEM_CATEGORY,"shoes")
putString(FirebaseAnalytics.Param.ITEM_VARIANT,"brown")
putString(FirebaseAnalytics.Param.ITEM_BRAND,"Google")
putDouble(FirebaseAnalytics.Param.PRICE,24.99)
}
valitemSocks=Bundle().apply{
putString(FirebaseAnalytics.Param.ITEM_ID,"SKU_789")
putString(FirebaseAnalytics.Param.ITEM_NAME,"ankle_socks")
putString(FirebaseAnalytics.Param.ITEM_CATEGORY,"socks")
putString(FirebaseAnalytics.Param.ITEM_VARIANT,"red")
putString(FirebaseAnalytics.Param.ITEM_BRAND,"Google")
putDouble(FirebaseAnalytics.Param.PRICE,5.99)
}

Java

BundleitemJeggings=newBundle();
itemJeggings.putString(FirebaseAnalytics.Param.ITEM_ID,"SKU_123");
itemJeggings.putString(FirebaseAnalytics.Param.ITEM_NAME,"jeggings");
itemJeggings.putString(FirebaseAnalytics.Param.ITEM_CATEGORY,"pants");
itemJeggings.putString(FirebaseAnalytics.Param.ITEM_VARIANT,"black");
itemJeggings.putString(FirebaseAnalytics.Param.ITEM_BRAND,"Google");
itemJeggings.putDouble(FirebaseAnalytics.Param.PRICE,9.99);
BundleitemBoots=newBundle();
itemBoots.putString(FirebaseAnalytics.Param.ITEM_ID,"SKU_456");
itemBoots.putString(FirebaseAnalytics.Param.ITEM_NAME,"boots");
itemBoots.putString(FirebaseAnalytics.Param.ITEM_CATEGORY,"shoes");
itemBoots.putString(FirebaseAnalytics.Param.ITEM_VARIANT,"brown");
itemBoots.putString(FirebaseAnalytics.Param.ITEM_BRAND,"Google");
itemBoots.putDouble(FirebaseAnalytics.Param.PRICE,24.99);
BundleitemSocks=newBundle();
itemSocks.putString(FirebaseAnalytics.Param.ITEM_ID,"SKU_789");
itemSocks.putString(FirebaseAnalytics.Param.ITEM_NAME,"ankle_socks");
itemSocks.putString(FirebaseAnalytics.Param.ITEM_CATEGORY,"socks");
itemSocks.putString(FirebaseAnalytics.Param.ITEM_VARIANT,"red");
itemSocks.putString(FirebaseAnalytics.Param.ITEM_BRAND,"Google");
itemSocks.putDouble(FirebaseAnalytics.Param.PRICE,5.99);

Web

// A pair of jeggings
constitem_jeggings={
item_id:'SKU_123',
item_name:'jeggings',
item_category:'pants',
item_variant:'black',
item_brand:'Google',
price:9.99
};
// A pair of boots
constitem_boots={
item_id:'SKU_456',
item_name:'boots',
item_category:'shoes',
item_variant:'brown',
item_brand:'Google',
price:24.99
};
// A pair of socks
constitem_socks={
item_id:'SKU_789',
item_name:'ankle_socks',
item_category:'socks',
item_variant:'red',
item_brand:'Google',
price:5.99
};

Web

// A pair of jeggings
constitem_jeggings={
item_id:'SKU_123',
item_name:'jeggings',
item_category:'pants',
item_variant:'black',
item_brand:'Google',
price:9.99
};
// A pair of boots
constitem_boots={
item_id:'SKU_456',
item_name:'boots',
item_category:'shoes',
item_variant:'brown',
item_brand:'Google',
price:24.99
};
// A pair of socks
constitem_socks={
item_id:'SKU_789',
item_name:'ankle_socks',
item_category:'socks',
item_variant:'red',
item_brand:'Google',
price:5.99
};

Dart

// A pair of jeggings
finaljeggings=AnalyticsEventItem(
itemId:"SKU_123",
itemName:"jeggings",
itemCategory:"pants",
itemVariant:"black",
itemBrand:"Google",
price:9.99,
);
// A pair of boots
finalboots=AnalyticsEventItem(
itemId:"SKU_456",
itemName:"boots",
itemCategory:"shoes",
itemVariant:"brown",
itemBrand:"Google",
price:24.99,
);
// A pair of socks
finalsocks=AnalyticsEventItem(
itemId:"SKU_789",
itemName:"ankle_socks",
itemCategory:"socks",
itemVariant:"red",
itemBrand:"Google",
price:5.99,
);

Select a product from a list

When a user is presented with a list of results, log a view_item_list event including an items array parameter containing the displayed products.

Swift

Note: This Firebase product is not available on the macOS target.
// Add item indexes
jeggings[AnalyticsParameterIndex]=1
boots[AnalyticsParameterIndex]=2
socks[AnalyticsParameterIndex]=3
// Prepare ecommerce parameters
varitemList:[String:Any]=[
AnalyticsParameterItemListID:"L001",
AnalyticsParameterItemListName:"Related products",
]
// Add items array
itemList[AnalyticsParameterItems]=[jeggings,boots,socks]
// Log view item list event
Analytics.logEvent(AnalyticsEventViewItemList,parameters:itemList)

Objective-C

Note: This Firebase product is not available on the macOS target.
// Add item indexes
jeggings[kFIRParameterIndex]=@1;
boots[kFIRParameterIndex]=@2;
socks[kFIRParameterIndex]=@3;
// Prepare ecommerce parameters
NSMutableDictionary*itemList=[@{
kFIRParameterItemListID:@"L001",
kFIRParameterItemListName:@"Related products",
}mutableCopy];
// Add items array
itemList[kFIRParameterItems]=@[jeggings,boots,socks];
// Log view item list event
[FIRAnalyticslogEventWithName:kFIREventViewItemListparameters:itemList];

Kotlin

valitemJeggingsWithIndex=Bundle(itemJeggings).apply{
putLong(FirebaseAnalytics.Param.INDEX,1)
}
valitemBootsWithIndex=Bundle(itemBoots).apply{
putLong(FirebaseAnalytics.Param.INDEX,2)
}
valitemSocksWithIndex=Bundle(itemSocks).apply{
putLong(FirebaseAnalytics.Param.INDEX,3)
}
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM_LIST){
param(FirebaseAnalytics.Param.ITEM_LIST_ID,"L001")
param(FirebaseAnalytics.Param.ITEM_LIST_NAME,"Related products")
param(
FirebaseAnalytics.Param.ITEMS,
arrayOf(itemJeggingsWithIndex,itemBootsWithIndex,itemSocksWithIndex),
)
}

Java

BundleitemJeggingsWithIndex=newBundle(itemJeggings);
itemJeggingsWithIndex.putLong(FirebaseAnalytics.Param.INDEX,1);
BundleitemBootsWithIndex=newBundle(itemBoots);
itemBootsWithIndex.putLong(FirebaseAnalytics.Param.INDEX,2);
BundleitemSocksWithIndex=newBundle(itemSocks);
itemSocksWithIndex.putLong(FirebaseAnalytics.Param.INDEX,3);
BundleviewItemListParams=newBundle();
viewItemListParams.putString(FirebaseAnalytics.Param.ITEM_LIST_ID,"L001");
viewItemListParams.putString(FirebaseAnalytics.Param.ITEM_LIST_NAME,"Related products");
viewItemListParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,
newParcelable[]{itemJeggingsWithIndex,itemBootsWithIndex,itemSocksWithIndex});
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM_LIST,viewItemListParams);

Web

import{getAnalytics,logEvent}from"firebase/analytics";
// Prepare ecommerce params
constparams1={
item_list_id:'L001',
item_list_name:'Related products',
items:[item_jeggings,item_boots,item_socks]
};
// Log event
constanalytics=getAnalytics();
logEvent(analytics,'view_item_list',params1);

Web

// Prepare ecommerce params
constparams1={
item_list_id:'L001',
item_list_name:'Related products',
items:[item_jeggings,item_boots,item_socks]
};
// Log event
firebase.analytics().logEvent(firebase.analytics.EventName.VIEW_ITEM_LIST,params1);

Dart

awaitFirebaseAnalytics.instance.logViewItemList(
itemListId:"L001",
itemListName:"Related products",
items:[jeggings,boots,socks],
);

Once a user selects a particular product from the list, log a select_item event with the chosen product in an items array parameter.

Swift

Note: This Firebase product is not available on the macOS target.
// Prepare ecommerce parameters
varselectedItem:[String:Any]=[
AnalyticsParameterItemListID:"L001",
AnalyticsParameterItemListName:"Related products",
]
// Add items array
selectedItem[AnalyticsParameterItems]=[jeggings]
// Log select item event
Analytics.logEvent(AnalyticsEventSelectItem,parameters:selectedItem)

Objective-C

Note: This Firebase product is not available on the macOS target.
// Prepare ecommerce parameters
NSMutableDictionary*selectedItem=[@{
kFIRParameterItemListID:@"L001",
kFIRParameterItemListName:@"Related products",
}mutableCopy];
// Add items array
selectedItem[kFIRParameterItems]=@[jeggings];
// Log select item event
[FIRAnalyticslogEventWithName:kFIREventSelectItemparameters:selectedItem];

Kotlin

firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM){
param(FirebaseAnalytics.Param.ITEM_LIST_ID,"L001")
param(FirebaseAnalytics.Param.ITEM_LIST_NAME,"Related products")
param(FirebaseAnalytics.Param.ITEMS,arrayOf(itemJeggings))
}

Java

BundleselectItemParams=newBundle();
selectItemParams.putString(FirebaseAnalytics.Param.ITEM_LIST_ID,"L001");
selectItemParams.putString(FirebaseAnalytics.Param.ITEM_LIST_NAME,"Related products");
selectItemParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,
newParcelable[]{itemJeggings});
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_ITEM,selectItemParams);

Web

import{getAnalytics,logEvent}from"firebase/analytics";
// Prepare ecommerce event params
constparams2={
item_list_id:'L001',
item_list_name:'Related products',
items:[item_jeggings]
};
// Log event
constanalytics=getAnalytics();
logEvent(analytics,'select_item',params2);

Web

// Prepare ecommerce event params
constparams2={
item_list_id:'L001',
item_list_name:'Related products',
items:[item_jeggings]
};
// Log event
firebase.analytics().logEvent(firebase.analytics.EventName.SELECT_ITEM,params2);

Dart

awaitFirebaseAnalytics.instance.logSelectItem(
itemListId:"L001",
itemListName:"Related products",
items:[jeggings],
);

View product details

To measure how many times product details are viewed, log a view_item event whenever a user views a product’s details screen.

Swift

Note: This Firebase product is not available on the macOS target.
// Prepare ecommerce parameters
varproductDetails:[String:Any]=[
AnalyticsParameterCurrency:"USD",
AnalyticsParameterValue:9.99
]
// Add items array
productDetails[AnalyticsParameterItems]=[jeggings]
// Log view item event
Analytics.logEvent(AnalyticsEventViewItem,parameters:productDetails)

Objective-C

Note: This Firebase product is not available on the macOS target.
// Prepare ecommerce parameters
NSMutableDictionary*productDetails=[@{
kFIRParameterCurrency:@"USD",
kFIRParameterValue:@9.99
}mutableCopy];
// Add items array
productDetails[kFIRParameterItems]=@[jeggings];
// Log view item event
[FIRAnalyticslogEventWithName:kFIREventViewItemparameters:productDetails];

Kotlin

firebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM){
param(FirebaseAnalytics.Param.CURRENCY,"USD")
param(FirebaseAnalytics.Param.VALUE,9.99)
param(FirebaseAnalytics.Param.ITEMS,arrayOf(itemJeggings))
}

Java

BundleviewItemParams=newBundle();
viewItemParams.putString(FirebaseAnalytics.Param.CURRENCY,"USD");
viewItemParams.putDouble(FirebaseAnalytics.Param.VALUE,9.99);
viewItemParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,
newParcelable[]{itemJeggings});
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM,viewItemParams);

Web

import{getAnalytics,logEvent}from"firebase/analytics";
// Prepare ecommerce event params
constparams3={
currency:'USD',
value:9.99,
items:[item_jeggings]
};
// Log event
constanalytics=getAnalytics();
logEvent(analytics,'view_item',params3);

Web

// Prepare ecommerce event params
constparams3={
currency:'USD',
value:9.99,
items:[item_jeggings]
};
// Log event
firebase.analytics().logEvent(firebase.analytics.EventName.VIEW_ITEM,params3);

Dart

awaitFirebaseAnalytics.instance.logViewItem(
currency:'USD',
value:9.99,
items:[jeggings],
);

Add or remove a product from a shopping cart

Measure a product being added to a wishlist or cart by logging an add_to_wishlist or add_to_cart event, respectively, with the relevant products in an items array parameter.

Swift

Note: This Firebase product is not available on the macOS target.
// Specify order quantity
jeggings[AnalyticsParameterQuantity]=2
// Prepare item detail params
varitemDetails:[String:Any]=[
AnalyticsParameterCurrency:"USD",
AnalyticsParameterValue:19.98
]
// Add items
itemDetails[AnalyticsParameterItems]=[jeggings]
// Log an event when product is added to wishlist
Analytics.logEvent(AnalyticsEventAddToWishlist,parameters:itemDetails)
// Log an event when product is added to cart
Analytics.logEvent(AnalyticsEventAddToCart,parameters:itemDetails)

Objective-C

Note: This Firebase product is not available on the macOS target.
// Specify order quantity
jeggings[kFIRParameterQuantity]=@2;
// Prepare item detail params
NSMutableDictionary*itemDetails=[@{
kFIRParameterCurrency:@"USD",
kFIRParameterValue:@19.98
}mutableCopy];
// Add items
itemDetails[kFIRParameterItems]=@[jeggings];
// Log an event when product is added to wishlist
[FIRAnalyticslogEventWithName:kFIREventAddToWishlistparameters:itemDetails];
// Log an event when product is added to cart
[FIRAnalyticslogEventWithName:kFIREventAddToCartparameters:itemDetails];

Kotlin

valitemJeggingsWishlist=Bundle(itemJeggings).apply{
putLong(FirebaseAnalytics.Param.QUANTITY,2)
}
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.ADD_TO_WISHLIST){
param(FirebaseAnalytics.Param.CURRENCY,"USD")
param(FirebaseAnalytics.Param.VALUE,2*9.99)
param(FirebaseAnalytics.Param.ITEMS,arrayOf(itemJeggingsWishlist))
}

Java

BundleitemJeggingsWishlist=newBundle(itemJeggings);
itemJeggingsWishlist.putLong(FirebaseAnalytics.Param.QUANTITY,2);
BundleaddToWishlistParams=newBundle();
addToWishlistParams.putString(FirebaseAnalytics.Param.CURRENCY,"USD");
addToWishlistParams.putDouble(FirebaseAnalytics.Param.VALUE,2*9.99);
addToWishlistParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,
newParcelable[]{itemJeggingsWishlist});
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.ADD_TO_WISHLIST,addToWishlistParams);

Web

import{getAnalytics,logEvent}from"firebase/analytics";
// Specify order quantity
constitem_jeggings_quantity={
...item_jeggings,
quantity:2
};
// Prepare ecommerce bundle
constparams4={
currency:'USD',
value:19.98,
items:[item_jeggings_quantity]
};
// Log event when a product is added to a wishlist
constanalytics=getAnalytics();
logEvent(analytics,'add_to_wishlist',params4);
// Log event when a product is added to the cart
logEvent(analytics,'add_to_cart',params4);

Web

// Specify order quantity
constitem_jeggings_quantity={
...item_jeggings,
quantity:2
};
// Prepare ecommerce bundle
constparams4={
currency:'USD',
value:19.98,
items:[item_jeggings_quantity]
};
// Log event when a product is added to a wishlist
firebase.analytics().logEvent(firebase.analytics.EventName.ADD_TO_WISHLIST,params4);
// Log event when a product is added to the cart
firebase.analytics().logEvent(firebase.analytics.EventName.ADD_TO_CART,params4);

Dart

finaljeggingsWithQuantity=AnalyticsEventItem(
itemId:jeggings.itemId,
itemName:jeggings.itemName,
itemCategory:jeggings.itemCategory,
itemVariant:jeggings.itemVariant,
itemBrand:jeggings.itemBrand,
price:jeggings.price,
quantity:2,
);
awaitFirebaseAnalytics.instance.logAddToWishlist(
currency:'USD',
value:19.98,
items:[jeggingsWithQuantity],
);
awaitFirebaseAnalytics.instance.logAddToCart(
currency:'USD',
value:19.98,
items:[jeggingsWithQuantity],
);

When a user subsequently views the cart, log the view_cart event with all items in the cart.

Swift

Note: This Firebase product is not available on the macOS target.
// Specify order quantity
jeggings[AnalyticsParameterQuantity]=2
boots[AnalyticsParameterQuantity]=1
// Prepare order parameters
varorderParameters:[String:Any]=[
AnalyticsParameterCurrency:"USD",
AnalyticsParameterValue:44.97
]
// Add items array
orderParameters[AnalyticsParameterItems]=[jeggings,boots]
// Log event when cart is viewed
Analytics.logEvent(AnalyticsEventViewCart,parameters:orderParameters)

Objective-C

Note: This Firebase product is not available on the macOS target.
// Specify order quantity
jeggings[kFIRParameterQuantity]=@2;
boots[kFIRParameterQuantity]=@1;
// Prepare order parameters
NSMutableDictionary*orderParameters=[@{
kFIRParameterCurrency:@"USD",
kFIRParameterValue:@44.97
}mutableCopy];
// Add items array
orderParameters[kFIRParameterItems]=@[jeggings,boots];
// Log event when cart is viewed
[FIRAnalyticslogEventWithName:kFIREventViewCartparameters:orderParameters];

Kotlin

valitemJeggingsCart=Bundle(itemJeggings).apply{
putLong(FirebaseAnalytics.Param.QUANTITY,2)
}
valitemBootsCart=Bundle(itemBoots).apply{
putLong(FirebaseAnalytics.Param.QUANTITY,1)
}
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_CART){
param(FirebaseAnalytics.Param.CURRENCY,"USD")
param(FirebaseAnalytics.Param.VALUE,2*9.99+1*24.99)
param(FirebaseAnalytics.Param.ITEMS,arrayOf(itemJeggingsCart,itemBootsCart))
}

Java

BundleitemJeggingsCart=newBundle(itemJeggings);
itemJeggingsCart.putLong(FirebaseAnalytics.Param.QUANTITY,2);
BundleitemBootsCart=newBundle(itemBoots);
itemBootsCart.putLong(FirebaseAnalytics.Param.QUANTITY,1);
BundleviewCartParams=newBundle();
viewCartParams.putString(FirebaseAnalytics.Param.CURRENCY,"USD");
viewCartParams.putDouble(FirebaseAnalytics.Param.VALUE,(2*9.99)+(1*24.99));
viewCartParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,
newParcelable[]{itemJeggingsCart,itemBootsCart});
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_CART,viewCartParams);

Web

import{getAnalytics,logEvent}from"firebase/analytics";
// Specify order quantity
constitem_jeggings_quantity={
...item_jeggings,
quantity:2
};
constitem_boots_quantity={
...item_boots,
quantity:1
};
// Prepare ecommerce params
constparams5={
currency:'USD',
value:44.97,
items:[item_jeggings_quantity,item_boots_quantity]
};
// Log event when the cart is viewed
constanalytics=getAnalytics();
logEvent(analytics,'view_cart',params5);

Web

// Specify order quantity
constitem_jeggings_quantity={
...item_jeggings,
quantity:2
};
constitem_boots_quantity={
...item_boots,
quantity:1
};
// Prepare ecommerce params
constparams5={
currency:'USD',
value:44.97,
items:[item_jeggings_quantity,item_boots_quantity]
};
// Log event when the cart is viewed
firebase.analytics().logEvent(firebase.analytics.EventName.VIEW_CART,params5);

Dart

awaitFirebaseAnalytics.instance.logViewCart(
currency:'USD',
value:19.98,
items:[jeggingsWithQuantity],
);

To measure when a user removes a product from a cart, log the remove_from_cart event.

Swift

Note: This Firebase product is not available on the macOS target.
// Specify removal quantity
boots[AnalyticsParameterQuantity]=1
// Prepare params
varremoveParams:[String:Any]=[
AnalyticsParameterCurrency:"USD",
AnalyticsParameterValue:24.99
]
// Add items
removeParams[AnalyticsParameterItems]=[boots]
// Log removal event
Analytics.logEvent(AnalyticsEventRemoveFromCart,parameters:removeParams)

Objective-C

Note: This Firebase product is not available on the macOS target.
// Specify removal quantity
boots[kFIRParameterQuantity]=@1;
// Prepare params
NSMutableDictionary*removeParams=[@{
kFIRParameterCurrency:@"USD",
kFIRParameterValue:@24.99
}mutableCopy];
// Add items
removeParams[kFIRParameterItems]=@[boots];
// Log removal event
[FIRAnalyticslogEventWithName:kFIREventRemoveFromCartparameters:removeParams];

Kotlin

firebaseAnalytics.logEvent(FirebaseAnalytics.Event.REMOVE_FROM_CART){
param(FirebaseAnalytics.Param.CURRENCY,"USD")
param(FirebaseAnalytics.Param.VALUE,1*24.99)
param(FirebaseAnalytics.Param.ITEMS,arrayOf(itemBootsCart))
}

Java

BundleremoveCartParams=newBundle();
removeCartParams.putString(FirebaseAnalytics.Param.CURRENCY,"USD");
removeCartParams.putDouble(FirebaseAnalytics.Param.VALUE,(1*24.99));
removeCartParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,
newParcelable[]{itemBootsCart});
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.REMOVE_FROM_CART,removeCartParams);

Web

import{getAnalytics,logEvent}from"firebase/analytics";
// Prepare ecommerce params
constparams6={
currency:'USD',
value:24.99,
items:[item_jeggings]
};
// Log event
constanalytics=getAnalytics();
logEvent(analytics,'remove_from_cart',params6);

Web

// Prepare ecommerce params
constparams6={
currency:'USD',
value:24.99,
items:[item_jeggings]
};
// Log event
firebase.analytics().logEvent(firebase.analytics.EventName.REMOVE_FROM_CART,params6);

Dart

finaljeggingsWithQuantity=AnalyticsEventItem(
itemId:jeggings.itemId,
itemName:jeggings.itemName,
itemCategory:jeggings.itemCategory,
itemVariant:jeggings.itemVariant,
itemBrand:jeggings.itemBrand,
price:jeggings.price,
quantity:1,
);
awaitFirebaseAnalytics.instance.logRemoveFromCart(
currency:'USD',
value:9.99,
items:[jeggingsWithQuantity],
);

Initiate the checkout process

Measure the first step in a checkout process by logging a begin_checkout event with one or more items defined with the relevant fields. A coupon can also be added at this stage to the entire order by adding it to the event or applied to a particular item by adding it to specific elements in the items array.

Swift

Note: This Firebase product is not available on the macOS target.
// Prepare checkout params
varcheckoutParams:[String:Any]=[
AnalyticsParameterCurrency:"USD",
AnalyticsParameterValue:14.98,
AnalyticsParameterCoupon:"SUMMER_FUN"
];
// Add items
checkoutParams[AnalyticsParameterItems]=[jeggings]
// Log checkout event
Analytics.logEvent(AnalyticsEventBeginCheckout,parameters:checkoutParams)

Objective-C

Note: This Firebase product is not available on the macOS target.
// Prepare checkout params
NSMutableDictionary*checkoutParams=[@{
kFIRParameterCurrency:@"USD",
kFIRParameterValue:@14.98,
kFIRParameterCoupon:@"SUMMER_FUN"
}mutableCopy];
// Add items
checkoutParams[kFIRParameterItems]=@[jeggings];
// Log checkout event
[FIRAnalyticslogEventWithName:kFIREventBeginCheckoutparameters:checkoutParams];

Kotlin

firebaseAnalytics.logEvent(FirebaseAnalytics.Event.BEGIN_CHECKOUT){
param(FirebaseAnalytics.Param.CURRENCY,"USD")
param(FirebaseAnalytics.Param.VALUE,14.98)
param(FirebaseAnalytics.Param.COUPON,"SUMMER_FUN")
param(FirebaseAnalytics.Param.ITEMS,arrayOf(itemJeggingsCart))
}

Java

BundlebeginCheckoutParams=newBundle();
beginCheckoutParams.putString(FirebaseAnalytics.Param.CURRENCY,"USD");
beginCheckoutParams.putDouble(FirebaseAnalytics.Param.VALUE,14.98);
beginCheckoutParams.putString(FirebaseAnalytics.Param.COUPON,"SUMMER_FUN");
beginCheckoutParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,
newParcelable[]{itemJeggingsCart});
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.BEGIN_CHECKOUT,beginCheckoutParams);

Web

import{getAnalytics,logEvent}from"firebase/analytics";
// Prepare ecommerce params
constparams7={
currency:'USD',
value:14.98,// Total Revenue
coupon:'SUMMER_FUN',
items:[item_jeggings]
};
// Log event
constanalytics=getAnalytics();
logEvent(analytics,'begin_checkout',params7);

Web

// Prepare ecommerce params
constparams7={
currency:'USD',
value:14.98,// Total Revenue
coupon:'SUMMER_FUN',
items:[item_jeggings]
};
// Log event
firebase.analytics().logEvent(firebase.analytics.EventName.BEGIN_CHECKOUT,params7);

Dart

awaitFirebaseAnalytics.instance.logBeginCheckout(
currency:'USD',
value:15.98,// Discount applied.
coupon:"SUMMER_FUN",
items:[jeggingsWithQuantity],
);

When a user proceeds to the next step in the checkout process and adds shipping information, log an add_shipping_info event. Use the parameter shipping_tier to specify the user’s delivery option, such as "Ground", "Air", or "Next-day".

Swift

Note: This Firebase product is not available on the macOS target.
// Prepare shipping params
varshippingParams:[String:Any]=[
AnalyticsParameterCurrency:"USD",
AnalyticsParameterValue:14.98,
AnalyticsParameterCoupon:"SUMMER_FUN",
AnalyticsParameterShippingTier:"Ground"
]
// Add items
shippingParams[AnalyticsParameterItems]=[jeggings]
// Log added shipping info event
Analytics.logEvent(AnalyticsEventAddShippingInfo,parameters:shippingParams)

Objective-C

Note: This Firebase product is not available on the macOS target.
// Prepare shipping params
NSMutableDictionary*shippingParams=[@{
kFIRParameterCurrency:@"USD",
kFIRParameterValue:@14.98,
kFIRParameterCoupon:@"SUMMER_FUN",
kFIRParameterShippingTier:@"Ground"
}mutableCopy];
// Add items
shippingParams[kFIRParameterItems]=@[jeggings];
// Log added shipping info event
[FIRAnalyticslogEventWithName:kFIREventAddShippingInfoparameters:shippingParams];

Kotlin

firebaseAnalytics.logEvent(FirebaseAnalytics.Event.ADD_SHIPPING_INFO){
param(FirebaseAnalytics.Param.CURRENCY,"USD")
param(FirebaseAnalytics.Param.VALUE,14.98)
param(FirebaseAnalytics.Param.COUPON,"SUMMER_FUN")
param(FirebaseAnalytics.Param.SHIPPING_TIER,"Ground")
param(FirebaseAnalytics.Param.ITEMS,arrayOf(itemJeggingsCart))
}

Java

BundleaddShippingParams=newBundle();
addShippingParams.putString(FirebaseAnalytics.Param.CURRENCY,"USD");
addShippingParams.putDouble(FirebaseAnalytics.Param.VALUE,14.98);
addShippingParams.putString(FirebaseAnalytics.Param.COUPON,"SUMMER_FUN");
addShippingParams.putString(FirebaseAnalytics.Param.SHIPPING_TIER,"Ground");
addShippingParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,
newParcelable[]{itemJeggingsCart});
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.ADD_SHIPPING_INFO,addShippingParams);

Web

import{getAnalytics,logEvent}from"firebase/analytics";
// Prepare ecommerce params
constparams8={
currency:'USD',
value:14.98,// Total Revenue
coupon:'SUMMER_FUN',
shipping_tier:'Ground',
items:[item_jeggings]
};
// Log event
constanalytics=getAnalytics();
logEvent(analytics,'add_shipping_info',params8);

Web

// Prepare ecommerce params
constparams8={
currency:'USD',
value:14.98,// Total Revenue
coupon:'SUMMER_FUN',
shipping_tier:'Ground',
items:[item_jeggings]
};
// Log event
firebase.analytics().logEvent(firebase.analytics.EventName.ADD_SHIPPING_INFO,params8);

Dart

awaitFirebaseAnalytics.instance.logAddShippingInfo(
currency:'USD',
value:15.98,
coupon:"SUMMER_FUN",
shippingTier:"Ground",
items:[jeggingsWithQuantity],
);

Log add_payment_info when a user submits their payment information. If applicable, include payment_type with this event for the chosen method of payment.

Swift

Note: This Firebase product is not available on the macOS target.
// Prepare payment params
varpaymentParams:[String:Any]=[
AnalyticsParameterCurrency:"USD",
AnalyticsParameterValue:14.98,
AnalyticsParameterCoupon:"SUMMER_FUN",
AnalyticsParameterPaymentType:"Visa"
]
// Add items
paymentParams[AnalyticsParameterItems]=[jeggings]
// Log added payment info event
Analytics.logEvent(AnalyticsEventAddPaymentInfo,parameters:paymentParams)

Objective-C

Note: This Firebase product is not available on the macOS target.
// Prepare payment params
NSMutableDictionary*paymentParams=[@{
kFIRParameterCurrency:@"USD",
kFIRParameterValue:@14.98,
kFIRParameterCoupon:@"SUMMER_FUN",
kFIRParameterPaymentType:@"Visa"
}mutableCopy];
// Add items
paymentParams[kFIRParameterItems]=@[jeggings];
// Log added payment info event
[FIRAnalyticslogEventWithName:kFIREventAddPaymentInfoparameters:paymentParams];

Kotlin

firebaseAnalytics.logEvent(FirebaseAnalytics.Event.ADD_PAYMENT_INFO){
param(FirebaseAnalytics.Param.CURRENCY,"USD")
param(FirebaseAnalytics.Param.VALUE,14.98)
param(FirebaseAnalytics.Param.COUPON,"SUMMER_FUN")
param(FirebaseAnalytics.Param.PAYMENT_TYPE,"Visa")
param(FirebaseAnalytics.Param.ITEMS,arrayOf(itemJeggingsCart))
}

Java

BundleaddPaymentParams=newBundle();
addPaymentParams.putString(FirebaseAnalytics.Param.CURRENCY,"USD");
addPaymentParams.putDouble(FirebaseAnalytics.Param.VALUE,14.98);
addPaymentParams.putString(FirebaseAnalytics.Param.COUPON,"SUMMER_FUN");
addPaymentParams.putString(FirebaseAnalytics.Param.PAYMENT_TYPE,"Visa");
addPaymentParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,
newParcelable[]{itemJeggingsCart});
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.ADD_PAYMENT_INFO,addPaymentParams);

Web

import{getAnalytics,logEvent}from"firebase/analytics";
// Prepare ecommerce params
constparams9={
currency:'USD',
value:14.98,// Total Revenue
coupon:'SUMMER_FUN',
payment_type:'Visa',
items:[item_jeggings]
};
// Log event
constanalytics=getAnalytics();
logEvent(analytics,'add_payment_info',params9);

Web

// Prepare ecommerce params
constparams9={
currency:'USD',
value:14.98,// Total Revenue
coupon:'SUMMER_FUN',
payment_type:'Visa',
items:[item_jeggings]
};
// Log event
firebase.analytics().logEvent(firebase.analytics.EventName.ADD_PAYMENT_INFO,params9);

Dart

awaitFirebaseAnalytics.instance.logAddPaymentInfo(
currency:'USD',
value:15.98,
coupon:"SUMMER_FUN",
paymentType:"Visa",
items:[jeggingsWithQuantity],
);

Make a purchase or issue a refund

Measure a purchase by logging a purchase event with one or more items defined with the relevant fields.

Swift

Note: This Firebase product is not available on the macOS target.
// Prepare purchase params
varpurchaseParams:[String:Any]=[
AnalyticsParameterTransactionID:"T12345",
AnalyticsParameterAffiliation:"Google Store",
AnalyticsParameterCurrency:"USD",
AnalyticsParameterValue:14.98,
AnalyticsParameterTax:2.58,
AnalyticsParameterShipping:5.34,
AnalyticsParameterCoupon:"SUMMER_FUN"
]
// Add items
purchaseParams[AnalyticsParameterItems]=[jeggings]
// Log purchase event
Analytics.logEvent(AnalyticsEventPurchase,parameters:purchaseParams)

Objective-C

Note: This Firebase product is not available on the macOS target.
// Prepare purchase params
NSMutableDictionary*purchaseParams=[@{
kFIRParameterTransactionID:@"T12345",
kFIRParameterAffiliation:@"Google Store",
kFIRParameterCurrency:@"USD",
kFIRParameterValue:@14.98,
kFIRParameterTax:@2.58,
kFIRParameterShipping:@5.34,
kFIRParameterCoupon:@"SUMMER_FUN"
}mutableCopy];
// Add items
purchaseParams[kFIRParameterItems]=@[jeggings];
// Log purchase event
[FIRAnalyticslogEventWithName:kFIREventPurchaseparameters:purchaseParams];

Kotlin

firebaseAnalytics.logEvent(FirebaseAnalytics.Event.PURCHASE){
param(FirebaseAnalytics.Param.TRANSACTION_ID,"T12345")
param(FirebaseAnalytics.Param.AFFILIATION,"Google Store")
param(FirebaseAnalytics.Param.CURRENCY,"USD")
param(FirebaseAnalytics.Param.VALUE,14.98)
param(FirebaseAnalytics.Param.TAX,2.58)
param(FirebaseAnalytics.Param.SHIPPING,5.34)
param(FirebaseAnalytics.Param.COUPON,"SUMMER_FUN")
param(FirebaseAnalytics.Param.ITEMS,arrayOf(itemJeggingsCart))
}

Java

BundlepurchaseParams=newBundle();
purchaseParams.putString(FirebaseAnalytics.Param.TRANSACTION_ID,"T12345");
purchaseParams.putString(FirebaseAnalytics.Param.AFFILIATION,"Google Store");
purchaseParams.putString(FirebaseAnalytics.Param.CURRENCY,"USD");
purchaseParams.putDouble(FirebaseAnalytics.Param.VALUE,14.98);
purchaseParams.putDouble(FirebaseAnalytics.Param.TAX,2.58);
purchaseParams.putDouble(FirebaseAnalytics.Param.SHIPPING,5.34);
purchaseParams.putString(FirebaseAnalytics.Param.COUPON,"SUMMER_FUN");
purchaseParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,
newParcelable[]{itemJeggingsCart});
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.PURCHASE,purchaseParams);

Web

import{getAnalytics,logEvent}from"firebase/analytics";
// Prepare ecommerce bundle
constparams10={
transaction_id:'T12345',
affiliation:'Google Store',
currency:'USD',
value:14.98,// Total Revenue
tax:2.85,
shipping:5.34,
coupon:'SUMMER_FUN',
items:[item_jeggings]
};
// Log event
constanalytics=getAnalytics();
logEvent(analytics,'purchase',params10);

Web

// Prepare ecommerce bundle
constparams10={
transaction_id:'T12345',
affiliation:'Google Store',
currency:'USD',
value:14.98,// Total Revenue
tax:2.85,
shipping:5.34,
coupon:'SUMMER_FUN',
items:[item_jeggings]
};
// Log event
firebase.analytics().logEvent(firebase.analytics.EventName.PURCHASE,params10);

Dart

awaitFirebaseAnalytics.instance.logPurchase(
transactionId:"12345",
affiliation:"Google Store",
currency:'USD',
value:15.98,
shipping:2.00,
tax:1.66,
coupon:"SUMMER_FUN",
items:[jeggingsWithQuantity],
);

Measure refunds by logging a refund event with the relevant transaction_id specified and optionally one or more items defined with item_id and quantity. We recommend that you include item information in your refund event to see item-level refund metrics in Analytics.

Swift

Note: This Firebase product is not available on the macOS target.
// Prepare refund params
varrefundParams:[String:Any]=[
AnalyticsParameterTransactionID:"T12345",
AnalyticsParameterCurrency:"USD",
AnalyticsParameterValue:9.99,
]
// (Optional) for partial refunds, define the item ID and quantity of refunded items
letrefundedProduct:[String:Any]=[
AnalyticsParameterItemID:"SKU_123",
AnalyticsParameterQuantity:1,
];
// Add items
refundParams[AnalyticsParameterItems]=[refundedProduct]
// Log refund event
Analytics.logEvent(AnalyticsEventRefund,parameters:refundParams)

Objective-C

Note: This Firebase product is not available on the macOS target.
// Prepare refund params
NSMutableDictionary*refundParams=[@{
kFIRParameterTransactionID:@"T12345",
kFIRParameterCurrency:@"USD",
kFIRParameterValue:@9.99,
}mutableCopy];
// (Optional) for partial refunds, define the item ID and quantity of refunded items
NSDictionary*refundedProduct=@{
kFIRParameterItemID:@"SKU_123",
kFIRParameterQuantity:@1,
};
// Add items
refundParams[kFIRParameterItems]=@[refundedProduct];
// Log refund event
[FIRAnalyticslogEventWithName:kFIREventRefundparameters:refundParams];

Kotlin

firebaseAnalytics.logEvent(FirebaseAnalytics.Event.REFUND){
param(FirebaseAnalytics.Param.TRANSACTION_ID,"T12345")
param(FirebaseAnalytics.Param.AFFILIATION,"Google Store")
param(FirebaseAnalytics.Param.CURRENCY,"USD")
param(FirebaseAnalytics.Param.VALUE,9.99)
// (Optional) for partial refunds, define the item ID and quantity of refunded items
param(FirebaseAnalytics.Param.ITEM_ID,"SKU_123")
param(FirebaseAnalytics.Param.QUANTITY,1)
param(FirebaseAnalytics.Param.ITEMS,arrayOf(itemJeggings))
}

Java

BundlerefundParams=newBundle();
refundParams.putString(FirebaseAnalytics.Param.TRANSACTION_ID,"T12345");
refundParams.putString(FirebaseAnalytics.Param.AFFILIATION,"Google Store");
refundParams.putString(FirebaseAnalytics.Param.CURRENCY,"USD");
refundParams.putDouble(FirebaseAnalytics.Param.VALUE,9.99);
// (Optional) for partial refunds, define the item ID and quantity of refunded items
refundParams.putString(FirebaseAnalytics.Param.ITEM_ID,"SKU_123");
refundParams.putLong(FirebaseAnalytics.Param.QUANTITY,1);
refundParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,
newParcelable[]{itemJeggings});
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.REFUND,refundParams);

Web

import{getAnalytics,logEvent}from"firebase/analytics";
// Prepare ecommerce params
constparams11={
transaction_id:'T12345',// Required
affiliation:'Google Store',
currency:'USD',
value:9.99,
items:[]
};
// (Optional) For partial refunds, define the item_id and quantity of refunded items
constrefundedProduct={
item_id:'SKU_123',// Required
quantity:1// Required
};
params11.items.push(refundedProduct);
// Log event
constanalytics=getAnalytics();
logEvent(analytics,'refund',params11);

Web

// Prepare ecommerce params
constparams11={
transaction_id:'T12345',// Required
affiliation:'Google Store',
currency:'USD',
value:9.99,
items:[]
};
// (Optional) For partial refunds, define the item_id and quantity of refunded items
constrefundedProduct={
item_id:'SKU_123',// Required
quantity:1// Required
};
params11.items.push(refundedProduct);
// Log event
firebase.analytics().logEvent(firebase.analytics.EventName.REFUND,params11);

Dart

awaitFirebaseAnalytics.instance.logRefund(
transactionId:"12345",
affiliation:"Google Store",
currency:'USD',
value:15.98,
items:[jeggingsWithQuantity],
);

Apply promotions

Ecommerce includes support for measuring impressions and clicks of internal promotions, such as banners displayed to promote a sale.

Promotion impressions are typically measured with the initial screen view by logging the view_promotion event with an items parameter to specify the promoted product. To indicate a user clicked on a promotion, log a select_promotion event with that product as an item parameter.

Swift

Note: This Firebase product is not available on the macOS target.
// Prepare promotion parameters
varpromoParams:[String:Any]=[
AnalyticsParameterPromotionID:"T12345",
AnalyticsParameterPromotionName:"Summer Sale",
AnalyticsParameterCreativeName:"summer2020_promo.jpg",
AnalyticsParameterCreativeSlot:"featured_app_1",
AnalyticsParameterLocationID:"HERO_BANNER",
]
// Add items
promoParams[AnalyticsParameterItems]=[jeggings]
// Log event when promotion is displayed
Analytics.logEvent(AnalyticsEventViewPromotion,parameters:promoParams)
// Log event when promotion is selected
Analytics.logEvent(AnalyticsEventSelectPromotion,parameters:promoParams)

Objective-C

Note: This Firebase product is not available on the macOS target.
// Prepare promotion parameters
NSMutableDictionary*promoParams=[@{
kFIRParameterPromotionID:@"T12345",
kFIRParameterPromotionName:@"Summer Sale",
kFIRParameterCreativeName:@"summer2020_promo.jpg",
kFIRParameterCreativeSlot:@"featured_app_1",
kFIRParameterLocationID:@"HERO_BANNER",
}mutableCopy];
// Add items
promoParams[kFIRParameterItems]=@[jeggings];
// Log event when promotion is displayed
[FIRAnalyticslogEventWithName:kFIREventViewPromotionparameters:promoParams];
// Log event when promotion is selected
[FIRAnalyticslogEventWithName:kFIREventSelectPromotionparameters:promoParams];

Kotlin

valpromoParams=Bundle().apply{
putString(FirebaseAnalytics.Param.PROMOTION_ID,"SUMMER_FUN")
putString(FirebaseAnalytics.Param.PROMOTION_NAME,"Summer Sale")
putString(FirebaseAnalytics.Param.CREATIVE_NAME,"summer2020_promo.jpg")
putString(FirebaseAnalytics.Param.CREATIVE_SLOT,"featured_app_1")
putString(FirebaseAnalytics.Param.LOCATION_ID,"HERO_BANNER")
putParcelableArray(FirebaseAnalytics.Param.ITEMS,arrayOf<Parcelable>(itemJeggings))
}
// Promotion displayed
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_PROMOTION,promoParams)
// Promotion selected
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_PROMOTION,promoParams)

Java

BundlepromoParams=newBundle();
promoParams.putString(FirebaseAnalytics.Param.PROMOTION_ID,"SUMMER_FUN");
promoParams.putString(FirebaseAnalytics.Param.PROMOTION_NAME,"Summer Sale");
promoParams.putString(FirebaseAnalytics.Param.CREATIVE_NAME,"summer2020_promo.jpg");
promoParams.putString(FirebaseAnalytics.Param.CREATIVE_SLOT,"featured_app_1");
promoParams.putString(FirebaseAnalytics.Param.LOCATION_ID,"HERO_BANNER");
promoParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,
newParcelable[]{itemJeggings});
// Promotion displayed
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.VIEW_PROMOTION,promoParams);
// Promotion selected
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.SELECT_PROMOTION,promoParams);

Web

import{getAnalytics,logEvent}from"firebase/analytics";
// Prepare ecommerce params
constparams12={
promotion_id:'ABC123',
promotion_name:'Summer Sale',
creative_name:'summer2020_promo.jpg',
creative_slot:'featured_app_1',
location_id:'HERO_BANNER',
items:[item_jeggings]
};
// Log event when a promotion is displayed
constanalytics=getAnalytics();
logEvent(analytics,'view_promotion',params12);
// Log event when a promotion is selected
logEvent(analytics,'select_promotion',params12);

Web

// Prepare ecommerce params
constparams12={
promotion_id:'ABC123',
promotion_name:'Summer Sale',
creative_name:'summer2020_promo.jpg',
creative_slot:'featured_app_1',
location_id:'HERO_BANNER',
items:[item_jeggings]
};
// Log event when a promotion is displayed
firebase.analytics().logEvent(firebase.analytics.EventName.VIEW_PROMOTION,params12);
// Log event when a promotion is selected
firebase.analytics().logEvent(firebase.analytics.EventName.SELECT_PROMOTION,params12);

Dart

awaitFirebaseAnalytics.instance.logViewPromotion(
promotionId:"SUMMER_FUN",
promotionName:"Summer Sale",
creativeName:"summer2020_promo.jpg",
creativeSlot:"featured_app_1",
locationId:"HERO_BANNER",
);
awaitFirebaseAnalytics.instance.logSelectPromotion(
promotionId:"SUMMER_FUN",
promotionName:"Summer Sale",
creativeName:"summer2020_promo.jpg",
creativeSlot:"featured_app_1",
locationId:"HERO_BANNER",
);

Send item-scoped custom parameters

An item-scoped custom parameter is a parameter that isn't one of the parameters that Google includes in the list of required or optional parameters for an ecommerce item. The custom parameter lets you collect information about an item that's useful to your specific business.

From your app, you can send up to 27 item-scoped custom parameters in the array of items, of which you can configure 10 item-scoped custom dimensions for standard properties and 25 for Analytics 360 properties. This gives you the flexibility to choose from a larger pool of parameters without having to retag your app.

Swift

Note: This Firebase product is not available on the macOS target.
// A pair of jeggings
varjeggings:[String:Any]=[
AnalyticsParameterItemID:"SKU_123",
AnalyticsParameterItemName:"jeggings",
AnalyticsParameterItemCategory:"pants",
AnalyticsParameterItemVariant:"black",
AnalyticsParameterItemBrand:"Google",
AnalyticsParameterPrice:9.99,
AnalyticsParameterItemColor:"blue",// The item-scoped custom parameter
]

Objective-C

Note: This Firebase product is not available on the macOS target.
// A pair of jeggings
NSMutableDictionary*jeggings=[@{
kFIRParameterItemID:@"SKU_123",
kFIRParameterItemName:@"jeggings",
kFIRParameterItemCategory:@"pants",
kFIRParameterItemVariant:@"black",
kFIRParameterItemBrand:@"Google",
kFIRParameterPrice:@9.99,
kFIRParameterItemColor:@"blue",// The item-scoped custom parameter
}mutableCopy];

Kotlin

valitemJeggings=Bundle().apply{
putString(FirebaseAnalytics.Param.ITEM_ID,"SKU_123")
putString(FirebaseAnalytics.Param.ITEM_NAME,"jeggings")
putString(FirebaseAnalytics.Param.ITEM_CATEGORY,"pants")
putString(FirebaseAnalytics.Param.ITEM_VARIANT,"black")
putString(FirebaseAnalytics.Param.ITEM_BRAND,"Google")
putDouble(FirebaseAnalytics.Param.PRICE,9.99)
putString(FirebaseAnalytics.Param.ITEM_COLOR,"blue")// The item-scoped custom parameter
}

Java

BundleitemJeggings=newBundle();
itemJeggings.putString(FirebaseAnalytics.Param.ITEM_ID,"SKU_123");
itemJeggings.putString(FirebaseAnalytics.Param.ITEM_NAME,"jeggings");
itemJeggings.putString(FirebaseAnalytics.Param.ITEM_CATEGORY,"pants");
itemJeggings.putString(FirebaseAnalytics.Param.ITEM_VARIANT,"black");
itemJeggings.putString(FirebaseAnalytics.Param.ITEM_BRAND,"Google");
itemJeggings.putDouble(FirebaseAnalytics.Param.PRICE,9.99);
itemJeggings.putDouble(FirebaseAnalytics.Param.ITEM_COLOR,9.99);// The item-scoped custom parameter

Web

// A pair of jeggings
constitem_jeggings={
item_id:'SKU_123',
item_name:'jeggings',
item_category:'pants',
item_variant:'black',
item_brand:'Google',
price:9.99,
item_color:'blue'// The item-scoped custom parameter
};

Web

// A pair of jeggings
constitem_jeggings={
item_id:'SKU_123',
item_name:'jeggings',
item_category:'pants',
item_variant:'black',
item_brand:'Google',
price:9.99,
item_color:'blue'// The item-scoped custom parameter
};

Dart

// A pair of jeggings
finaljeggings=AnalyticsEventItem(
itemId:"SKU_123",
itemName:"jeggings",
itemCategory:"pants",
itemVariant:"black",
itemBrand:"Google",
price:9.99,
itemColor:"blue",// The item-scoped custom parameter
);

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年11月06日 UTC.