Available options to add Data Tags to devices with OneSignal.
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.
sendTags
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
MethodsendTags
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
MethodParameter | 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
MethodParameter | 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
MethodsendTag
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
MethodsendTag
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. |
device 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: