プッシュ通知のサポート
Apple Push Notification Service(APNs)をSingular SDKと統合することで、プッシュ通知とのユーザーインタラクションを追跡し、再エンゲージメントキャンペーンを測定してコンバージョンを正確にアトリビューションします。
以下の実装ガイドラインに従って、通知データがSingular SDKに正しく渡され、適切にアトリビューションされるようにしてください。
プッシュ通知を追跡する理由: プッシュ通知は再エンゲージメントを促進しますが、追跡には正しい統合が必要です。Singularは、通知とインタラクトしたユーザーが適切にアトリビューションされることを保証し、マーケティングキャンペーンとエンゲージメント戦略を最適化します。
前提条件: APNsトークンが生成され、Singularがプッシュペイロードを抽出する前に、以下のすべてが整っていることを確認してください:
- アプリターゲットの Signing & Capabilities でXcodeの Push Notifications 機能が有効になっていること。
- APNsキー(.p8)または証明書(.p12)がアプリのSingularダッシュボードにアップロードされていること。
- アプリは aps-environment エンタイトルメントを含むプロビジョニングプロファイルでビルドされていること。
- テストは実機で行うこと — APNsトークンはiOSシミュレーターでは発行されません。
-
Singular.start(_:)が実行されていることで、SDKはpushNotificationLinkPathを介して通知ペイロードからSingularリンクを抽出できます。
実装ガイド
プッシュ通知の登録
UNUserNotificationCenterを使用してユーザーからプッシュ通知の受信許可をリクエストし、アプリをAPNsに登録します。
import UserNotifications
// Set the current instance as the delegate for UNUserNotificationCenter
UNUserNotificationCenter.current().delegate = self
// Define the notification authorization options (alert, badge, sound)
let pushAuthOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
// Request notification authorization from the user
UNUserNotificationCenter.current().requestAuthorization(options: pushAuthOptions) { granted, error in
// If an error occurs during authorization, print the error description
if let error = error {
print("registerForPushNotifications : failure - \(error.localizedDescription)")
}
// If the user granted permission, register for remote notifications
if granted {
// Ensure registration is done on the main thread
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
- (void)registerForPushNotifications:(UIApplication *)application {
// Set delegate to self
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
// Define the push notification options
UNAuthorizationOptions pushAuthOptions = UNAuthorizationOptionAlert |
UNAuthorizationOptionBadge |
UNAuthorizationOptionSound;
// Request push notification authorization
[[UNUserNotificationCenter currentNotificationCenter]
requestAuthorizationWithOptions:pushAuthOptions
completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (error) {
NSLog(@"registerForPushNotifications : failure - %@", error.localizedDescription);
}
if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{
[application registerForRemoteNotifications];
});
}
}];
}
ベストプラクティス: 通知許可のリクエストは、アプリのライフサイクルの早い段階で、理想的にはユーザーに価値を示した後に行い、オプトイン率を向上させてください。
通知応答の処理
ユーザーがプッシュ通知をタップしたときに通知応答を処理し、ペイロードデータをSingularに転送して追跡します。
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
// Extract the notification payload
let userInfo = response.notification.request.content.userInfo
// Pass the notification data to Singular for tracking
Singular.handlePushNotification(userInfo)
// Call the completion handler to indicate processing is complete
completionHandler()
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)(void))completionHandler {
// Extract the push notification payload (user info)
NSDictionary *userInfo = response.notification.request.content.userInfo;
// Log the userInfo dictionary for debugging purposes
NSLog(@"didReceiveNotificationResponse userInfo = %@", userInfo);
// Pass the notification data to Singular for tracking
[Singular handlePushNotification:userInfo];
// Call the completion handler to indicate processing is complete
completionHandler();
}
ベストプラクティス: 通知処理が完了したことをシステムに知らせるため、常にコンプリーションハンドラーを速やかに呼び出してください。完了が遅れると、システム警告やスロットリングが発生する可能性があります。
プッシュペイロード用のSDK設定
SDK設定にプッシュ通知ペイロードセレクターを追加して、通知データ構造のどこにSingularリンクが配置されているかを指定します。
func getConfig() -> SingularConfig? {
guard let config = SingularConfig(apiKey: "SDK_KEY", andSecret: "SDK_SECRET") else {
return nil
}
// Configure push notification link paths
config.pushNotificationLinkPath = [
["sng_link"],
["rootObj", "nestedObj", "anotherNested", "singularLink"]
]
return config
}
// Start the Singular SDK with the configuration
if let config = getConfig() {
Singular.start(config)
}
- (SingularConfig *)getConfig {
SingularConfig *config = [[SingularConfig alloc] initWithApiKey:@"SDK_KEY"
andSecret:@"SDK_SECRET"];
// Configure push notification link paths
config.pushNotificationLinkPath = @[
@[@"sng_link"],
@[@"rootObj", @"nestedObj", @"anotherNested", @"singularLink"]
];
return config;
}
// Start the Singular SDK with the configuration
SingularConfig *config = [self getConfig];
[Singular start:config];
セレクターの設定:
-
単純なキー:
ペイロード内のトップレベルのキーには
["sng_link"]を使用します -
ネストされたキー:
ネストされたJSON構造をたどるには
["rootObj", "nestedObj", "key"]を使用します - 複数のパス: Singularリンクが存在し得る複数の場所をチェックするために、複数のセレクター配列を定義します
検証ガイド
Start Sessionでペイロードを確認
start session API呼び出しを検査して、プッシュ通知リンクがSingularに正しく渡されていることを確認します。
ユーザーが通知をタップすると、Singular SDKはstart sessionリクエストの
singular_link
パラメーターにプッシュ通知ペイロードを含めます。
Start Sessionリクエストの例:
https://skan.singular.net:443/api/v1/start?
dnt=-1
&update_time=0
&singular_link=https://sl.sng.link/Cclbu/2a7n?_dl=com.singular.app&_smtype=3
&i=com.singular.SwiftScene
&sdk=Singular/12.7.1
&p=iOS
&v=18.2.1
代替の検証方法: Singular SDK Consoleを使用してプッシュ通知の追跡を検証します。 Deeplink URL フィールドを確認して、追跡リンクが正しくキャプチャされていることを確認してください。
高度な設定
ESPドメインの設定
Email Service Provider(ESP)またはその他のサードパーティドメイン内にSingularリンクをラップする場合は、外部ドメインを設定してください。
func getConfig() -> SingularConfig? {
guard let config = SingularConfig(apiKey: "SDK_KEY", andSecret: "SDK_SECRET") else {
return nil
}
// Configure ESP domains for wrapped links
config.espDomains = ["sl.esp.link", "custom.domain.com"]
return config
}
- (SingularConfig *)getConfig {
SingularConfig *config = [[SingularConfig alloc] initWithApiKey:@"SDK_KEY"
andSecret:@"SDK_SECRET"];
// Configure ESP domains for wrapped links
config.espDomains = @[@"sl.esp.link", @"custom.domain.com"];
return config;
}
セキュリティに関する注意:
デフォルトでは、SingularのManage Linksページに事前定義された
sng.link
ドメインのみが許可されます。ラップされたリンクを使用する場合は、ESPドメインを明示的に設定してください。
動的ディープリンクルーティング
動的リダイレクトオーバーライドを使用して1つのSingular追跡リンクを設定することで、単一の通知から複数のディープリンク先を実装します。
ユースケース例: 複数のアクションオプションを備えた速報通知
-
最新ニュースを読む:
newsapp://article?id=12345 -
トレンドトピック:
newsapp://trending -
スポーツ:
newsapp://sports
複数の追跡リンクを作成する代わりに、1つのSingularリンクを使用し、ユーザーの選択に基づいてリダイレクトを動的にオーバーライドします。実装の詳細については、 Singular追跡リンクのリダイレクトのオーバーライド を参照してください。
重要な考慮事項
実装に関する注意事項
-
コールバックハンドラーなし:
singularLinksHandlerとは異なり、プッシュ通知機能はペイロードのコールバックを提供しません。アプリ内の特定のコンテンツにユーザーをルーティングするには、独自のディープリンクロジックを実装してください -
アトリビューションフロー:
ユーザーが通知をタップすると、Singularはペイロードを取得し、
Singular.start()によってトリガーされるstart sessionイベントに含めます。バックエンドはこのデータを処理して、プッシュ通知のタッチポイントをアトリビューションし、再エンゲージメント追跡を登録します -
ドメイン制限:
デフォルトでは、Manage LinksページのSingularリンクドメイン(
sng.link)のみが許可されます。ラップされたリンクの場合は、espDomainsを使用してESPドメインを明示的に設定してください
成功: これらの手順に従うことで、アプリはSingularを通じてプッシュ通知のインタラクションを追跡できるようになり、キャンペーンパフォーマンスのインサイトが向上し、正確な再エンゲージメントアトリビューションが保証されます。