Enable and Use Analytics on iOS
Enable analytics in your configuration file using the analytics:true value. The SDK collects analytics in the background and when SDK methods are called.
To ensure proper tracking of push notifications by the SDK and Marketing Cloud Engagement analytics, call the SDK in your push notification handler method. If you don’t, analytic events can’t track open counts for your push messaging campaigns. This code example shows how to track push notifications using version 10 of the SDK.
If you use version 8 of the SDK, use this code.
If you use version 7 of the SDK, use this code.
You can also track analytics for Inbox messages. To send the open analytic value to Engagement, call trackInboxOpenEvent(). We automatically provide analytical information for message downloads.
To record analytics, call trackMessageOpened with an inbox message dictionary. This code example shows how to track inbox message opens using version 10 of the SDK.
For version 8 of the SDK, use this code.
If you use version 7 of the SDK, use this code.
Einstein Recommendations analytics uses a unique identifier to attribute collected analytics to a specific user. By default, the SDK uses the contact key as this identifier, called the PIID. Your app can explicitly set this value.
The Mobile Push SDK has an optional configuration option called useLegacyPiIdentifier. This option replaces an absent or empty PIID with the MobilePush contact key. If this configuration option is false, the SDK doesn’t replace an absent or empty PIID. Review Configure the SDK section to configure the SDK with pianalytics and useLegacyPiIdentifier.
To ensure future compatibility, we recommend explicitly setting the PIID. The useLegacyPiIdentifier configuration option will be deprecated in a future release.
This code example shows how to set and clear the PIID using version 10 of the SDK.
For version 8 of the SDK, use this code.
If you use version 7 of the SDK, use this code.
The methods listed in this section integrate your mobile app with Einstein Recommendations. To use these methods, you must have an existing Einstein Recommendations deployment, and you must enable the pianalytics option when you configure your SDK.
To track the contents of an in-app shopping cart, use the method shown in this example. For more information about this method’s general use with Einstein Recommendations, review Track Items in Shopping Cart.
This code example shows how to track the contents of an in-app shopping cart using version 10 of the SDK.
For version 8 of the SDK, use this code.
If you use version 7 of the SDK, use this code.
To track a purchase made through your mobile app, use the method shown in this example. For more information about this method’s general use with Einstein Recommendations, review Track Purchase Details.
This code example shows how to track a purchase made through your mobile app using version 10 of the SDK.
For version 8 of the SDK, use this code.
If you use version 7 of the SDK, use this code.
To implement page-view analytics in your app, use the method shown in this example. For more information about this method’s general use with Einstein Recommendations, see Track Items Viewed.
This code example shows how to implement page-view analytics in your app using version 10 of the SDK.
If you use version 8 of the SDK, use this code.
For version 7 of the SDK, use this code.
Rights of ALBERT EINSTEIN are used with the permission of The Hebrew University of Jerusalem. Represented exclusively by Greenlight.