SDK 구성
build.gradle (app) 파일 내에 임포트해준다.
dependencies {
...
implementation 'io.branch.sdk.android:library:5.+'
implementation 'com.google.android.gms:play-services-ads-identifier:17.1.0+'
implementation 'androidx.browser:browser:1.0.0'
...
}
Branch 대시보드 내 Configure 페이지에서 앱 상세 정보를 입력해준다.
Android - I have on Android App 체크박스를 체크해주고 앱을 열 수 있는 스킴을 등록해준다. 예를 들면 testapp:// 이런 식으로. 앱이 스토어에 등록된 상태라면 스킴을 통해 앱이 열리지 않을 경우 이동할 스토어 링크와 앱 패키지명을 입력해 준다. 패키지명은 정확히 입력해 주어야 한다.
대시보드 구성을 모두 입력하고 나면 하단 save 버튼을 눌러준다.
딥링크를 통해 앱이 바로 열리게 하려면 Enable App Link 또한 체크해 주어야 한다.
SHA256 (앱 서명 인증서)은 터미널을 통해 확인할 수 있다.
>keytool -list -v -alias ${key alias} -keystore ${key store path}
Enter keystore password:
위와 같이 터미널에 명령어를 입력하고 비밀번호를 입력하고 뜨면 key password를 입력하면 된다. 앱 서명 인증서는 .jks 확장자로 되어 있다.
<application>
<activity
android:name=".LauncherActivity"
android:launchMode="singleTask"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- Branch URI Scheme -->
<intent-filter>
<data android:scheme="yourapp" android:host="open" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<!-- Branch App Links - Live App -->
<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="example.app.link" />
<data android:scheme="https" android:host="example-alternate.app.link" />
</intent-filter>
<!-- Branch App Links - Test App -->
<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="example.test-app.link" />
<data android:scheme="https" android:host="example-alternate.test-app.link" />
</intent-filter>
</activity>
<!-- Branch init -->
<meta-data
android:name="io.branch.sdk.BranchKey"
android:value="key_live_kaFuWw8WvY7yn1d9yYiP8gokwqjV0Sw" />
<meta-data
android:name="io.branch.sdk.BranchKey.test"
android:value="key_test_hlxrWC5Zx16DkYmWu4AHiimdqugRYMr" />
<meta-data
android:name="io.branch.sdk.TestMode"
android:value="true" />
</application>
- example.test-app.link -> Configure > 링크 도메인 ex) test.app.link
- example-alternate.test-app.link -> 대체 링크 도메인 ex) test_alternate.app.link
- io.branch.sdk.BranchKey : Account Setting > Branch Key ex) test.app.link
- io.branch.sdk.BranchKey.test : Branch Key (Test Mode) ex) test_alternate.app.link
앱 디버그 버전을 통해 테스트키를 사용한 테스트를 하려면 TestMode "true"를 입력해 주어야 한다.
아니면 Branch.enableTestMode() 를 통해 테스트모드를 사용할 수도 있다.
Track Event
앱 내에서 사용자의 참여 이벤트를 추적할 수 있는 기능이다. Branch 문서에는 미리 정의되어있는 이벤트들이 여러개 있고, 사용자 정의 이벤트명을 새로 생성할 수도 있다. 스탠다드 이벤트를 사용할 땐 BRANCH_STANDARD_EVENT.VIEW_ITEM 이벤트명을 사용할 때 이런식으로 코드를 작성한다.
BranchEvent(BRANCH_STANDARD_EVENT.VIEW_ITEM).addContentItems(buo).logEvent(context)
사용자 정의 이벤트(Custom Event)를 트래킹하는 코드이다. 아래와 같은 코드는 Some Custom Event 라는 이벤트에 대한 BranchEvent 인스턴스를 생성하고, addCustomDataProperty 를 통해 함께 기록할 데이터 속성을 추가한다.
logEvent() 를 실행하면 연결된 Branch 대시보드에 이벤트가 기록된다.
BranchEvent("Some Custom Event")
.addCustomDataProperty("Key1", "value1")
.addCustomDataProperty("Key2", "value2")
.logEvent(this);
전송된 이벤트는 브랜치 대시보드에서 트래킹할 수 있다. 데이터 반영이 바로 바로 되지는 않는 느낌이었는데, 대시보드 왼쪽 메뉴창에서 LiveView 탭을 클릭해 filter를 custom event로 설정하면 실시간으로 들어오는 이벤트를 좀 더 빨리 확인할 수 있다.
참고: https://help.branch.io/developers-hub/docs/android-sdk-overview
'Android' 카테고리의 다른 글
[Android] 포그라운드 서비스 사용 (Foreground Service) (1) | 2024.09.24 |
---|---|
[Android] Widget 에서 ListView 사용하여 데이터 노출하기 (2) | 2023.10.12 |
[Android] 딥링크 / URI Scheme 방식 사용하기 (0) | 2023.04.04 |
[Android] Naver Map Api로 네이버 지도 사용하기 (0) | 2022.04.07 |