안드로이드 인스턴트 앱

Overview

At the 2017 Google IO, Google launched the public version of Instant Apps for developers to adopt and build on. Instant Apps are a way to load a partial section (or split as Google refers to them), without the user having to visit the Play Store and install your app. In effect, it's instant access to your native app. If you have been using a website as a fallback when your full Android app is not installed, an Instant App is an alternative. You'll have to choose between mobile web and your Instant App on Android so make sure you plan out your integration!

Branch는 아래와 같이 Instant App에서 기본 Branch 링크 사용을 매우 쉽게 시작할 수 있도록 했습니다. 이 페이지의 가이드는 새로운 Instant App에서 Branch를 활성화하기 위한 전체 설정 프로세스를 안내합니다.

2106

📘

Instant App이 되도록 안드로이드 앱 설정하기

This guide is not about how to configure your Android app to be an Instant App. Please see Google's documentation for detailed instructions on how to do this. Come back to this guide when you're ready to enable Branch.

Instant App에 Branch를 사용하는 이유

Google의 가이드를 따르면 자신의 웹 링크를 안드로이드 앱 링크로 연동하여 Instant App을 트리거 합니다. 그렇다면 Branch는 무엇을 할 수 있을까요? 먼저 Branch가 Instant App과 어떻게 작동하는지 설명하겠습니다. Branch는 자체 웹 도메인 외에 Android 앱 링크에 등록 할 새로운 웹 도메인 역할을 하거나 매니페스트의 유일한 도메인 역할을 합니다. Branch는 귀하의 링크 역할을 하는 것이죠.

다음은 Branch 링크 및 Instant App의 잠재적 사용 사례 목록입니다.

  1. Branch는 모든 앱에 대해 커스텀 도메인(yourapp.app.link 또는 화이트라벨 방식)을 제공하므로 맞춤화 웹 링크를 호스팅 합니다. 웹 사이트가 없는 경우 Google에서 모든 Android 앱 링크 요구 사항을 처리하여 자동으로 assetlinks.json 파일을 서정하고 호스팅 할 수 있습니다.
  2. 인기 있는 웹 사이트를 보유하고 있고 Android 앱 링크를 설정했다면 모든 웹 링크가 Instant App을 트리거 하는 것을 원하지 않을 것입니다. Instant App은 전체 앱 기능의 일부만 지원합니다. Branch 링크 도메인 및 경로에서만 트리거 하도록 Instant App을 설정한 다음 Branch 사용을 활용하여 유저 Instant App에 연결되는 시기를 제어 할 수 있습니다.
  3. Branch can measure and attribute clicks, installs and custom conversion events back to the Branch tracking link for all visits to your Instant App, which are visible on the dashboard.
  4. Branch 링크를 사용하여 안드로이드 Instant App에서 전체 안드로이드 앱으로의 지연된 딥링크(Deep Link)를 사용할 수 있습니다. Instant App에서 정식 안드로이드 앱으로 유저를 푸시하는 기능을 구축할 가능성이 높으며 Branch는 이러한 전환에 작용할 수 있습니다.
  5. Branch can measure and attribute clicks, installs and custom conversion events inside your full native Android App for users who were referred from an Instant App, showing the conversion from click -> Instant App -> Full App on the dashboard.

Setup

Instant App을 위한 Branch 연동

So you're convinced. Let's get started! If at any time, you need a real example, you can check out a full demo application on our Github. We've replicated our original Android demo application and modified it to support Android Instant Apps.

Branch SDK 초기화

If you plan on deep linking from your Android Instant App to your full Android app after its installed, you'll be utilizing the Play Install Referrer Library, which is bundled with the SDK. The referrer library returns deeplinking information asynchronously, which may impact your startup time. For that purpose, the SDK provides the method, setPlayStoreReferrerCheckTimeout, which defines how long the Branch initialization will wait for the Google Play Referrer, the default timeout is 1.5 seconds. If you want to set a different timeout, make sure you call this method before SDK initialization as shown below.

같은 섹션에서 코드 스니펫을 다음으로 바꿉니다.

public class MyApplication extends Application {
  ...
  @Override
  public void onCreate() {
    super.onCreate();
    // This tells the Branch initialization how long to wait for the Google Play Referrer before proceeding. (Default: 1.5 second)
    Branch.setPlayStoreReferrerCheckTimeout(1000L);
  
    // Initialize the Branch SDK
    Branch.getAutoInstance(this);
  }
  ...
}

In Section https://help.branch.io/developers-hub/docs/android-instant-apps#add-your-branch-keys-and-register-for-install-referrer replace code snippet with:

<application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:supportsRtl="true"
        android:name=".MyApplication">

  <meta-data android:name="io.branch.sdk.TestMode" android:value="false" /> <!-- Set to true to use Branch_Test_Key -->
  <meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_my_live_key" />
  <meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_my_test_key" />

