Adobe Launch Android SDK

向您的 Adobe Marketing Cloud 应用添加 Branch 深度链接和归因的功能。借助 Branch 的链接平台,移动开发人员和营销者可以通过世界一流的深度链接和归因来发展他们的移动业务。

❗️

Google Play Services 17+版本

2019年6月 Google Play Services 进行的一次重大更新导致 Branch 的 Android SDK(以及其他各种跨平台 SDK,例如 Unity)停止收集 Android AID。

To ensure Branch deep linking and attribution continue to work, you must follow Google's update instructions here.

如果您运行的 Google Play Services 版本低于17,则无需更新。

功能

  1. 使用 Adobe SDK 追踪的所有事件将自动发送到 Branch,无需进行任何其他工作
  2. 所有核心 Branch 功能均可访问
  3. The SDK will automatically pick up the Adobe ID's

要求

  • Android API 级别16或更高
  • Adobe 核心平台

👍

不需要 Branch SDK

由于 Adobe Branch 扩展是自动包含 Branch SDK 的子依赖项的包装,因此您无需(我们也不建议)在应用中单独使用 Branch SDK。

示例应用

An example app can be found in the AdobeBranchExtension-Android repository, in the AdobeBranchExample
项目。

安装及使用

❗️

请注意,Adobe Experience Platform(AEP)SDK 和 AdobeMobileLibrary 不能共存于同一项目中。

这是有关如何在应用中使用 AdobeBranchExtension 的简要概述:

  1. You'll need to configure your app and get a Branch API key in the Branch Metrics dashboard. You can read more about configuring your dashboard in the Branch docs here.

  2. 对于应用集成,您需要按照此处 Branch 文档中所述的说明进行操作(忽略 “Load Branch” 和 “Initialize Branch” 部分):

  3. 要进行深度链接,您需要将 Branch domain,应用 URI scheme 和 Branch Key 添加到应用的 Manifest 文件中。

  4. 在 Adobe 操作后台 (Dashboard)中,激活 Branch 并将您的 Branch key 添加到应用的配置中。

418
  1. 将 AdobeBranchExtension 添加到应用的 build.gradle。
    implementation 'io.branch.sdk.android:adobebranchextension:1.+'

  2. Register the Branch AdobeBranchExtension with MobileCore in configureWithAppID

public class CustomApplicationClass extends Application {
    private static final String MY_ADOBE_APP_ID = "launch-{adobe app guid}-development";

    @Override
    public void onCreate() {
        super.onCreate();

        MobileCore.setApplication(this);

        try {
            AdobeBranchExtension.registerExtension(this);
            MobileCore.start(new AdobeCallback () {
                @Override public void call(Object o) {
                    MobileCore.configureWithAppID(ADOBE_APP_ID);
                }
            });
        } catch (InvalidInitException ignored) {}
    ...
    }
  1. Initialize Branch session and register BranchReferralInitListener in your launcher activity's onStart method. You can see some best practices on deep link routing in this doc
AdobeBranch.initSession(new Branch.BranchReferralInitListener() {
  @Override
    public void onInitFinished(JSONObject referringParams, BranchError error) {
    try {
      // Retrieve deep link params and route to content appropriately
      if (referringParams.has("+clicked_branch_link") && referringParams.getBoolean("+clicked_branch_link")) {
        // Handle your Branch deep link routing in the callback
      }
    } catch (JSONException e) {
      // referringParams property doesn't exist
    }
  }
}, getIntent().getData(), this);

By default, AdobeBranch will delay session initialization by 750 milliseconds in order to wait for Adobe Launch to initialize and to collect Adobe IDs from it. If you do not wish to delay session initialization, pass in 0 as the delay parameter in the method below.

AdobeBranch.initSession(Branch.BranchReferralInitListener callback, Uri data, Activity activity, int delay)

实现 Branch 功能

Once you've added the AdobeBranchExtension and Branch, you can always use Branch features directly (with the exception of getAutoInstanceinitSessionreInitSessionsessionBuilder methods). You can learn about using the Branch features here, in the Branch documentation for Android.

Register an Event Allowlist

Selectively track certain events within Branch by registering an allowlist :

List<AdobeBranch.EventTypeSource> apiWhitelist = new ArrayList<>();
apiWhitelist.add(new AdobeBranch.EventTypeSource("com.adobe.eventType.generic.track", "com.adobe.eventSource.requestContent"));
apiWhitelist.add(new AdobeBranch.EventTypeSource("io.branch.eventType.generic.track", "io.branch.eventSource.requestContent"));

AdobeBranch.registerAdobeBranchEvents(apiWhitelist);

Note that all Adobe Events are processed by default. To optionally track events with custom names you can register an allowlist as follows:

Additional Allowlist Configuration Implementation Notes:

  • Allowlist Configuration must happen after Adobe Initialization has completed.
  • An empty allowlist will not listen for any events.
  • A null allowlist (default) will listen for all Adobe events.
  • A non-empty allowlist will listen for only those events that are in the list.

Disable Event Sharing between Adobe/Branch

To disable Event Sharing between Adobe and Branch (empty allowlist), add the following code:

// Disable event sharing by creating an empty allowlist 
List<AdobeBranch.EventTypeSource> apiWhitelist = new ArrayList<>();
apiWhitelist.add(new AdobeBranch.EventTypeSource("", ""));
AdobeBranch.registerAdobeBranchEvents(whitelist);

自动:追踪行为和状态

当您在 Adobe Launch 中追踪动作和状态时,动作和状态消息也会被发送到 Branch,并在 Branch 操作后台显示。这使您可以在 App 的操作中追踪深度链接活动和病毒共享的有效性。

如果使用 trackAction function 追踪 Adobe 事件,则自定义事件将位于 Branch 操作后台 (Dashboard)上的 “Analytics Track” 下。如果使用 dispatchEvent function 追踪 Adobe 事件,则自定义事件将位于Branch 操作后台 (Dashboard)上的自定义名称下。

private void doPurchase(View view) {
        Long timestamp = System.currentTimeMillis()/1000;

        Map<String, Object> eventData = new HashMap<>();
        eventData.put(AdobeBranch.KEY_AFFILIATION, "Branch Metrics Company Store");
        eventData.put(AdobeBranch.KEY_COUPON, "SATURDAY NIGHT SPECIAL");
        eventData.put(AdobeBranch.KEY_CURRENCY, "USD");
        eventData.put(AdobeBranch.KEY_DESCRIPTION, model.getDescription());
        eventData.put(AdobeBranch.KEY_REVENUE, model.getPrice());
        eventData.put(AdobeBranch.KEY_SHIPPING, 0.99);
        eventData.put(AdobeBranch.KEY_TAX, (model.getPrice() * 0.077));
        eventData.put(AdobeBranch.KEY_TRANSACTION_ID, UUID.randomUUID().toString());

        eventData.put("category", "Arts & Entertainment");
        eventData.put("product_id", model.getId());
        eventData.put("sku", "sku-be-doo");
        eventData.put("timestamp", timestamp.toString());

        eventData.put("custom1", "Custom Data 1");
        eventData.put("custom2", "Custom Data 2");

        Event newEvent = new Event.Builder("PURCHASE",
                "com.adobe.eventType.generic.track",
                "com.adobe.eventSource.requestContent")
                .setEventData(eventData).build();

        // dispatch the analytics event
        MobileCore.dispatchEvent(newEvent, this);
    }

Define an Allow List of Event Names

🚧

Conflict

You can either define an allow list or an exclusion list of events but you can't define both. If you don't configure any, all events will send to Branch, which is not ideal.

// Define the allow list of the event names
AdobeBranchExtension.configureEventAllowList(Arrays.asList("VIEW"));

Define an Exclusion List of Event Names

🚧

Conflict

You can either define an exclusion list or an allow list of events but you can't define both. If you don't configure any, all events will send to Branch, which is not ideal.

// Define the exclusion list of the event names
AdobeBranchExtension.configureEventExclusionList(Arrays.asList("VIEW"));

Register the AdobeBranchExtension

Once the Allow or Exclusion event names list has been configured, the AdobeBranchExtension needs to be registered.

// Register the AdobeBranchExtension
AdobeBranchExtension.registerExtension(this, true);