dusanmiha

GA4 - iOS - Swift - view_item

Oct 8th, 2021 (edited)
644
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.89 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.  
  6. // A pair of jeggings (product1)
  7. var jeggings: [String: Any] = [
  8.   AnalyticsParameterItemID: "SKU_123",                      //Item ID (context-specific) (NSString).
  9.   AnalyticsParameterItemName: "jeggings",                   //Item Name (context-specific) (NSString).
  10.   AnalyticsParameterItemCategory: "pants",                  //Item category (context-specific) (NSString).
  11.   AnalyticsParameterItemCategory2: "sub-cat1",              //Item sub-category (context-specific) (NSString).
  12.   AnalyticsParameterItemCategory3: "sub-cat2",              //Item sub-category (context-specific) (NSString).
  13.   AnalyticsParameterItemCategory4: "sub-cat3",              //Item sub-category (context-specific) (NSString).
  14.   AnalyticsParameterItemCategory5: "sub-cat4",              //Item sub-category (context-specific) (NSString).
  15.   AnalyticsParameterItemVariant: "black",                   //Item variant (NSString).
  16.   AnalyticsParameterItemBrand: "Google",                    //Item brand (NSString).
  17.   AnalyticsParameterPrice: 9.99,                            //Product price (double as NSNumber).
  18. ]
  19. // Prepare ecommerce parameters
  20. var productDetails: [String: Any] = [
  21.   AnalyticsParameterCurrency: "USD",                //Currency of the product or items associated with the event, in 3-letter ISO_4217 format (NSString).
  22.   AnalyticsParameterValue: 9.99                     //A context-specific numeric value which is accumulated automatically for each event type.
  23. ]
  24.  
  25. // Add items array
  26. productDetails[AnalyticsParameterItems] = [jeggings]        //The list of items involved in the e-commerce action. (NSArray).
  27.  
  28. // Log view item event
  29. Analytics.logEvent(AnalyticsEventViewItem, parameters: productDetails)
  30.  
Advertisement
Add Comment
Please, Sign In to add comment