Class Evergage

This class is primarily used to initialize, configure, and start Marketing Cloud Personalization.

Tracking user interactions should typically be done from an Activity. For the APIs, see getScreenForActivity(Activity) and Context.

First initialize Personalization via initialize(Application) in your custom Application implementation, within Application.onCreate(). Then provide the app's Personalization configuration and start Personalization using start(String, String). Finally, when the user is logged in, we recommend to call setUserId(String) to correlate user activity across devices.

To add information about the user, see setUserId(String) and setUserAttribute(String, String). In the examples above, setting the userId provides Personalization with the user's authenticated ID. This could also have been called later, if the user's ID was not known at startup, and would then be sent with subsequent events. Likewise, if your users belong to an account, see setAccountId(String) and setAccountAttribute(String, String).

To easily and codelessly manage test campaigns from the device in debug/debuggable builds, the app can be configured to use its Personalization-generated URL Scheme. For more information, see EvergageActivity and the Testing guide.

Once start(String, String) has been called at app launch, the Personalization client will track user activity, send any applicable events to the Personalization server, and receive campaigns in response. Personalization will monitor network availability and store events if necessary, sending them when the network becomes available again.

For information on tracking screens, see the Tracking guide.

Personalization can track how the user views and interacts with articles, blogs and products which are collectively called items. Personalization understands the actions that are possible on these items (View, Comment, Purchase, etc.) and also how they relate to each other (categories, brands, keywords, etc.). For more information, see the Tracking guide and Context.

Campaigns may be served in response to actions generated by the user interacting with the app,

  • "In-App Message" campaigns are automatically handled by Personalization.
  • Custom "Data" campaigns are handled by app-defined code. For more information, see Mobile Data Campaigns and Campaign.
MethodDescriptionModifier and Type
getAccountId()Returns the accountId, after set via setAccountId(String)abstract java.lang.String
getAnonymousId()The user's anonymous ID, which will be used if no authenticated ID is specified for the user via setUserId(String).abstract java.lang.String
getGlobalContext()When a Screen/Activity is available, the same methods on Screen (which extends Context) should always be used over this global context, because Screen methods enable that screen to receive campaigns in response to certain actions.abstract Context
getInstance()Get the Personalization singleton.static Evergage
getScreenForActivity(android.app.Activity activity)Gets the Personalization Screen associated with the specified Activity.abstract Screen
getUserId()The authenticated user's ID, once set via setUserId(String)abstract java.lang.String
initialize(android.app.Application application)Initialize Personalization by providing the Application from onCreate().static void
processIntent(android.content.Intent intent)Advanced: Manually provide an Intent to Personalization for processing.abstract boolean
reset()Advanced: Resets Personalization so start(String, String) can be called again with a different dataset, in order to support an app that changes its server environment (production, demo, QA, etc) and wants to change the Personalization dataset accordingly.abstract void
setAccountAttribute(java.lang.String attributeName, java.lang.String attributeValue)Sets an attribute (a name/value pair) on the account.abstract void
setLogLevel(int logLevel)Allows developers to adjust the threshold level of Personalization messages to log.static void
setUserAttribute(java.lang.String attributeName, java.lang.String attributeValue)Sets an attribute (a name/value pair) on the user.abstract void
setUserId(java.lang.String userId)The authenticated user's ID.abstract void
start(java.lang.String accountKey, java.lang.String dataset)Configures Personalization with the specified account and dataset, and starts sending events.abstract void

Initialize Personalization by providing the Application from onCreate(). This method enables Personalization to follow Activities, so it may provide activity-related APIs & analytics, and also suspend operations while the app is in the background.

This is a required method.

Separate from start(String, String), in order to support rare cases where start must be delayed.

Parameters

ParameterDescription
applicationThe Application from onCreate()

Get the Personalization singleton. Be sure to first call initialize(Application) from the Application's onCreate().

Returns

The Personalization singleton.

Configures Personalization with the specified account and dataset, and starts sending events. Recommended to call from Application.onCreate(). For example code, see the Startup section in this article. Once started, subsequent calls to start will have no effect, unless reset() has been called due to an environment change.

Parameters

ParameterDescription
accountKeyAccount within Personalization to use.
datasetDataset within the Personalization account to use.

See Also

This is an advanced method.

Resets Personalization so start(String, String) can be called again with a different dataset, in order to support an app that changes its server environment (production, demo, QA, etc) and wants to change the Personalization dataset accordingly.

Reset will clear settings, unsent actions, held campaigns, test campaign settings, userId, accountId, and unsent attributes.

Reset will keep existing campaign handlers, current screen visibility and items being viewed, since it would otherwise be cumbersome/confusing to require re-playing lifecycle methods, re-navigating to screens, re-setting items being viewed, etc.

Ideally the app will avoid environment churn:

  • On app launch, if the user must select/confirm the environment before using the app, consider delaying the call to start(String, String) to when the environment is chosen and avoid calling reset.
  • Otherwise, if the user can immediately use the app with the current environment, call start(String, String) as normal with the corresponding dataset. And when the environment later changes, and a different Personalization dataset is desired, call reset as demonstrated below.

Recommended Usage

The authenticated user's ID, once set via setUserId(String).

Returns

