Custom Tags

OneSignal supports custom tags which categorize and segment users. Add and remove tags to subscribe or unsubscribe your users to different categories of notifications or none at all. Tags are name-value pairs of strings. More info on OneSignal tags at
https://documentation.onesignal.com/docs/data-tags

You may get and set these tags programmatically using Javascript, or alternatively expose a native UI where users can toggle pre-specified tags on/off.

Method #1 - Javascript

/* Callback Function */
function tagGetCallbackFunction(tagResult){
    console.log(tagResult);
}

/* Get Tags */
gonative.onesignal.tags.getTags({callback:tagGetCallbackFunction});
//tagResult contains the below
{
  success: true,
    tags: {
      tag1: "value1",
        tag2: "value2"
    }
}
/* Tags Object with values to set */
var onesignalTags = {
  tags: {
    tag1: 'value1',
    tag2: 'value2'
  },
  callback: tagSetCallbackFunction
};

/* Callback Function */
function tagSetCallbackFunction(tagResult){
    console.log(tagResult);
}

/* Set Tags */
gonative.onesignal.tags.setTags(onesignalTags);
//tagResult contains the below
{
  success: true
}

Method #2 - Native UI

Edit appConfig.json within the Import/Export section of your app's configuration as follows. Your tags can be specified in JSON format per example provided.

/* appConfig.json */
"oneSignal": {
  "active": true,
  "applicationId": "XXXXX",
  "tagsJsonUrl": "https://yourdomain.com/path/tags.json"
}
{
  "sections": [{
    "name": "News",
    "items": [{
      "name": "National",
      "identifier": "national"
    }, {
      "name": "New York City",
      "identifier": "nyc"
    }, {
      "name": "US Politics",
      "identifier": "us_politics"
    }, {
      "name": "International",
      "identifier": "international"
    }]
  }, {
    "name": "Sports",
    "items": [{
      "name": "NFL Football",
      "identifier": "nfl"
    }, {
      "name": "NBA Basketball",
      "identifier": "nba"
    }, {
      "name": "MLB Baseball",
      "identifier": "mlb"
    }]
  }, {
    "name": "Lifestyle",
    "items": [{
      "name": "Fashion",
      "identifier": "fashion"
    }, {
      "name": "Dining",
      "identifier": "dining"
    }, {
      "name": "Live Entertainment",
      "identifier": "entertainment"
    }]
  }, {
    "name": "Journalists",
    "items": [{
      "name": "Mary Poppins",
      "identifier": "mpoppins"
    }, {
      "name": "Snow White",
      "identifier": "swhite"
    }, {
      "name": "Captain Hook",
      "identifier": "chook"
    }]
  }]
}

️GoNative JavaScript Bridge

To display the tag UI run the following command:

gonative.onesignal.showTagsUI();
<button onclick="gonative.onesignal.showTagsUI()">Edit Notification Subscriptions</button>

📱

Custom Tags Native UI

Custom Tags Native UI Demo App