アンインストールトラッキング
Apple Push Notification Service (APNs) を Singular SDK と統合することで、 アプリのアンインストールをトラッキングし、ユーザーリテンションを測定し、 リエンゲージメントキャンペーンを最適化できます。
重要: アンインストールトラッキングを使用するには、アプリで APNs の構成が必要です。 実装の詳細については、 Apple の UserNotifications Framework ドキュメント を参照してください。
前提条件
Singular プラットフォームの構成
アプリにアンインストールトラッキングを実装する前に、次のガイドに従って Singular プラットフォームでアプリを構成してください。 iOS アンインストールトラッキングのセットアップ .
システム要件
アンインストールトラッキングには Apple Push Notification Service と特定のデバイス構成が必要です。
APNs の要件 ( 出典 ):
- iOS バージョン: UserNotifications フレームワークを使用するには、デバイスが iOS 10.0 以降で動作している必要があります
- APNs 証明書: Apple Developer ポータルで APNs 証明書またはトークンを構成してください
- プッシュ機能: Xcode プロジェクト設定で Push Notifications 機能を有効にしてください
- ユーザーパーミッション: プッシュ通知のユーザー認証をリクエストし、取得してください
注意: プッシュ通知のパーミッションを拒否したユーザーや、APNs に対応していないデバイスを使用するユーザーは、 アンインストールのトラッキング対象外となります。
実装手順
ステップ 1: プッシュ通知を有効にする
まだ有効になっていない場合は、プッシュ通知をサポートするように Xcode プロジェクトを構成してください。
- Xcode でプロジェクトを開きます
- アプリのターゲットを選択し、 Signing & Capabilities に移動します
- + Capability をクリックし、 Push Notifications を追加します
- Background Modes で Remote notifications がチェックされていることを確認します
ステップ 2: ユーザー認証をリクエストする
UserNotifications フレームワークを使用して、ユーザーにプッシュ通知を受信するパーミッションをリクエストします。
import UIKit
import UserNotifications
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Set notification delegate
UNUserNotificationCenter.current().delegate = self
// Request authorization for notifications
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: authOptions) { granted, error in
if let error = error {
print("Notification authorization error: \(error.localizedDescription)")
}
if granted {
// Register for remote notifications on main thread
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
}
}
return true
}
}
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Set notification delegate
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
// Request authorization for notifications
UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
UNAuthorizationOptionBadge |
UNAuthorizationOptionSound;
[[UNUserNotificationCenter currentNotificationCenter]
requestAuthorizationWithOptions:authOptions
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (error) {
NSLog(@"Notification authorization error: %@", error.localizedDescription);
}
if (granted) {
// Register for remote notifications on main thread
dispatch_async(dispatch_get_main_queue(), ^{
[application registerForRemoteNotifications];
});
}
}];
return YES;
}
@end
ステップ 3: APNs デバイストークンを登録する
APNs デバイストークンを取得し、アンインストールトラッキングのために Singular に送信します。
トークンの取得と設定
didRegisterForRemoteNotificationsWithDeviceToken
コールバックを実装して、APNs トークンを取得し、Singular に登録します。
import Singular
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// Register the device token with Singular for uninstall tracking
Singular.registerDeviceToken(forUninstall: deviceToken)
print("APNs device token registered with Singular")
// Also send to your server if needed for your own push notifications
sendTokenToServer(deviceToken)
}
func application(_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Failed to register for remote notifications: \(error.localizedDescription)")
}
private func sendTokenToServer(_ deviceToken: Data) {
// Implement your server communication logic here
}
#import <Singular/Singular.h>
- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Register the device token with Singular for uninstall tracking
[Singular registerDeviceTokenForUninstall:deviceToken];
NSLog(@"APNs device token registered with Singular");
// Also send to your server if needed for your own push notifications
[self sendTokenToServer:deviceToken];
}
- (void)application:(UIApplication *)application
didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"Failed to register for remote notifications: %@", error.localizedDescription);
}
- (void)sendTokenToServer:(NSData *)deviceToken {
// Implement your server communication logic here
}
ベストプラクティス:
トークンを受信したら、すぐに
registerDeviceTokenForUninstall
を呼び出して、最初のアプリセッションからアンインストールトラッキングが有効になるようにしてください。
トークンデータ形式
APNs デバイストークンを Apple から受信したそのままのネイティブバイナリ形式で Singular に渡します。
重要: APNs トークンはバイナリデータ (NSData/Data) です。変換せずにそのまま Singular に渡してください。 アプリが他の目的でトークンを 16 進文字列に変換する必要がある場合は、Singular 用には元の NSData オブジェクトを保持してください。
16 進形式の例:
b0adf7c9730763f88e1a048e28c68a9f806ed032fb522debff5bfba010a9b052
検証とトラブルシューティング
実装の検証
アンインストールトラッキングが正しく動作していることを確認します。
- ログを確認: ログに APNs トークンの登録が表示されていることを確認してください
- トークン生成のテスト: アプリの初回起動時にトークンが生成されることを確認してください
- ダッシュボードの監視: 24〜48 時間後に Singular ダッシュボードでアンインストールトラッキングデータを確認してください
- パーミッションのテスト: 通知認証のプロンプトが表示され、正しく機能することを確認してください
よくある問題
- トークンが生成されない: Xcode で Push Notifications 機能が有効になっていること、および Apple Developer ポータルで APNs 証明書が構成されていることを確認してください
- ユーザーがパーミッションを拒否: 拒否された通知パーミッションを適切に処理するロジックを実装してください
- データの欠落: デバイスが iOS 10.0 以降で動作し、ユーザーが通知パーミッションを許可していることを確認してください
- 構成エラー: Singular プラットフォームの設定でアンインストールトラッキングが有効になっていることを確認してください
- シミュレータの制限: APNs トークンは iOS シミュレータでは利用できません。実機でテストしてください
追加リソース: 詳細なトラブルシューティングについては、 アンインストールトラッキングセットアップガイド および Apple の UserNotifications ドキュメント を参照してください。