dusanmiha

GA4 - Android - Java - view_item

Oct 8th, 2021 (edited)
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.60 KB | None | 0 0
  1. // Products can be instrumented as an array of items that can be added to prescribed ecommerce events.
  2.  
  3. //To measure how many times product details are viewed, log a view_item event whenever a user views a product’s details screen.
  4.  
  5. // A pair of jeggings (product1)
  6. Bundle itemJeggings = new Bundle();
  7. itemJeggings.putString(FirebaseAnalytics.Param.ITEM_ID, "SKU_123");                     //Item ID (context-specific) (String).
  8. itemJeggings.putString(FirebaseAnalytics.Param.ITEM_NAME, "jeggings");                  //Item Name (context-specific) (String).
  9. itemJeggings.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, "pants");                 //Item category (context-specific) (String).
  10. itemJeggings.putString(FirebaseAnalytics.Param.ITEM_CATEGORY2, "sub-cat1");             //Item sub-category (context-specific) (String).
  11. itemJeggings.putString(FirebaseAnalytics.Param.ITEM_CATEGORY3, "sub-cat2");             //Item sub-category (context-specific) (String).
  12. itemJeggings.putString(FirebaseAnalytics.Param.ITEM_CATEGORY4, "sub-cat3");             //Item sub-category (context-specific) (String).
  13. itemJeggings.putString(FirebaseAnalytics.Param.ITEM_CATEGORY5, "sub-cat4");             //Item sub-category (context-specific) (String).
  14. itemJeggings.putString(FirebaseAnalytics.Param.ITEM_VARIANT, "black");                  //Item variant (String).
  15. itemJeggings.putString(FirebaseAnalytics.Param.ITEM_BRAND, "Google");                   //Item brand. The parameter expects a string value
  16. itemJeggings.putDouble(FirebaseAnalytics.Param.PRICE, 9.99);                            //Product price (double). Expecting a double value
  17.  
  18. Bundle viewItemParams = new Bundle();
  19. viewItemParams.putString(FirebaseAnalytics.Param.CURRENCY, "USD");      //Currency of the purchase or items associated with the event, in 3-letter ISO_4217 format (String). The parameter expects a string value set with BaseBundle.putString(String, String)
  20. viewItemParams.putDouble(FirebaseAnalytics.Param.VALUE, 9.99);         
  21.         new Parcelable[] { itemJeggings });                         //A context-specific numeric value which is accumulated automatically for each event type. Value should be specified with BaseBundle.putLong(String, long) or BaseBundle.putDouble(String, double). Note: Values for pre-defined currency-related events should be accompanied by a CURRENCY param.
  22. viewItemParams.putParcelableArray(FirebaseAnalytics.Param.ITEMS,        //The list of items involved in the e-commerce action. (Parcelable[]). The parameter expects a Parcelable Array set with Bundle.putParcelableArray(String, Parcelable[]):
  23.  
  24. analytics.logEvent(FirebaseAnalytics.Event.VIEW_ITEM, viewItemParams);
Add Comment
Please, Sign In to add comment