Documentation Index
Fetch the complete documentation index at: https://documentation.onesignal.com/llms.txt
Use this file to discover all available pages before exploring further.
주제 기반 콘텐츠가 있는 게시자이거나 제품 관심사를 추적하는 전자 상거래 사이트인 경우 사용자가 상호 작용하는 알림의 사용자 지정 데이터를 기반으로 사용자를 세그먼트할 수 있습니다.
OneSignal을 사용하면 Tags를 사용하여 이를 수행할 수 있습니다. 알림 페이로드에서 정의한 메타데이터를 기반으로 알림을 클릭할 때 사용자에게 태그를 지정하여 풍부하고 행동 중심적인 세그먼트를 만들 수 있습니다.
1. 코드 추가
OneSignal SDK의 알림 이벤트 핸들러를 사용하여 알림이 열릴 때를 감지합니다. 해당 핸들러에서 페이로드에서 사용자 지정 데이터를 추출하고 addTag 또는 addTags를 사용하여 저장합니다.
이 예시에서는 사용자 지정 데이터에서 "notification_topic"으로 사용자에게 태그를 지정합니다. 카테고리, 제품 유형 또는 캠페인과 같은 다른 필드를 추가할 수 있습니다.
OneSignal.setNotificationOpenedHandler(
new OneSignal.OSNotificationOpenedHandler() {
@Override
public void notificationOpened(OSNotificationOpenedResult result) {
JSONObject data = result.getNotification().getAdditionalData();
Log.i("OneSignalExample", "Notification Data: " + data);
if (data != null) {
String topic = data.optString("notification_topic", null);
if (topic != null)
OneSignal.User.addTag("notification_topic", topic);
// Add more tags from custom data if needed
String category = data.optString("category", null);
if (category != null)
OneSignal.User.addTag("notification_category", category);
}
}
}
);
```swift Swift
let notificationOpenedBlock: OSHandleNotificationActionBlock = { result in
let payload: OSNotificationPayload? = result?.notification.payload
let additionalData = payload?.additionalData
if let topic = additionalData?["notification_topic"] as? String {
OneSignal.User.addTags(["notification_topic": topic])
}
if let category = additionalData?["category"] as? String {
OneSignal.User.addTags(["notification_category": category])
}
// Add more tags from custom data if needed
}
2. 알림에 사용자 지정 데이터 추가
알림을 생성할 때 대시보드 또는 API data 매개변수를 사용하여 알림에 Additional Data를 추가하기만 하면 됩니다.
이것은 알림의 주제이며 사용자를 세그먼트하는 데 사용하는 것입니다. 일반적인 주제는 “news”, “entertainment”, “politics”, “finance”, “tech” 등이 있습니다.
3. 태그를 기반으로 세그먼트
이제 사용자가 클릭한 사용자 지정 데이터 값을 기반으로 세그먼트를 생성할 수 있습니다.
예시: 금융 주제를 클릭한 사용자
- Key:
notification_topic
- Condition:
equals
- Value:
finance
4. 사용자 지정 데이터로 알림 전송
이제 사용자가 알림을 클릭할 때마다 다음과 같이 자동으로 태그가 지정됩니다:
- 알림을 클릭한 날짜 (Unix 타임스탬프)
- 알림의 주제 및 해당 주제를 클릭한 총 횟수
이제 이 데이터를 기반으로 구독자를 세그먼트할 수 있습니다.