iOS SDK - アンインストールトラッキング

ドキュメント

アンインストール追跡

Apple Push Notification Service(APNs)をSingular SDKに統合することで、アプリのアンインストールをトラッキングし、ユーザーのリテンションを測定し、リエンゲージメントキャンペーンを最適化します。

重要:アンインストールトラッキングには、アプリ内でAPNsを設定する必要があります。実装の詳細については、AppleのUserNotifications Frameworkのドキュメントを参照してください。

前提条件

Singular プラットフォームの設定

アプリにアンインストールトラッキングを実装する前に、Setting Up iOS Uninstall Tracking のガイドに従って、Singular プラットフォームでアプリを設定してください。


システム要件

アンインストールトラッキングには、Apple Push Notification Service と特定のデバイス設定が必要です。

APN の要件(ソース):

  • iOS バージョン:デバイスは、UserNotifications フレームワークの iOS 10.0 以降を実行している必要があります。
  • APNs証明書:Apple DeveloperポータルでAPNs証明書またはトークンを設定する。
  • プッシュ機能:Xcode プロジェクト設定でプッシュ通知機能を有効にする。
  • ユーザの許可:プッシュ通知に対するユーザの許可を要求し、取得する。

注意:プッシュ通知の許可を拒否したり、APNs をサポートしていないデバイスを使用しているユーザは、アンインストールのために追跡されません。


実装ステップ

ステップ 1: プッシュ通知を有効にする

まだ有効になっていない場合は、プッシュ通知をサポートするように Xcode プロジェクトを設定します。

  1. Xcode でプロジェクトを開きます。
  2. アプリのターゲットを選択し、署名と機能に移動します。
  3. Capability をクリックし、Push Notifications を追加する。
  4. Background ModesでRemote notificationsがチェックされていることを確認してください。

ステップ2:ユーザー認証を要求する

UserNotificationsフレームワークを使用して、プッシュ通知の受信許可をユーザーに要求します。

SwiftObjective-C
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
    }
}

ステップ3: APNsデバイストークンの登録

APNsデバイストークンを取得し、アンインストール追跡のためにSingularに送信します。

トークンの取得と設定

didRegisterForRemoteNotificationsWithDeviceToken コールバックを実装して APNs トークンを取得し、Singular に登録します。

SwiftObjective-C
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
}

ベストプラクティスです:最初のアプリセッションからアンインストールトラッキングが有効になるように、トークンを受信したら直ちにregisterDeviceTokenForUninstall を呼び出します。


トークンのデータ形式

APNsデバイストークンをAppleから受け取ったネイティブのバイナリ形式でSingularに渡します。

重要:APNsトークンはバイナリデータ(NSData/Data)です。 変換せずに直接Singularに渡してください。トークンを16進文字列に変換する必要がある場合は、元のNSDataオブジェクトをSingularに渡してください。

16進数フォーマットの例:b0adf7c9730763f88e1a048e28c68a9f806ed032fb522debff5bfba010a9b052


別の設定方法

初期化時にトークンを設定する

SDKの初期化前にAPNsトークンが利用可能な場合は、SingularConfig オブジェクトで設定します。

SwiftObjective-C
// Get cached token if available
if let cachedToken = getCachedAPNsToken() {
    let config = SingularConfig(apiKey: "SDK_KEY", andSecret: "SDK_SECRET")
    config?.apnsDeviceToken = cachedToken
    
    Singular.start(config)
}

func getCachedAPNsToken() -> Data? {
    // Implement your token caching logic here
    return nil
}

メソッドの署名

@property (nonatomic, strong) NSData *apnsDeviceToken;

検証とトラブルシューティング

実装の確認

アンインストールトラッキングが正しく動作していることを確認します。

  1. ログの確認APNのトークン登録がログに表示されることを確認する。
  2. トークン生成のテスト:最初のアプリ起動時にトークンが生成されることを確認します。
  3. ダッシュボードを監視する:24~48時間後のアンインストール追跡データをSingularダッシュボードで確認する
  4. 権限のテスト:通知承認プロンプトが表示され、正しく機能することを確認する

よくある問題

  • トークンが生成されない:プッシュ通知機能が Xcode で有効になっており、APN 証明書が Apple Developer ポータルで設定されていることを確認してください。
  • ユーザの権限拒否:辞退された通知許可を優雅に処理するロジックを実装する。
  • データの欠落:デバイスがiOS 10.0+を実行し、ユーザに通知権限が付与されていることを確認する。
  • 設定エラー:Singularプラットフォーム設定でアンインストールトラッキングが有効になっていることを確認
  • シミュレータの制限:APNトークンはiOSシミュレータでは利用できません。

その他のリソース詳細なトラブルシューティングについては、アンインストール追跡セットアップガイドおよびApple の UserNotifications ドキュメントを参照してください。