プッシュ通知のサポート
Firebase Cloud Messaging (FCM) とSingular SDKを統合することで、プッシュ通知によるユーザーインタラクションを追跡し、リエンゲージメントキャンペーンやコンバージョン率を正確に測定することができます。
以下の実装ガイドラインに従って、通知データが正しくSingular SDKに渡され、適切なアトリビューションが行われるようにしてください。
プッシュ通知を追跡する理由プッシュ通知はリエンゲージメントを促進しますが、トラッキングには正しい統合が必要です。Singularは、通知を受け取ったユーザーが適切にアトリビューションされるようにし、マーケティングキャンペーンとエンゲージメント戦略を最適化します。
実装ガイド
FCM通知の処理
FirebaseMessagingService のonMessageReceived() メソッドをオーバーライドして、プッシュメッセージが届いたときに通知データを取得します。
override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
var title = ""
var body = ""
message.notification?.let {
Log.d("singular-app", it.toString())
title = it.title ?: ""
body = it.body ?: ""
}
val data: Map<String, String> = message.data
if (data.isNotEmpty()) {
Log.d("singular-app", data.toString())
}
// Forward payload data to intent
processNotification(title, body, data)
}
@Override
public void onMessageReceived(@NonNull RemoteMessage message) {
super.onMessageReceived(message);
String title = "";
String body = "";
if (message.getNotification() != null) {
Log.d("singular-app", message.getNotification().toString());
title = message.getNotification().getTitle();
body = message.getNotification().getBody();
}
Map<String, String> data = message.getData();
if (!data.isEmpty()) {
Log.d("singular-app", data.toString());
}
// Forward payload data to intent
processNotification(title, body, data);
}
ベストプラクティス通知内容(タイトル、本文)とデータペイロードの両方を取得し、完全なトラッキング情報をアトリビューションに利用できるようにします。
通知データの処理と転送
通知ペイロードが添付されたMainActivityを起動するインテントを作成し、Singularがトラッキングデータを受け取れるようにします。
private fun processNotification(title: String, body: String, data: Map<String, String>) {
val intent = Intent(this, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
// Attach notification data to the intent
data.forEach { (key, value) ->
putExtra(key, value)
}
}
val pendingIntent = PendingIntent.getActivity(
this,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)
val notificationBuilder = NotificationCompat.Builder(this, "your_channel_id")
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setContentText(body)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
notificationManager?.notify(0, notificationBuilder.build())
}
private void processNotification(String title, String body, Map<String, String> data) {
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
// Attach notification data to the intent
for (Map.Entry<String, String> entry : data.entrySet()) {
intent.putExtra(entry.getKey(), entry.getValue());
}
PendingIntent pendingIntent = PendingIntent.getActivity(
this,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE
);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "your_channel_id")
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(title)
.setContentText(body)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.notify(0, notificationBuilder.build());
}
}
Android 12+の要件:セキュリティ要件に準拠するため、PendingIntent.FLAG_IMMUTABLE for Android API 31+を使用してください。
プッシュペイロード用SDKの設定
SDK設定にプッシュ通知ペイロードセレクタを追加し、通知データ構造のどこにSingularリンクがあるかを指定します。
val pushSelectors = arrayOf(
arrayOf("sng_link"),
arrayOf("rootObj", "nestedObj", "anotherNested", "singularLink")
)
val config = SingularConfig("SDK_KEY", "SDK_SECRET")
.withPushNotificationPayload(intent, pushSelectors)
Singular.init(applicationContext, config)
String[][] pushSelectors = {
{"sng_link"},
{"rootObj", "nestedObj", "anotherNested", "singularLink"}
};
SingularConfig config = new SingularConfig("SDK_KEY", "SDK_SECRET")
.withPushNotificationPayload(getIntent(), pushSelectors);
Singular.init(getApplicationContext(), config);
セレクタ構成:
-
単純キー:ペイロードのトップレベルキーに
arrayOf("sng_link")。 -
ネストされたキー:ネストされたJSON構造をトラバースするには
arrayOf("rootObj", "nestedObj", "key")。 - 複数のパス:複数のセレクタ配列を定義して、Singularリンクのさまざまな場所をチェックする。
検証ガイド
セッション開始時のペイロードの検証
開始セッションAPIコールを検査することで、プッシュ通知リンクがSingularに正しく渡されていることを確認します。
Singular SDKは、ユーザーが通知をタップすると、開始セッションリクエストのsingular_link パラメータの下にプッシュ通知ペイロードを含めます。
セッション開始リクエストの例:
https://sdk-api-v1.singular.net/api/v1/start?
a=<SDK-Key>
&singular_link=https://singularassist2.sng.link/C4nw9/r1m0?_dl=singular://test&_smtype=3
&i=net.singular.singularsampleapp
&s=1740905574084
&sdk=Singular/v12.6.2
代替検証:Singular SDKコンソールを使用して、プッシュ通知のトラッキングを確認します。ディープリンクURLフィールドをチェックして、トラッキングリンクが正しくキャプチャされていることを確認します。
高度な構成
ESPドメイン設定
SingularリンクをEメールサービスプロバイダ(ESP)またはその他のサードパーティのドメインでラップする場合は、外部ドメインを設定します。
val config = SingularConfig("SDK_KEY", "SDK_SECRET")
.withESPDomains(listOf("sl.esp.link", "custom.domain.com"))
SingularConfig config = new SingularConfig("SDK_KEY", "SDK_SECRET")
.withESPDomains(Arrays.asList("sl.esp.link", "custom.domain.com"));
セキュリティ上の注意:デフォルトでは、Singularリンク管理ページで事前に定義されたsng.linkドメインのみが許可されます。ラップリンクを使用する場合は、ESPドメインを明示的に設定します。
ダイナミックディープリンクルーティング
動的なリダイレクトオーバーライドで1つのSingularトラッキングリンクを設定することで、1つの通知から複数のディープリンク先を実装できます。
使用例複数のアクションオプションを持つニュース速報
-
最新ニュースを読む:
newsapp://article?id=12345 -
トレンドトピック
newsapp://trending -
スポーツ
newsapp://sports
複数のトラッキングリンクを作成する代わりに、1つのSingularリンクを使用し、ユーザーの選択に基づいて動的にリダイレクトを上書きします。実装の詳細については、Singular トラッキングリンクでリダイレクトを上書きするを参照してください。
重要な考慮事項
実装上の注意
-
コールバックハンドラはありません:
withSingularLinkと異なり、プッシュ通知機能はペイロードコールバックを提供しません。独自のディープリンクロジックを実装して、ユーザーをアプリ内の特定のコンテンツに誘導してください。 -
アトリビューションフロー:ユーザーが通知をタップすると、Singularはペイロードを取得し、
Singular.init()によってトリガーされるセッション開始イベントに含めます。バックエンドはこのデータを処理して、プッシュ通知のタッチポイントに属性を付け、リエンゲージメント追跡を登録します。 -
ドメインの制限:デフォルトでは、[Manage Links(リンクの管理)]ページにあるSingularリンクドメイン(
sng.link)のみが許可されています。withESPDomains()を使用して、ラップリンク用の ESP ドメインを明示的に設定します。
成功しました:これらのステップに従うことで、あなたのアプリはSingularでプッシュ通知のインタラクションをトラッキングし、キャンペーンパフォーマンスのインサイトを改善し、正確なリエンゲージメントアトリビューションを保証します。