</application>
public void onCreate() {
  super.onCreate();
  // Branch's InstallListener is needed to deferred deep link from an Android Instant App to a full app
  // This tells the Branch initialization how long to wait for the Google Play Referrer before proceeding. (Default: 1 second)
  Branch.setPlayStoreReferrerCheckTimeout(1000L);

  // Initialize the Branch SDK
  Branch.getAutoInstance(this);
}

Branch 키를 추가하고 설치 리퍼러 등록

Instant Apps can be rather confusing as there are many different manifests, but you want to find the Manifest that contains your application tags. Make sure your Application class name is defined here, and then specify the Branch keys inside the application element.

<application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:supportsRtl="true"
        android:name=".MyApplication">

  <meta-data android:name="io.branch.sdk.TestMode" android:value="false" /> <!-- Set to true to use Branch_Test_Key -->
  <meta-data android:name="io.branch.sdk.BranchKey" android:value="key_live_my_live_key" />
  <meta-data android:name="io.branch.sdk.BranchKey.test" android:value="key_test_my_test_key" />

  <receiver android:name="io.branch.referral.InstallListener" android:exported="true">
    <intent-filter>
       <action android:name="com.android.vending.INSTALL_REFERRER" />
    </intent-filter>
  </receiver>
</application>

Branch 링크를 Android 앱 링크로 설정

이 가이드에서는 이전에 Android 앱 링크용 Branch를 이미 설정했다고 가정합니다.

Now, you simply need to edit the above manifest and paste in the following snippet inside the desired activity. Then you'll need to replace the xxxx with your own custom subdomain which will be visible on the Branch link settings dashboard at the bottom of the page. If you're using a custom subdomain, you can find the advanced instructions in the above link regarding configuring Android App Links.

<application
  ......>

<activity...
  <intent-filter android:autoVerify="true">
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:scheme="https" android:host="xxxx.app.link" />
      <data android:scheme="https" android:host="xxxx-alternate.app.link" />
  </intent-filter>
</activity>

</application>

Branch 링크의 커스텀 경로 지정

Optionally, when you create shortened Branch links, you can specify a alias parameter (described here) in the creation flow to define a custom path (e.g. https://example.app.link/product/id12345 or any custom strings). This can be helpful if you are managing multiple Instant App paths.

Branch 딥링크(Deep Link) 데이터 검색

Add Branch sessionBuilder()...init() in Activities which are configured to open from a link click in order to receive the deep link params.

protected void onStart() {
    super.onStart();
    Branch.sessionBuilder(this).withCallback(new Branch.BranchReferralInitListener() {
        @Override
        public void onInitFinished(JSONObject referringParams, BranchError error) {
            Log.d(""Branch"", ""onInitFinished() with deep link data: "" + referringParams);
        }
    }).init();
}

Instant App에서 전체 앱으로의 딥링킹(Deep Linking) 설정

Now, the user has arrived in your Instant App and you're ready to convert them to install your full native app. Don't worry, Branch as got your covered! We have overridden the default showInstallPrompt with a method that auto configures the Google Play prompt with all of the deep link data you need to carry context through install. Additionally, we can provide you the full set of attribution on how many users convert through this prompt.

Branch SDK provides convenient methods to check for app types and full app conversion. This eliminates the dependency on Google IA support SDK ('com.google.android.instantapp'). Here are some of the methods that makes life easy

  • Branch#isInstantApp()

This convenience methods checks whether the current version of app running is Instant App or Full Android App to allow you convenience

  • Branch#showInstallPrompt()

This methods shows an install prompt for the full Android app, allowing you an easy way to pass Branch referring deep data to the full app through the install process. Similar to how deferred deep linking works for Branch normally, the full app will receive the deep link params in the handle callback.

The below example shows how to create a custom Branch Universal Object, the associate it with the installation prompt that will be passed through to your full native Android app after the user installs.

if (Branch.isInstantApp(this)) {
  myFullAppInstallButton.setVisibility(View.VISIBLE);
  myFullAppInstallButton.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
       BranchUniversalObject branchUniversalObject = new BranchUniversalObject()
            .setCanonicalIdentifier("item/12345")
            .setTitle("My Content Title")
            .setContentDescription("My Content Description")
            .setContentImageUrl("https://example.com/mycontent-12345.png")
            .addContentMetadata("property1", "blue")
            .addContentMetadata("property2", "red");

      Branch.showInstallPrompt(myActivity, activity_ret_code, branchUniversalObject);
    }
  });
} else {
  myFullAppInstallButton.setVisibility(View.GONE);
}

Troubleshooting

Instant App 테스트

You can create Branch links in a variety of ways, but to quickly test your Branch integration, head to the quick links section on our dashboard and create a link. If you configured deep linking via a specific key in the deep link data, make sure that you add it to your quick link to properly simulate a real live Branch link.