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 purchase by logging a purchase event with one or more items defined with the relevant fields.
- // 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).
- ]
- // Prepare purchase params
- var purchaseParams: [String: Any] = [
- AnalyticsParameterTransactionID: "T12345", //The unique identifier of a transaction (NSString).
- AnalyticsParameterAffiliation: "Google Store", //Optional. A product affiliation to designate a supplying company or brick and mortar store location (NSString).
- AnalyticsParameterCurrency: "USD", //Currency of the purchase or items associated with the event, in 3-letter ISO_4217 format (NSString).
- AnalyticsParameterValue: 14.98, //Value should be specified as signed 64-bit integer or double as NSNumber.
- AnalyticsParameterTax: 2.58, //Tax cost associated with a transaction (double as NSNumber).
- AnalyticsParameterShipping: 5.34, //Shipping cost associated with a transaction (double as NSNumber).
- AnalyticsParameterCoupon: "SUMMER_FUN"
- ]
- // Add items
- purchaseParams[AnalyticsParameterItems] = [jeggings]
- // Log purchase event
- Analytics.logEvent(AnalyticsEventPurchase, parameters: purchaseParams)
Advertisement
Add Comment
Please, Sign In to add comment