Advertisement
emanuel1109

Android - add_to_cart

Apr 13th, 2022
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // an array with a product (or multiple products) that was added to a cart
  2. val items = arrayOf(
  3. Bundle().apply {
  4.     putString(FirebaseAnalytics.Param.ITEM_ID, "6349144490158") // insert an actual product ID
  5.     putString(FirebaseAnalytics.Param.ITEM_NAME, "Rib Support Tank - Black") // insert an actual product name
  6.     putDouble(FirebaseAnalytics.Param.PRICE, 64.00) // insert an actual product price. As a Double. Don't include currency code
  7.     putString(FirebaseAnalytics.Param.CURRENCY, "USD") // insert currency here with the correct format 'USD' 'GBP' 'EUR' etc. ISO-4217 format
  8.     putDouble(FirebaseAnalytics.Param.DISCOUNT, 26.00) // insert an actual product discount. Number or a string. Don't include currency code. Whole number of discount, not percentage. If product price is usually 100 and on sale it is 80, then discount is 20
  9.     putString(FirebaseAnalytics.Param.ITEM_BRAND, "alo") // insert an actual product brand
  10.     putString(FirebaseAnalytics.Param.AFFILIATION, "Alo_US") // insert store name region here
  11.     putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "Women") // insert an actual product top-level category
  12.     putString(FirebaseAnalytics.Param.ITEM_CATEGORY2, "Tops") // if it is possible to drill down the categories (e.g. Apparel, then T-shirt, then Men), use item_category3, etc. Can use from item_category up to item_category5
  13.     putString(FirebaseAnalytics.Param.ITEM_CATEGORY3, "Tanks")
  14.     putString(FirebaseAnalytics.Param.ITEM_CATEGORY4, "")
  15.     putString(FirebaseAnalytics.Param.ITEM_VARIANT, "Black / XS") // insert an actual product variant - in our case the color and the size, because when a user adds a product to the cart we already know the size chosen, Black / XS
  16.     putString(FirebaseAnalytics.Param.ITEM_LIST_NAME, "womens-fdm4") // if a product is added to cart directly from product list, add the list name here. If not remove that line
  17.     putLong(FirebaseAnalytics.Param.INDEX, 1)    // if a product is added to cart directly from product list, add the position in the list here, if not remove that line
  18.     putLong(FirebaseAnalytics.Param.QUANTITY, 1) // product quantity of how many products were added to a cart
  19. })
  20.  
  21. // Once a user adds a product to the cart, log an ADD_TO_CART event with the chosen product in an items array parameter.
  22. firebaseAnalytics.logEvent(FirebaseAnalytics.Event.ADD_TO_CART) {
  23.     param(FirebaseAnalytics.Param.ITEMS, items) // an array that contains the product that is being added to the cart
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement