适用于Android的Experience Rollout扩展 android-extension-integration-guide
本指南介绍如何将Experience Rollout扩展与Android上的Adobe Experience Platform Mobile SDK集成。
先决条件 prerequisites
在实施Experience Rollout扩展之前,请确保您已:
- 在Adobe Experience Platform数据收集中配置的移动属性
- 在您的移动资产中安装和配置的Experience Rollout扩展
- Adobe Experience Cloud组织ID
- 最小SDK:API 21 (Android 5.0 Lollipop)
扩展依赖关系 extension-dependencies
Experience Rollout扩展需要以下Adobe Experience Platform扩展:
确保这些扩展已安装在数据收集移动资产中并包含在应用程序依赖项中。
在数据收集中配置Experience Rollout扩展 configure
安装扩展 install-extension
-
选择 标记 选项卡并选择您的移动属性。
-
导航到扩展 > 目录。
-
搜索 Experience Rollout扩展 并选择安装。
-
配置扩展设置:
table 0-row-2 1-row-2 2-row-2 3-row-2 设置 描述 沙盒 包含您的Experience Rollout配置的Adobe Experience Platform沙盒 应用程序Id 您的应用程序在体验转出中的唯一标识符 数据集 ID 分析事件数据的Adobe Experience Platform数据集ID -
选择保存。
-
按照发布流程更新您的配置。
获取环境文件ID environment-file-id
- 在移动资产中,导航到环境。
- 为您的环境选择 Install 列下的框图标。
- 在 移动设备安装说明 对话框中,复制环境文件ID。
将Experience Rollout扩展添加到应用程序 add-to-app
添加依赖项 add-dependencies
将Mobile SDK依赖项添加到您的项目中。 Experience Rollout扩展需要使用Mobile Core以及下面列出的与Edge相关的扩展。
将Gradle与BOM结合使用(推荐) gradle-bom
将以下依赖项添加到应用程序的build.gradle.kts文件中:
dependencies {
// Adobe Experience Platform Mobile SDK BOM
implementation(platform("com.adobe.marketing.mobile:sdk-bom:3.+"))
// Required extensions
implementation("com.adobe.marketing.mobile:core")
implementation("com.adobe.marketing.mobile:lifecycle")
implementation("com.adobe.marketing.mobile:edge")
implementation("com.adobe.marketing.mobile:edgeidentity")
// Experience Rollout extension
implementation("com.adobe.marketing.mobile:rollout")
}
使用Gradle (Groovy) gradle-groovy
dependencies {
// Adobe Experience Platform Mobile SDK BOM
implementation platform('com.adobe.marketing.mobile:sdk-bom:3.+')
// Required extensions
implementation 'com.adobe.marketing.mobile:core'
implementation 'com.adobe.marketing.mobile:lifecycle'
implementation 'com.adobe.marketing.mobile:edge'
implementation 'com.adobe.marketing.mobile:edgeidentity'
// Experience Rollout extension
implementation 'com.adobe.marketing.mobile:rollout'
}
添加权限 add-permissions
向您的AndroidManifest.xml文件添加以下权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
初始化SDK initialize-sdk
在调用任何Experience Rollout扩展API之前,初始化Application类中的Mobile SDK。 将移动属性中的环境文件ID与MobileCore.initialize一起使用,以便应用程序选取您在数据收集中发布的转出设置。
使用MobileCore.initialize mobile-core-initialize
从Android BOM版本3.8.0开始提供此API,它自动注册扩展并启用生命周期跟踪。
LoggingMode.ERROR。 请勿在版本内部版本中使用DEBUG或VERBOSE。Kotlin
import android.app.Application
import com.adobe.marketing.mobile.LoggingMode
import com.adobe.marketing.mobile.MobileCore
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
MobileCore.setLogLevel(LoggingMode.ERROR)
// Initialize with your Environment File ID from Data Collection
MobileCore.initialize(this, "YOUR_ENVIRONMENT_FILE_ID")
}
}
Java
import android.app.Application;
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
MobileCore.setLogLevel(LoggingMode.ERROR);
// Initialize with your Environment File ID from Data Collection
MobileCore.initialize(this, "YOUR_ENVIRONMENT_FILE_ID", null);
}
}
注册Application类 register-application
在AndroidManifest.xml中注册您的Application类:
<application
android:name=".MainApplication"
... >
</application>
评估上下文 evaluation-context
FeatureEvaluationContext包括定位属性(用于转出规则匹配)和可选标识(用于analytics)。
withIdentity(namespace, id)withAttributes(map)Map<String, List<String>>. 键值是转出规则使用的上下文属性名称(例如locale、platform、appVersion、deviceType)。 值是当前用户/会话的该键的候选属性值列表(例如["en_US"]或["phone"])。Kotlin
import com.adobe.marketing.mobile.rollout.FeatureEvaluationContext
val attrs = mapOf(
"locale" to listOf("en_US"),
"platform" to listOf("ANDROID"),
"appVersion" to listOf("3.0.0")
)
val ctx = FeatureEvaluationContext.builder()
.withIdentity("Email", "customer@example.com")
.withAttributes(attrs)
.build()
Java
import com.adobe.marketing.mobile.rollout.FeatureEvaluationContext;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Map<String, List<String>> attrs = new HashMap<>();
attrs.put("locale", Arrays.asList("en_US"));
attrs.put("platform", Arrays.asList("ANDROID"));
attrs.put("appVersion", Arrays.asList("3.0.0"));
FeatureEvaluationContext ctx = FeatureEvaluationContext.builder()
.withIdentity("Email", "customer@example.com")
.withAttributes(attrs)
.build();
定位属性示例 sample-attributes
locale["en_US"], ["fr_FR"]platform["ANDROID"]appVersion["3.0.0"]deviceType["phone"], ["tablet"]API 参考 api-reference
isFeatureEnable is-feature-enabled
isFeatureEnabled返回给定上下文的体验转出功能是打开还是关闭。 传递featureKey、FeatureEvaluationContext(可选定位属性和可选标识,适用于Analytics)和回调。 查看评估上下文。
签名
Kotlin
Rollout.isFeatureEnabled(
featureKey: String,
evaluationContext: FeatureEvaluationContext,
callback: AdobeCallback<Boolean>
)
Java
Rollout.isFeatureEnabled(
String featureKey,
FeatureEvaluationContext evaluationContext,
AdobeCallback<Boolean> callback);
参数
featureKeyevaluationContextFeatureEvaluationContext.builder().build()用于空上下文。 查看评估上下文。callbacktrue调用,否则通过false调用。 您还可以传递AdobeCallbackWithError<Boolean>以处理fail(...)。示例
Kotlin
import com.adobe.marketing.mobile.AdobeCallback
import com.adobe.marketing.mobile.rollout.Rollout
Rollout.isFeatureEnabled(
"new-checkout-experience",
ctx,
object : AdobeCallback<Boolean> {
override fun call(isEnabled: Boolean?) {
if (isEnabled == true) {
showNewCheckout()
} else {
showDefaultCheckout()
}
}
}
)
Java
import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.rollout.Rollout;
Rollout.isFeatureEnabled(
"new-checkout-experience",
ctx,
new AdobeCallback<Boolean>() {
@Override
public void call(Boolean isEnabled) {
if (Boolean.TRUE.equals(isEnabled)) {
showNewCheckout();
} else {
showDefaultCheckout();
}
}
}
);
getFeature get-feature
getFeature针对提供的上下文返回已评估的功能有效负载。 当您需要启用/禁用以外的功能,并且需要功能元数据或值时,请使用此API。
签名
Kotlin
Rollout.getFeature(
featureKey: String,
evaluationContext: FeatureEvaluationContext,
callback: AdobeCallback<FeatureEvaluationResult>
)
Java
Rollout.getFeature(
String featureKey,
FeatureEvaluationContext evaluationContext,
AdobeCallback<FeatureEvaluationResult> callback);
参数
featureKeyevaluationContextFeatureEvaluationContext.builder().build()用于空上下文。 查看评估上下文。callbacknull。 您还可以传递AdobeCallbackWithError<FeatureEvaluationResult>以处理fail(...)。响应
FeatureEvaluationResult
idkeyreleaseKeymetaanalyticsParamAnalyticsParam
releaseIdfeatureIdvariantId示例
Kotlin
import com.adobe.marketing.mobile.AdobeCallback
import com.adobe.marketing.mobile.rollout.FeatureEvaluationResult
import com.adobe.marketing.mobile.rollout.Rollout
Rollout.getFeature(
"new-checkout-experience",
ctx,
object : AdobeCallback<FeatureEvaluationResult> {
override fun call(feature: FeatureEvaluationResult?) {
val meta = feature?.meta
if (!meta.isNullOrEmpty()) {
applyMetaDrivenExperience(meta)
} else {
showFallbackExperience()
}
}
}
)
Java
import com.adobe.marketing.mobile.AdobeCallback;
import com.adobe.marketing.mobile.rollout.FeatureEvaluationResult;
import com.adobe.marketing.mobile.rollout.Rollout;
Rollout.getFeature(
"new-checkout-experience",
ctx,
new AdobeCallback<FeatureEvaluationResult>() {
@Override
public void call(FeatureEvaluationResult feature) {
String meta = feature != null ? feature.getMeta() : null;
if (meta != null && !meta.isEmpty()) {
applyMetaDrivenExperience(meta);
} else {
showFallbackExperience();
}
}
}
);
refreshcache refresh-cache
默认情况下,Experience Rollout扩展会按照您可以配置的计划定期从服务器同步最新转出规则和功能。 如果您需要比下一次计划同步更早的更新,请调用refreshCache以强制刷新。 典型案例包括登录后或应用程序状态发生变化而影响定位。
语法
Kotlin
Rollout.refreshCache()
Java
Rollout.refreshCache();
extensionVersion extension-version
返回Experience Rollout扩展的版本字符串。
语法
Rollout.extensionVersion(): String
示例
Kotlin
val version = Rollout.extensionVersion()
Java
String version = Rollout.extensionVersion();
API摘要 api-summary
isFeatureEnabled(featureKey, evaluationContext, callback). FeatureEvaluationContext携带规则的定位属性和analytics的可选标识。 请参阅功能评估。getFeature(featureKey, evaluationContext, callback). 返回给定上下文的已评估功能有效负载。 请参阅getFeature。refreshCache()extensionVersion()