SFMCSdk.configure(applicationContext asApplication,SFMCSdkModuleConfig.build{
pushModuleConfig =MarketingCloudConfig.builder().apply{// Other configuration valuessetAnalyticsEnabled(true)// Enable ET Analytics, default = falsesetPiAnalyticsEnabled(true)// Enable Predictive Intelligence Analytics, default = false/*
To explicitly control PI analytic attribution setUseLegacyPiIdentifier to false
and set a value for the Predictive Intelligence Identifier in the SDK's AnalyticsManager.
*/setUseLegacyPiIdentifier(false)}.build(applicationContext)}){// TODO handle initialization status}
7.x
MarketingCloudSdk.init(applicationContext asApplication,MarketingCloudConfig.builder().apply{// Other configuration valuessetAnalyticsEnabled(true)// Enable ET Analytics, default = falsesetPiAnalyticsEnabled(true)// Enable Predictive Intelligence Analytics, default = false/*
To explicitly control PI analytic attribution setUseLegacyPiIdentifier to false
and set a value for the Predictive Intelligence Identifier in the SDK's AnalyticsManager.
*/setUseLegacyPiIdentifier(false)}.build(applicationContext)){// TODO handle initialization status}
Integrate Einstein Recommendations and Collect API
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, also known as the Predictive Intelligence Identifier (PIID). Your app can explicitly set this value.
If the PIID is unset or null, and the SDK is set to use the Legacy PIID, it uses the Contact Key instead.
Important
Example: Analytic Attribution
8.x
SFMCSdk.requestSdk{ sdk ->
sdk.mp{
val analyticsManager = it.analyticsManager// Set the PI ID
analyticsManager.piIdentifier="developer@salesforce.com"// Clear the PI ID
analyticsManager.piIdentifier=null}}
7.x
MarketingCloudSdk.requestSdk{
val analyticsManager = it.analyticsManager// Set the PI ID
analyticsManager.piIdentifier="developer@salesforce.com"// Clear the PI ID
analyticsManager.piIdentifier=null}
Integration Methods
Use the following methods to 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.
Track Cart
To track the contents of an in-app shopping cart, use trackCartContents(), as shown in the following example. For more information about this method’s general use with Einstein Recommendations, see Track Items in Shopping Cart.
8.x
SFMCSdk.requestSdk{ sdk ->
sdk.mp{
val analyticsManager = it.analyticsManager
val cartItem =PiCartItem("Burger",2,2.99,"burger_123")
val cart =PiCart(listOf(cartItem))
analyticsManager.trackCartContents(cart)}}
7.x
MarketingCloudSdk.requestSdk{
val analyticsManager = it.analyticsManager
val cartItem =PiCartItem("Burger",2,2.99,"burger_123")
val cart =PiCart(listOf(cartItem))
analyticsManager.trackCartContents(cart)}
Track Conversion
To track a purchase made through your mobile app, use trackCartConversion(), as shown in the following example. For more information about this method’s general use with Einstein Recommendations, see Track Purchase Details.
8.x
SFMCSdk.requestSdk{ sdk ->
sdk.mp{
val analyticsManager = it.analyticsManager
val cartItem =PiCartItem("Burger",2,2.99,"burger_123")
val cart =PiCart(listOf(cartItem))
val order =PiOrder(cart,"ABC1234",4.99,.2)
analyticsManager.trackCartConversion(order)}}
7.x
MarketingCloudSdk.requestSdk{
val analyticsManager = it.analyticsManager
val cartItem =PiCartItem("Burger",2,2.99,"burger_123")
val cart =PiCart(listOf(cartItem))
val order =PiOrder(cart,"ABC1234",4.99,.2)
analyticsManager.trackCartConversion(order)}
Track Page Views
To implement page-view analytics in your app, use trackPageView(), as shown in the following example. For more information about this method’s general use with Einstein Recommendations, see Track Page View.
8.x
SFMCSdk.requestSdk{ sdk ->
sdk.mp{
val analyticsManager = it.analyticsManager// trackPageView() requires, at a minimum, a String representing the in-app URL to be tracked.// Additional overloaded methods are available. Refer to the Javadoc for details.
analyticsManager.trackPageView("url")
analyticsManager.trackPageView("url","title")
analyticsManager.trackPageView("url","title","item")
analyticsManager.trackPageView("url","title","item","searchTerms")}}
7.x
MarketingCloudSdk.requestSdk{
val analyticsManager = it.analyticsManager// trackPageView() requires, at a minimum, a String representing the in-app URL to be tracked.// Additional overloaded methods are available. Refer to the Javadoc for details.
analyticsManager.trackPageView("url")
analyticsManager.trackPageView("url","title")
analyticsManager.trackPageView("url","title","item")
analyticsManager.trackPageView("url","title","item","searchTerms")}
Track Inbox Message Opens
To track analytics for inbox messages, use trackInboxOpenEvent(). This method sends the open analytic value to Marketing Cloud Engagement, as shown in the following example. The SDK automatically provides analytics for message downloads.
8.x
SFMCSdk.requestSdk{ sdk ->
sdk.mp{
val analyticsManager = it.analyticsManager
analyticsManager.trackInboxOpenEvent(message asInboxMessage)}}
7.x
MarketingCloudSdk.requestSdk{
val analyticsManager = it.analyticsManager
analyticsManager.trackInboxOpenEvent(message asInboxMessage)}
Rights of ALBERT EINSTEIN are used with the permission of The Hebrew University of Jerusalem. Represented exclusively by Greenlight.