Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Products can be instrumented as an array of items that can be added to prescribed ecommerce events.
- //Measure a product being added to a cart by logging an add_to_cart event with the relevant products in an items array parameter.
- // A pair of jeggings (product1)
- var jeggings: [String: Any] = [
- AnalyticsParameterItemID: "SKU_123", //Item ID (context-specific) (NSString).
- AnalyticsParameterItemName: "jeggings", //Item Name (context-specific) (NSString).
- AnalyticsParameterItemCategory: "pants", //Item category (context-specific) (NSString).
- AnalyticsParameterItemCategory2: "sub-cat1", //Item sub-category (context-specific) (NSString).
- AnalyticsParameterItemCategory3: "sub-cat2", //Item sub-category (context-specific) (NSString).
- AnalyticsParameterItemCategory4: "sub-cat3", //Item sub-category (context-specific) (NSString).
- AnalyticsParameterItemCategory5: "sub-cat4", //Item sub-category (context-specific) (NSString).
- AnalyticsParameterItemVariant: "black", //Item variant (NSString).
- AnalyticsParameterItemBrand: "Google", //Item brand (NSString).
- AnalyticsParameterPrice: 9.99, //Product price (double as NSNumber).
- ]
- // Specify order quantity
- jeggings[AnalyticsParameterQuantity] = 2 //Product quantity (signed 64-bit integer as NSNumber).
- // Prepare item detail params
- var itemDetails: [String: Any] = [
- AnalyticsParameterCurrency: "USD", //Currency of the product or items associated with the event, in 3-letter ISO_4217 format (NSString).
- AnalyticsParameterValue: 19.98 //A context-specific numeric value which is accumulated automatically for each event type.
- ]
- // Add items
- itemDetails[AnalyticsParameterItems] = [jeggings] //The list of items involved in the e-commerce action. (NSArray).
- // Log an event when product is added to cart
- Analytics.logEvent(AnalyticsEventAddToCart, parameters: itemDetails)
Advertisement
Add Comment
Please, Sign In to add comment