プッシュ通知を使ったリエンゲージメント・トラッキングのサポート
Singularはプッシュ通知のトラッキングをサポートし、リエンゲージメント測定を強化します。Firebase Cloud Messaging (FCM)をSingular SDKと統合することで、プッシュ通知とやり取りしたユーザーを追跡し、それに応じて属性を設定することができます。
正確なトラッキングを行うには、以下の実装ガイドラインに従い、通知データがSingular SDKに正しく渡されるようにしてください。
なぜプッシュ通知のトラッキングが重要なのですか?
プッシュ通知は重要なリエンゲージメントツールですが、トラッキングには正しい統合が必要です。Singularは通知とやり取りしたユーザーを適切に帰属させ、マーケティングキャンペーンやエンゲージメント戦略を最適化します。
実装ガイド
ステップ 1: Firebase Cloud Messaging (FCM) 通知を処理する
アプリがFirebaseからプッシュ通知を受け取ると、onMessageReceived() メソッドがトリガーされます。Singular で通知を追跡するには、このメソッドを更新して通知データを処理します。
例
@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(); // Fixed the incorrect Map generic type
if (!data.isEmpty()) {
Log.d("===singular-app", data.toString());
}
// Implement processNotification method to forward payload data to intent
processNotification(title, body, data);
}
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())
}
// Implement processNotification method to forward payload data to intent
processNotification(title, body, data)
}
これにより、関連するすべてのプッシュデータが取得され、処理のために転送されます。
ステップ2:プッシュ通知の処理とSingularへのデータ送信
通知を受信したら、そのデータをSingularが初期化されるメインアクティビティを起動するインテントに渡すことが重要です。
例
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 // Added FLAG_IMMUTABLE for API 31+
);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "your_channel_id")
.setSmallIcon(R.drawable.info_btn)
.setContentTitle(title)
.setContentText(body)
.setPriority(NotificationCompat.PRIORITY_HIGH) // Optional: Set priority for better visibility
.setAutoCancel(true)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.notify(0, notificationBuilder.build());
}
}
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 // For Android 12+
)
val notificationBuilder = NotificationCompat.Builder(this, "your_channel_id")
.setSmallIcon(R.drawable.info_btn)
.setContentTitle(title)
.setContentText(body)
.setPriority(NotificationCompat.PRIORITY_HIGH) // Optional for better visibility
.setAutoCancel(true)
.setContentIntent(pendingIntent)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
notificationManager?.notify(0, notificationBuilder.build())
}
これにより、ユーザーが通知をタップすると、正しいトラッキングデータとともに適切なアクティビティに誘導されます。
ステップ3:プッシュ通知のペイロードをSingular SDKと統合する
最後に、Singular SDKの設定を更新して、プッシュ通知のペイロードが正しく渡され、処理されるようにします。
例
String[][] pushSelectors = {
{"sng_link"},
{"rootObj", "nestedObj", "anotherNested", "singularLink"}
};
config.withPushNotificationPayload(intent, pushSelectors);
Singular.init(context, config);
val pushSelectors = arrayOf(
arrayOf("sng_link"),
arrayOf("rootObj", "nestedObj", "anotherNested", "singularLink")
)
config.withPushNotificationPayload(intent, pushSelectors)
Singular.init(context, config)
このステップでは、Singularがアトリビューション目的でプッシュ通知のエンゲージメントを正しくトラッキングすることを確認します。
検証ガイド
Singular SDK APIコールは、プッシュ通知のペイロードリンクがセッション開始コールのsingular_link予約パラメータの下に正しく渡されることを確認します。
例
https://sdk-api-v1.singular.net/api/v1/start?a=<SDK-Key>&ab=arm64-v8a&aifa=180f63a1-0955-47b4-896a-d75ae3d35955&apc=Marchv7&apg=1&aps=Intex&asid_scope=1&asid_timeinterval=0.112&av=20.0&br=samsung&c=wifi¤t_device_time=1740905574088&de=m15x&device_type=phone&device_user_agent=Dalvik/2.1.0 (Linux; U; Android 14; SM-E156B Build/UP1A.231005.007)&dnt=0&event_index=3&fi=e5bRZuVddO8:APA91bHXI3OmFZv3-r8f03zyji2kvKWbIngwf8KBDHk4Rj5q5MEeEm6EtzC-if1vpJRmuYLyGdAcSz9-nc49eIjD86xwj-n9J4jKucqMVt9mP8ICifP0arA&i=net.singular.singularsampleapp&install_time=1740905507036&is=false&k=SDID&lag=0.067&lc=en_IN&ma=samsung&mo=SM-E156B&n=Singular-TestApp-Debug&p=Android&pr=m15xnndins&pu=1&rt=json&s=1740905574084&sdk=Singular/v12.6.2&singular_install_id=2dc5dfc2-a2a8-484a-aad1-fed6cb7a3023&singular_link=https://singularassist2.sng.link/C4nw9/r1m0?_dl=singular://test&_smtype=3&src=com.android.shell&u=75f7b911-5a77-597d-8892-56f5e0e210ff&update_time=1740905507036&v=14&h=1e723fd90344d5d037059f110611ed1d84fbba88
代わりに、Singular SDK コンソールを使って、以下のようにDeeplink URL の下にあるプッシュ通知トラッキングリンクを確認することもできます。
これを確認することで、プッシュ通知のエンゲージメントがSingular SDK内で正しくトラッキングされていることを確認できます。
注意事項
- withSingularLink ハンドラコードとは異なり、Singular SDK はこの機能のためのプッシュペイロードコールバックを提供していないことにご注意ください。プッシュ通知データを読み取り、ユーザーをアプリ内の特定の商品ページにリダイレクトするディープリンクロジックを実装するのは、アプリ開発者の責任です。このソリューションでは、ユーザーが通知をタップするとSingularがプッシュ通知のペイロードを取得し、このペイロードをSingular.init() によってトリガーされるSDK開始セッションイベントに含めます。このデータはSingularのバックエンドで処理され、プッシュ通知のタッチポイント/クリックを属性化し、リエンゲージメント追跡のために登録されます。
-
プッシュ通知のペイロードに渡されたカスタムキー値のペアから、Singular のリンクドメインだけを許可する安全メカニズムがあります。具体的には、Singular Manage Linksページで事前に定義されたsng.linkドメインのみが許可されます。
例えば
https://prod_test.sng.link/B0s2a/51oi?_dl=singular%3A%2F%2Fmain
Singularリンクを別のドメイン(例:EメールサービスプロバイダのESPドメイン)でラップする場合は、セットアップで以下のオプションを追加して明示的にドメインを設定する必要があります:これにより、Singularフレームワーク内で外部ドメインが認識され、許可されるようになります。以下の設定例を参照してください。config.withESPDomains(Arrays.asList("sl.esp.link")) ;
-
1つのプッシュ通知からユーザーのアクションに基づいて異なるディープリンクをトリガーする必要がある場合、1つのSingularトラッキングリンクを使用し、動的にリダイレクトを変更することができます。
例
ニュース速報のプッシュ通知は複数のディープリンクオプションを提供することがあります!複数のトラッキングリンクを作成する代わりに、1つのSingularトラッキングリンクを設定し、ユーザーの選択に基づいて動的にリダイレクトを調整します。
最新ニュースを読む
トレンドトピックを読む →トレンドトピックを読むnewsapp://article?id=12345
スポーツnewsapp://trending
newsapp://sports
成功です!
以下のステップに従うことで、あなたのアプリはSingularを使ってプッシュ通知のインタラクションをトラッキングするように設定されました。これにより、キャンペーンのパフォーマンスインサイトが改善され、正確なリエンゲージメントアトリビューションが保証されます。