OneSignal Help & Documentation

Welcome to the OneSignal New IA developer hub. You'll find comprehensive guides and documentation to help you start working with OneSignal New IA as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Discussions

Auto-Segment By Notification Topic

How to track and segment Mobile and Web Push users by clicked notification data

If you are a publisher that provides articles on different topics or an ecommerce site tracking product interest, there are 3 common things you will want to know about your notifications:

  1. what notification topics your users click
  2. how many times they are clicking that topic
  3. the last time they clicked a notification

With OneSignal, you can track this behavior using Data Tags, adding some code to your site or app (provided below) and sending notifications with a topic.

Doing so, you can segment and reengage your users with content you already know they want.

Here is how it works:

1. Add the Code

If you have a website, you can use the addListenerForNotificationOpened event. Or if you have a mobile app, see the SDK Reference Docs for your SDK and find the Notification Opened or Action Handler.

Within these events, you will use the sendTag and getTags methods to add the received notification details to your user records.

Here is some easy example code to get you started:

OneSignal.push(["addListenerForNotificationOpened", function(payload) {
  // Track last notification click time (paid feature only)
  let timestamp = Math.floor( / 1000);
  OneSignal.sendTag("ln_click", timestamp);

  console.log("Received Payload Data: ",;
  let topic =; // set topic in notification
  if (topic) {
    OneSignal.getTags().then(function(tags) {
      var topicCount = parseInt(tags[topic], 10);
      console.log("topicCount: ", topicCount);
      if (!isNaN(topicCount)) {
        topicCount += 1;
      } else {
        topicCount = 1;
      OneSignal.sendTag(topic, topicCount).then(function(tagsSent) {
        console.log("tagsSent: ", JSON.stringify(tagsSent));
class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
  // This fires when a notification is opened by tapping on it.
  public void notificationOpened(OSNotificationOpenResult result) {
    JSONObject data = result.notification.payload.additionalData;
    String topic;

    if (data != null) {
      topic = data.optString("topic", null);
      if (topic != null)
        OneSignal.sendTag("topic", topic);
let notificationOpenedBlock: OSHandleNotificationActionBlock = { result in
  let payload: OSNotificationPayload? = result?.notification.payload
    if let topic = payload.additionalData?["topic"] {
        OneSignal.sendTag("topic", value: topic)
^(OSNotificationOpenedResult *result) {
  OSNotificationPayload* payload = result.notification.payload;
   if (payload.additionalData["topic"]) {
      [OneSignal sendTag:@"topic" value:payload.additionalData["topic"]];


Paid Plan Benefits

Tracking notification clicked time is a paid plan feature only.

2. Send The Notifications With Data

This is very easy, you simply add some Additional Data to the notification using our Dashboard or API data 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.

3. Repeat and Segment

Now, whenever users click the notification, they will get automatically tagged with:

  1. the date they clicked the notification using Time Operators
  2. the notification's topic and how many total times that topic has been clicked

You can now segment subscribers based on the "topic" key, how many times that topic has been clicked and the last time any notification has been clicked.

For example, if you want to target users that click the "news" topic x amount of times. You can use the "is", "greater than" or "less than" operators with the "User Tag" filter.

Also, if you are on a Paid Plan, you can use the "time elapsed greater than" and "time elapsed less than" to track how long it has been since a device last clicked a notification and target them for reengagement.

You can now save these segments and target users based on their interest.

Updated 5 months ago

Auto-Segment By Notification Topic

How to track and segment Mobile and Web Push users by clicked notification data

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.