The processes for enabling and using analytics features have been updated in version 10 of the SDK. To upgrade your app to version 10 of the SDK, first update the initialization code. Then, use these code examples to update the analytics code in your app.
Enable Analytics During SDK Initialization
Use this code example to enable analytics during SDK initialization.
1// The method is called on the delegate when the user responds to the2// notification by opening the app, dismissing the notification, or choosing a3// UNNotificationAction. Set the delegate before the app returns from4// applicationDidFinishLaunching:.5func userNotificationCenter(6 _ center: UNUserNotificationCenter,7 didReceive response: UNNotificationResponse,8 withCompletionHandler completionHandler: @escaping() ->Void9){10 // tell the SDK about the notification11 PushFeature.requestSdk{ pushFeature in12 pushFeature?.setNotificationResponse(response)13}14 completionHandler()15}
Analytics Attribution
Use this code example to set the Predictive Intelligence Identifier in the SDK’s AnalyticsManager.
1MarketingCloudSdk.requestSdk{ mc in2 // Example: Setting and clearing pi identifier.3 // Setting the pi identifier4 mc?.setPiIdentifier("example@email.com")56 // Clearing the pi identifier7 mc?.setPiIdentifier(nil)8}
Track Cart Contents
Use this code example to track the contents of an in-app shopping cart.
1MarketingCloudSdk.requestSdk{ mc in2 let cartItem = mc?.cartItemDictionary(3 price: 1.10,4 quantity: 1,5 item: "123456",6 uniqueId: "uniqueId_123456"7)8 let cart = mc?.cartDictionary(cartItem: [cartItem])9 mc?.trackCartContents(cart!)10}
Track Cart Conversion
Use this code example to track the conversion of an in-app shopping cart.
1MarketingCloudSdk.requestSdk{ mc in2 let cartItem = mc?.cartItemDictionary(3 price: 1.10,4 quantity: 1,5 item: "123456",6 uniqueId: "uniqueId_123456"7)8 let cart = mc?.cartDictionary(cartItem: [cartItem])9 let order = mc?.orderDictionary(10 orderNumber: "123456",11 shipping: 2.11,12 discount: 4.99,13 cart: cart!14)15 mc?.trackCartConversion(order!)16}
Track Page Views
Use this code example to track the page views in your app.