Adjust Android SDKを使用して、アンインストールと再インストールを計測します。AdjustはPushトークンを使用することでユーザーのデバイスにサイレントPush通知を送信し、アプリが現在インストールされているかどうかを確認します。
この機能をアプリに追加するには、以下の手順に従ってください。
Uninstall and reinstall measurement is effective for apps distributed through any app store or direct download, as long as the device has Google Play Services installed. Devices without Google Play Services aren’t currently supported, such as Amazon and Huawei devices.
事前準備
はじめに、以下の設定手順をご覧ください。
要件
- Android SDK v4.12.0以降
- AndroidプロジェクトにFirebaseを追加すること
- 管理者、編集者およびカスタム編集者のユーザー権限
Google FCMをAdjustに連携する
GoogleのFirebase Cloud Messaging(FCM)APIを使用してサイレントPush通知を設定することで、アンインストールと再インストールを計測できます。 AdjustがGoogle FCMに接続するには、FCM HTTP v1 APIプライベートキーが必要です。
レガシー版のサービスキーを使用する代わりに、新しいFCM HTTP v1プライベートキーを生成してください。Googleは、2024年7月22日にCloud Messaging API(レガシー版)を終了します。影響を受けるサービス、廃止期間中の留意点、延長を申請する方法については、 Googleのドキュメントをご覧ください。
Google Cloudコンソール
1.Adjustのアンインストール・再インストール計測のカスタムアクセス権限を作成する
-
Google Cloud Consoleにアクセスします。
-
Firebaseプロジェクトに関連付けられているGoogle Cloudプロジェクトを選択します。
-
IAM & Admin を検索します。
-
サイドメニューで、 ロール(Role) を選択します。
-
+ 権限を作成 (Create Role) を選択します。
-
以下の詳細を入力します:
- Title : Adjust Uninstall
- ID : adjust_uninstall
- Role launch stage : General Availability
-
+ Add Permissions を選択します。
-
Enter property name or value フィールドに
cloudmessaging.messages.create
と入力し、検索結果から選択します。 -
cloudmessaging.messages.create オプションにチェックを入れ、 Add を選択します。
-
Create を選択します。
2.サービスアカウントを作成する
- サイドメニューから Service Accounts を選択します。
- + Create Service Account を選択します。
- Service account name フィールドに、
Adjust Uninstall Service Account
と入力します。 - Create and Continue を選択します。
- Select a role ドロップダウンを選択します。
Adjust Uninstall
を入力し、検索結果から選択します。 - 続ける(Continue) を選択します。
- Done を選択します。
3.プライベートキーを生成してダウンロードする
- 新しく作成したサービスアカウントを選択します。書式は以下のようになります:
adjust-uninstall-service-account@test3-55065.iam.gserviceaccount.com
。 - Keys タブを選択します。
- Add Key > Create new key を選択します。
- JSON > 作成 (Create) を選択します。 プライベートキーは、JSONファイルとしてコンピューターにダウンロードされます。
Adjustダッシュボードにて
AdjustとGoogle FCMを連携するために必要なプライベートキーの詳細を取得したら、AppViewのアプリ設定でアンインストール・再インストール計測を有効にする必要があります。
- プラットフォーム (Platforms) を選択します。
- 編集(EDIT) を選択します。
- Under Advanced settings , find the Record uninstall and reinstall data option.
- 接続先を追加(Add Connection) を選択します。モーダルが開き、AdjustとGoogle FCMの間に新しいパートナー接続を追加するよう求められます。
- 最近生成したFCMプライベートキーなどの必要な情報を入力します。 パートナー と サービス のフィールドは自動的に入力されます。
- 接続(Connect) を選択します。
- アプリの設定を確認し、 保存(Save) を選択します。
Adjust SDKを実装する
FCMをAdjust SDKに連携するには、以下の手順に従ってください。
-
build.gradle
ファイルに、 Firebase Messaging に必要なdependencyがあることを確認してください。dependencies {// ...implementation 'com.google.firebase:firebase-messaging:23.4.0'// ...} -
Set up a Firebase Cloud Messaging client app on Android following Google’s documentation, if you haven’t already done so.
-
デバイスのプッシュトークンをAdjust SDKにパスします。
- アプリに独自のPush通知を送信する場合は、全てのタイプのPush通知を処理するロジックを使って
FirebaseMessagingService
クラスのonMessageReceived
メソッドをオーバーライドするようにしてください。それにはアンインストールおよび再インストール計測のためのAdjustのサイレントPush通知も含まれます。
- アプリに独自のPush通知を送信する場合は、全てのタイプのPush通知を処理するロジックを使って
例
The following code snippet shows how you can extend the FirebaseMessagingService
class to pass the push token to the Adjust SDK, and to update your push notification handling logic. If you aren’t sending your own push notifications, you can skip the override of the onMessageReceived
method.
以下のようにonMessageReceived
をオーバーライドする際は、アプリが独自のPush通知を処理する方法に影響を与えないように注意してください。 以下のPush通知処理コードに変更を加えた後、アプリがフォアグラウンドで動作している間に独自のPush通知を送信するテストを実施してください。
import com.adjust.sdk.Adjustimport com.adjust.sdk.Utilimport com.google.firebase.messaging.FirebaseMessagingimport com.google.firebase.messaging.FirebaseMessagingServiceimport com.google.firebase.messaging.RemoteMessage
class MyFirebaseMessagingService : FirebaseMessagingService() {
override fun onCreate() { super.onCreate() // Fetch FCM token and set in Adjust SDK FirebaseMessaging.getInstance().token .addOnCompleteListener { task -> if (task.isSuccessful && task.result != null) { Adjust.setPushToken(task.result, applicationContext) } } }
override fun onNewToken(token: String) { super.onNewToken(token)
// Receive new FCM token and set in Adjust SDK Adjust.setPushToken(token, applicationContext) }
override fun onMessageReceived(remoteMessage: RemoteMessage) { super.onMessageReceived(remoteMessage)
// Check if message has data payload if (remoteMessage.data.isNotEmpty()) { val payload: Map<String, String> = remoteMessage.data
// Check for Adjust uninstall detection data message if (Util.isAdjustUninstallDetectionPayload(payload)) { // No handling required for Adjust data payload } else { // Handle other data payloads here } }
// Check if message has notification payload remoteMessage.notification?.let { // Handle notification payload here } }}
import com.adjust.sdk.Adjust;import com.adjust.sdk.Util;import com.google.firebase.messaging.FirebaseMessagingService;import com.google.firebase.messaging.RemoteMessage;import java.util.Map;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override public void onCreate() { super.onCreate(); // Fetch FCM token and set in Adjust SDK FirebaseMessaging.getInstance().getToken() .addOnCompleteListener(task -> { if (task.isSuccessful() && task.getResult() != null) { Adjust.setPushToken(task.getResult(),getApplicationContext()); } }); }
@Override public void onNewToken(String token) { super.onNewToken(token);
// Receive new FCM token and set in Adjust SDK Adjust.setPushToken(token, getApplicationContext()); }
@Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage);
// Check if message has data payload if (!remoteMessage.getData().isEmpty()) { Map<String, String> payload = remoteMessage.getData();
// Check for Adjust uninstall detection data message if (Util.isAdjustUninstallDetectionPayload(payload)) { // No handling required for Adjust data payload } else { // Handle other data payloads here } }
// Check if message has notification payload if (remoteMessage.getNotification() != null) { // Handle notification payload here } }}
- Adjust SDKを初期化する前に、アプリのFirebaseインスタンスを初期化します。
例
Androidプロジェクトのアプリケーションクラスの例を次に示します。アプリを起動すると同時に、Firebaseインスタンスが初期化されていることが確認できます。
import android.app.Applicationimport com.adjust.sdk.Adjustimport com.adjust.sdk.AdjustConfigimport com.google.firebase.FirebaseApp
class MyApp : Application() {
override fun onCreate() { super.onCreate()
// Initialize Firebase App FirebaseApp.initializeApp(this)
// Configure Adjust SDK // Replace {YourAppToken} with your Adjust app token val appToken = "{YourAppToken}" val environment = AdjustConfig.ENVIRONMENT_PRODUCTION val config = AdjustConfig(this, appToken, environment)
// Initialize Adjust SDK Adjust.onCreate(config) }}
import android.app.Application;import com.adjust.sdk.Adjust;import com.adjust.sdk.AdjustConfig;import com.google.firebase.FirebaseApp;
public class MyApp extends Application {
@Override public void onCreate() { super.onCreate();
// Initialize Firebase App FirebaseApp.initializeApp(this);
// Configure Adjust SDK // Replace {YourAppToken} with your Adjust app token String appToken = "{YourAppToken}"; String environment = AdjustConfig.ENVIRONMENT_PRODUCTION; AdjustConfig config = new AdjustConfig(this, appToken, environment);
// Initialize Adjust SDK Adjust.onCreate(config); }}
実装テスト
Adjustは、Adjustの本番環境で最後のアクティビティがあったデバイスからのAndroidアプリのアンインストールを確認します。
アンインストールと再インストールの計測をテストするには、デバッグビルドまたはリリースビルドのいずれかを使用してください。主な要件として、テストインストールを実行する際は、Adjust SDK環境を 本番用 に設定する必要があります。
アンインストール計測をテストする方法:
-
Adjust SDKで、Adjust SDKを初期化する前に環境を
AdjustConfig.ENVIRONMENT_PRODUCTION
に設定します。 -
実機テスト用のデバイスまたはエミュレーターにアプリをインストールします。
-
アプリを開きます。
-
Adjustのテストコンソール(Testing Console)を開きます。
-
デバイスID を入力し、 デバイスデータを表示(View device data) を選択します。
-
アプリ情報(App information) セクションで以下を実行します。
- インストールの状態(Install state) が インストール済み(Installed) と表示されていることを確認します。
- Pushトークン の値が確認できます。
-
アプリをアンインストールします。
-
Adjustは1日1回アンインストールを確認するため、24時間後に再度テストコンソールを確認してください。 アプリ情報 (App information) セクションの インストールの状態(Install state) に アンインストール済み(Uninstalled) と表示されます。
状態が インストール済み (Installed) から アンインストール済み(Uninstalled) に変更されることで、アンインストールと再インストール計測機能が正しく機能するようになります。 再インストール計測もテストする場合は、次の手順に従ってください。
- 実際のテストデバイスまたはエミュレーターにデバッグビルドまたはリリースビルドを再インストールします。
- アプリを開きます。
- Adjustは1日に1回再インストールを確認するため、24時間後に再度テストコンソールを確認してください。 アプリ情報 (App information) セクションの インストールの状態(Install state) に 再インストール済み(Reinstalled) と表示されます。
トラブルシューティング
アンインストール・再インストール計測をテストする際によくある問題は、以下のとおりです。
- テストインストールが行われると、Adjust SDK環境は
AdjustConfig.ENVIRONMENT_SANDBOX
に設定されます。アンインストール・再インストール計測はこの設定では機能しません。Adjust SDKでの設定は、必ずAdjustConfig.ENVIRONMENT_PRODUCTION
に変更してください。 - The push token is missing. If the push token doesn’t appear in the Testing Console, there might be something wrong with your Firebase implementation or with the code that integrates the Firebase SDK and the Adjust SDK. Review these elements of your implementation.
- FCM HTTP v1 APIプライベートキーに問題があります。例えば、生成したプライベートキーが誤ったプロジェクトに属しているか、 Adjust suiteに詳細が誤って入力された可能性があります。担当のテクニカルアカウントマネージャーまたはsupport@adjust.comにご連絡いただき、デバイスのPushトークンをお知らせください。担当者がログを取得して、AppleのAPIからのレスポンスを確認します。
問題が解決したら、次の手順に従って実装を再度テストしてください。
- アプリをアンインストールします。
- テストコンソールで デバイスID を入力し、 デバイスデータの表示(View device data) > デバイス削除(Forget Device) を選択します。
- 連携をテストするのセクションの手順を繰り返します。