User's authenticated ID, if any, set via setUserId.

See Also

The user's logged-in ID. Setting this property makes it easier to find users in reports and allows Personalization to correlate one user's activity across devices. Personalization will also identify the user by a generated anonymous UUID, regardless of the value of this property. Activity using anonymous identifiers may be combined automatically once the logged-in ID is provided with this method, if Merge Anonymous Users is enabled in the Personalization UI.

Recommended to set this property whenever the app's user is logged in, including at app launch when your app determines if the user is still logged in. If the user logs out, you should set this to null, which will also set accountId to null.

Parameters

ParameterDescription
userIdThe user's authenticated ID, or null to go back to anonymous.

See Also

The user's anonymous ID, which will be used if no logged-in ID is specified for the user via setUserId(String). This ID should be passed in SmartSearch requests if the user has not logged in yet.

The anonymous ID is a UUID generated by Personalization that is unique per app installation. Activity generated while using an anonymous ID will be combined once a logged-in ID is set via setUserId(String) if Merge Anonymous Users is enabled in the Personalization UI.

Returns

User's anonymous ID, null if Personalization is disabled or not initialized.

See Also

Sets an attribute (a name/value pair) on the user. The new value will be sent to the Personalization server with the next event.

Parameters

ParameterDescription
attributeNameThe name for the user attribute.
attributeValueThe new value of the user attribute, which replaces any existing value. Set null to clear.

Returns the accountId, after set via setAccountId(String).

Returns

User's account ID.

See Also

The optional account this user belongs to. Set this property to track which of your accounts inside the Personalization dataset and account your users belong to. If account is no longer applicable, it can be set to null.

This is not your main accountKey passed in to start(ClientConfiguration).

Parameters

ParameterDescription
accountIdOptional account the user belongs to.

See Also

Sets an attribute (a name/value pair) on the account. The new value will be sent to the Personalization server with the next event.

Parameters

ParameterDescription
attributeNameThe name for the account attribute.
attributeValueThe new value of the account attribute, which replaces any existing value. Set null to clear.

Gets the Personalization Screen associated with the specified Activity.

May be null if the Activity is ignorable, if Personalization is not initialized in the application's onCreate(), if not called from main thread, or if called outside the Screen lifecycle.

Personalization automatically creates the Screen for the non-ignorable Activity in its super.onCreate() call, and destroys it in its super.onDestroy() call.

Parameters

ParameterDescription
activityThe activity for which to get an Personalization Screen.

Returns

The Screen associated with the specified Activity, or null as documented above.

When a Screen/Activity is available, the same methods on Screen (which extends Context) should always be used over this global context, because Screen methods enable that screen to receive campaigns in response to certain actions.

Methods on the global context are intended for tracking non-screen events, and as a result cannot deliver campaigns to a screen.

Returns

Context to use for non-screen actions. null if Personalization is disabled.

See Also

Advanced: Manually provide an Intent to Personalization for processing.

Typically, this method is not called directly, but instead automatically called by EvergageActivity to support easily and codelessly managing test campaigns from the device in debug/debuggable builds by opening test URLs in the mobile browser. For more information on testing your campaigns, see Testing.

However, if EvergageActivity is completely removed (not recommended), this method can be used to provide the related URLs to Personalization. Simply provide an Intent with the desired Uri. If deciding to move the intent filter to an existing app Activity, be aware that URL handling is another launch point for an Activity, potentially resulting in multiple instances/tasks with that Activity, depending on launchMode, taskAffinity, etc.

The URL formats below are not what you type into the mobile browser on the device. For more information on supported URL formats, see Testing. Android typically requires a redirect or link-tap from the mobile browser to trigger the intent-filter. The URL formats below are after that redirect/link.

Test URL formats

PurposeURL FormatDescription
Test all campaigns<URLScheme>://test/allIn addition to default behavior of showing mobile campaigns in Published state, also show mobile campaigns that are in Test state. All campaign rules will still be active.
Test a specific experience<URLScheme>://test/<ExpId>In addition to default behavior of showing mobile campaigns in Published state, also show the particular experience of a mobile campaign, regardless of that campaign's state and rules that normally determine when its shown.
Stop testing<URLScheme>://test/noneReturn to the default behavior of showing mobile campaigns in Published state only.

For the URL formats listed in the preceding table:

  • <URLScheme> is the Personalization-generated URL scheme for the app, which is located in the Personalization UI: Select Dataset, then Settings > Sources > Apps > (this app) > URL Scheme: (format "evgxxxxx").
  • <ExpID> is the ID of a specific campaign experience, which can be found in the Personalization UI: Select Dataset, then Campaigns > Campaign Summary of the campaign the experience is in.
  • These URLs do not aggregate or combine. The most recent one determines the behavior.
  • Testing lasts for 30 minutes, or until app termination or another test URL is entered.

Parameters

ParameterDescriptionReturns
intentThe Intent for Personalization to processtrue, if the Intent was Personalization-specific

Allows developers to adjust the threshold level of Personalization messages to log. Usage of this method is typically unnecessary. For initial default levels, see LogLevel.

If you're using this method, you may call it before initialize(android.app.Application).

Recommended to use only during development in DEBUG builds:

Parameters

ParameterDescription
logLevelSee LogLevel