1. Add the Code
Use OneSignal SDK’s notification event handlers to detect when a notification is opened. In that handler, extract your custom data from the payload and useaddTag
or addTags
to store it.
In this example, we tag the user with a "notification_topic"
from the custom data. You can add any other fields you want—like category, product type, or campaign.
2. Add custom data to your notifications
When creating a notification you simply add some Additional Data to the notification using our Dashboard or APIdata
parameter.
This will be the topic of the notification and what you use to segment users. Common topics would be “news”, “entertainment”, “politics”, “finance”, “tech”, etc.

Adding notification topic data in dashboard
3. Segment based on the tags
You can now create segments based on the custom data values users clicked on. Example: Users who clicked a finance topic- Key:
notification_topic
- Condition:
equals
- Value:
finance

Segmenting users based on topic clicked
4. Send notifications with the custom data
Now, whenever users click the notification, they will get automatically tagged with:- the date (unix timestamp) they clicked the notification
- the notification’s topic and how many total times that topic has been clicked