dusanmiha

GA4 - iOS - Swift - select_item

Oct 8th, 2021 (edited)
1,121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.95 KB | None | 0 0
  1. // Products can be instrumented as an array of items that can be added to prescribed ecommerce events.
  2.  
  3. //Once a user selects a particular product from the list, log a select_item event with the chosen product in an items array parameter.
  4.  
  5. // A pair of jeggings (product1)
  6. var jeggings: [String: Any] = [
  7.   AnalyticsParameterItemID: "SKU_123",                      //Item ID (context-specific) (NSString).
  8.   AnalyticsParameterItemName: "jeggings",                   //Item Name (context-specific) (NSString).
  9.   AnalyticsParameterItemCategory: "pants",                  //Item category (context-specific) (NSString).
  10.   AnalyticsParameterItemCategory2: "sub-cat1",              //Item sub-category (context-specific) (NSString).
  11.   AnalyticsParameterItemCategory3: "sub-cat2",              //Item sub-category (context-specific) (NSString).
  12.   AnalyticsParameterItemCategory4: "sub-cat3",              //Item sub-category (context-specific) (NSString).
  13.   AnalyticsParameterItemCategory5: "sub-cat4",              //Item sub-category (context-specific) (NSString).
  14.   AnalyticsParameterItemVariant: "black",                   //Item variant (NSString).
  15.   AnalyticsParameterItemBrand: "Google",                    //Item brand (NSString).
  16.   AnalyticsParameterPrice: 9.99,                            //Product price (double as NSNumber).
  17. ]
  18.  
  19. // Prepare ecommerce parameters
  20. var selectedItem: [String: Any] = [
  21.   AnalyticsParameterItemListID: "L001",                             //The ID of the list in which the item was presented to the user (NSString).
  22.   AnalyticsParameterItemListName: "Related products",               //The name of the list in which the item was presented to the user (NSString).
  23. ]
  24.  
  25. // Add items array for selected product (for example, jeggings)
  26. selectedItem[AnalyticsParameterItems] = [jeggings]                  //The list of items involved in the transaction. (NSArray).
  27.  
  28. // Log select item event to Firebase Analytics
  29. Analytics.logEvent(AnalyticsEventSelectItem, parameters: selectedItem)
Advertisement
Add Comment
Please, Sign In to add comment