-
Notifications
You must be signed in to change notification settings - Fork 0
Android Instructions
This library is available from Maven github repository.
- Maven github repository
repositories {
maven {
url = uri("https://maven.pkg.github.com/persado/eapi-mobile-sdk")
credentials {
username = "github_username"
password = "created_token"
}
}
}Note: To create a token you need to:
- Login to your GitHub account
- Go to Settings > Developer settings > Personal access tokens
- Create a token with privilege
read:packages Download packages from GitHub Package Registry
Package name is com.persado.enterprise.apiclient
latest_version can be identified as the latest release. This example is using version 0.4.0
Add the dependency to your dependencies
- groovy
dependencies {
// ...
implementation "com.persado.enterprise.apiclient:mobilesdk-android:${latest_version}"
}- kts
dependencies {
implementation("com.persado.enterprise.apiclient:mobilesdk-android:${latest_version}")
}Add permissions to AndroidManifest.xml
<manifest>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>You must initialize the PSDClient in your applicaton. PSDClient needs an application identifier ("app-id") which will be given to users by Persado PSDClient can be initialized only asynchronous. Asynchronous happens in the background without delaying other processing. You can access the content as long as the procedure happened successfully and there are no errors.
Errors can be accessible from the callback method.
- Internet connection was not available [timestamp]
- Persado unavailable to initialize sdk
- No Persado campaigns configured for requested app id
- Something went wrong during Persado sdk initialization [cause]
/* Optional values in PSDClient.Builder(appId) are:
1. env : enum Environment (LOCAL, QA, QAAWS, STG, PROD) default value PROD.
sets the PersadoAPI environment
2. qaMode : Boolean default value false -> fetch LIVE and EXPIRED campaigns
ability to get campaigns that are in DRAFT, PENDING and SCHEDULED state
3. userAttributes : Map<String,String> default value empty map. Map key value should follow a naming convention.
Accepted key values should only contain alphanumeric characters and _ -> available from version 0.4.0,
gives the ability to pass user attributes that are used in content determination for specific campaign types
*/
PSDClient.Builder("app-id").build().initialize{success, errorMessage ->
if (success) {
/* content method here */
} else {
/* errorMessage will contain one of the error messages described above */
log(errorMessage)
}
}
// Example with user attributes
PSDClient.Builder("app-id").userAttributes(hashMapOf( "loyalty_points" to "900")).build()
.initialize{success, errorMessage ->
if (success) {
/* content method here */
} else {
/* errorMessage will contain one of the error messages described above */
log(errorMessage)
}
}This is a simple example that just gets the text content served from PersadoAPI regardless and sets it as a value to a text view. In different content types the usage of the returned content might differ. During initialization all campaigns that are bundled to the given app-id are stored in the application storage. There are two ways to identify which campaigns you want to work with:
- Campaign identifier: unique campaign identifier given by the system
- Campaign label: user friendly name given during the campaign configuration (ex. december_discount)
val campaignIdentifiers = PSDContent().getPSDResponse()?.variantResponseMap?.keys
val campaignLabels = PSDContent().getCampaignLabels()From set campaignIdentifiers or campaignLabels (this value could be null) you can select an identifier and find the touchpoints available for this.
val touchpoints = PSDContent().getCampaignContent("campaign_identifier")?.touchpoints
val touchpoints = PSDContent().getCampaignContentByLabel("campaign_label")?.touchpointsSet content to text view example:
fun setPersadoContent(){
setContentView(R.layout.activity_main)
val tv: TextView = findViewById(R.id.text_view)
// campaign identifier
val tp: TouchpointVariantResponse? =
PSDContent().getTouchpointContent("campaign_identifier", "touchpoint_name")
// or campaign label
val tp: TouchpointVariantResponse? =
PSDContent().getTouchpointContentByLabel("campaign_identifier", "touchpoint_name")
if (tp != null) {
tv.text = tp.content
}
}
//asynchronous call the method as a callback in initialization
PSDClient.Builder("your app-id").build().initialize{success, errorMessage ->
if (success) setPersadoContent()
}
There is the ability to send tracking events (VIEW,CLICK,CONVERT) to PersadoAPI. This feature is available only for:
- Campaigns that have been initialized for the given application identifier(key)
- Campaign that have the tracking feature enabled
- Users that has the tracking enabled on their device
Errors can be accessible from the callback method.
- Internet connection was not available [timestamp]
- Persado unavailable to track event
- No Persado campaigns configured for given campaign identifier
- Tracking is disabled for given campaign identifier
- User opted out of tracking
- Something went wrong during Persado sdk [cause]
/* Optional value in PSDTrack :
* env : enum Environment (LOCAL, QA, QAAWS, STG, PROD) default value PROD.
sets the PersadoAPI environment
* userAttributes : Map<String,String> default value empty map.
Map key value should follow a naming convention.
Accepted key values should only contain alphanumeric characters and _ -> available from version 0.4.0,
gives the ability to pass user attributes that are used in content determination for specific campaign types
Parameters
trackAction: enum TrackAction CLICK, CONVERT, VIEW)
campaign_identifier: String
*/
fun trackPersado(){
PSDTrack().userAttributes(hashMapOf( "loyalty_points" to "900"))
.track(TrackAction.CLICK,"campaign_identifier")
}
//access the errorMessages
fun trackPersado(){
PSDTrack()
.track(TrackAction.CLICK,"campaign_identifier"){
success, errorMessage -> {
if(success) log("Tracking event sent")
else log(errorMessage)
}
}
}
// Given the examples above you can use campaign label instead of campaign identifier
PSDTrack()
.trackByCampaignLabel(TrackAction.CLICK,"campaign_label")
PSDTrack()
.trackByCampaignLabel(TrackAction.CLICK,"campaign_identifier"){
success, errorMessage -> {
if(success) log("Tracking event sent")
else log(errorMessage)
}
}
//asynchronous call the method as a callback in initialization
PSDClient.Builder("your app-id").build().initialize{success,error->{
if(success) trackPersado()
}
}