key : value pairs of string data for setting custom user or event properties. This guide details how to add tags through the SDK, but tags can be set in a number of ways outlined in Tags: Tracking User Events and Attributes
Tags should be added as string data, but any numbers/integers/decimals will be detected automatically on our backend and available for use.
SDK Tagging Methods
Tag a user based on an event of your choosing so later you can create Segments or Message Personalization. Recommend usingsendTags over sendTag if you need to set more than one tag on a user at a time.
iOS SDK implements callbacks to verify tags were successfully added. Android saves tags to device cache and will retry updating the tag automatically upon a stable network connection being established.
sendTag Method
Tag a user based on an app event of your choosing so later you can later create segments to target these users. We recommend using sendTags over sendTag if you need to add or update more than one tag on a user at a time.
If you try to set more tags on a user than you plan allows, it will fail. You will need to delete any unwanted tags first before setting or updating tags. See Tags FAQ for details.
| Parameter | Type | Description |
|---|---|---|
key | String, NSString* | Key of your choosing to create or update |
value | String, NSString* | Value to set on the key. NOTE: Passing in a blank String deletes the key, you can also call deleteTag or deleteTags. |
onSuccess(Optional) | OneSignalResultSuccessBlock | iOS Called if there were no errors sending the tag. |
onFailure(Optional) | OneSignalFailureBlock | iOS Called if there was an error. Android Will retry automatically upon a stable network connection. |
callback (Web) | Function | Call back to be fired when the tags have been sent to our server and a response has been returned. The first parameter of the callback is an object of the tags you sent (key-value pairs). |
sendTags Method
Tag a user based on an app event of your choosing, so that later you can create segments to target these users. If you try to set more tags on a user than you plan allows, it will fail. You will need to delete any unwanted tags first before setting or updating tags. See Tags FAQ for details.
| Parameter | Type | Description |
|---|---|---|
keyValues | JSONObject, NSDictionary* | Key value pairs of your choosing to create or update. NOTE: Passing in a blank NSString* as a value deletes the key, you can also call deleteTag or deleteTags. |
onSuccess(Optional) | OneSignalResultSuccessBlock | iOS Called if there were no errors sending the tag. |
onFailure(Optional) | OneSignalFailureBlock | iOS Called if there was an error. Android Will retry automatically upon a stable network connection. |
callback (Web) | Function | Call back to be fired when the tags have been sent to our server and a response has been returned. The first parameter of the callback is an object of the tags you sent (key-value pairs). |
getTags Method
Retrieve a list of tags as that have been set on the user from the OneSignal server. Android will provide a cached copy if there is no network connection.
| Parameter | Type | Description |
|---|---|---|
tags | JSON Object of String data | Contains key-value pairs retrieved from the OneSignal server. |
successBlock | OneSignalResultSuccessBlock | Called when tags are received from OneSignal’s server. |
onFailure(Optional) | OneSignalFailureBlock | Called if there was an error. |
tagsReceivedCallBack (Web) | Function (Web) | Callback to be fired when the list of tags has been retrieved. The first parameter of the callback is an object containing key-value pairs of the tags. |
deleteTag Method
Deletes a single tag that was previously set on a user with sendTag or sendTags. Use deleteTags if you need to delete more than one.
| Parameter | Type | Description |
|---|---|---|
key | String, NSString* | Key to remove |
onSuccess(Optional) | OneSignalResultSuccessBlock | iOS Called if there were no errors |
onFailure(Optional) | OneSignalFailureBlock | iOS Called if there was an error Android Will retry automatically upon a stable network connection. |
deleteTags Method
Deletes one or more tags that were previously set on a user with sendTag or sendTags.
| Parameter | Type | Description |
|---|---|---|
keys | Array, Collection, NSArray* | Keys to remove. |
onSuccess(Optional) | OneSignalResultSuccessBlock | iOS Called if there were no errors |
onFailure(Optional) | OneSignalFailureBlock | iOS Called if there was an error Android Will retry automatically upon a stable network connection. |
callback (Web) | Function | Callback to be fired when the list of tags has been removed. The first parameter of the callback is an array of the tags that were deleted. |
Tagging Examples
Tag Based on Browser or Operating System
OneSignal currently tracksdevice type, which you can use to create Segments to target Android and iOS mobile app subscribers and Web Push subscribers independently.
If you want to segment by mobile web vs. desktop web subscribers, you can use this example code on the site to tag automatically once detected: