Notification Audience (WHO)¶
An important part of any push template is the audience which we be receiving notifications created from the template. Audience definition consists of several filters:
- device operating system (Android, iOS or both).
- messaging channel devices are registered with.
- user segment expressed as a query against the
DeviceRegistration
table.
When Backendless receives a request to publish a push notification, the system applies the filters and creates a list of devices which will be receiving the notification. Once the list is composed, Backendless proceeds with delivering the notification to the devices. This process is highly optimized to ensure minimal processing times and the fastest delivery process.
Operating System Filter¶
This filter consists of check boxes for each supported operating system. At the present moment available options include: All, Android and iOS. As Backendless push notification system evolves, additional options will become available.
Channel Filter¶
When a device registers with Backendless to receive push notifications, a channel is specified in the registration API. As a result, the Channel filter lets you include into the audience all devices registered with a Backendless messaging channel. The final list of devices is calculated dynamically when Backendless receives a request to publish a push notification. Since the channel selection UI is implemented with a drop-down list, only one channel can be selected. However, if you need to create an audience for multiple channels, it can be accomplished using the Segment Filter (see below).
Segment Filter¶
This filter is created with a "where clause" query applied against the DeviceRegistration
table. For example, the query shown below targets all devices registered with the news
and tipoftheday
channels:
You can also add the smart text to the segment field. Smart text is a variable which used as a placeholder for information passed to the request body. It comes in handy if you want to personalize a push notification depending on the end user.
This element can be inserted in the title, description, subtitle and headers of the notification. If the template does not have any custom smart text variables, the templateValues
element in the request body is optional.
The segment
option in the 'WHO'
section allows setting a 'where clause' condition, which identifies specific users that will receive a push notification. In the example below you can see that the 'where clause' is the clientShopping.clientAge='{age}',
where clientShopping
is a column in the DeviceRegistration
table, and the clientAge
is a related column from another data table. The {age}
is a smart text variable, which expects the age of the users that must receive a push notification:
The {age}
smart text must be passed to the request body:
{
"templateValues" :
{
"smartTextVar1" : "value",
"smartTextVar2" : "value",
}
"age": "value"
}
A query can reference any column in the DeviceRegistration
table, which has the following schema:
For example, the following query selects devices running Android 8.0:
operatingSystemName = 'ANDROID' and operationSystemVersion = '8.0'
User-based Selectors¶
A device registration may have a related user object in the Users
table. The relationship is established when a device registers from an application where there is a logged in Backendless user. The relationship between the DeviceRegistration
and the Users
tables is maintained through the ownerId
column define in the DeviceRegistration
table. Because of that, it is possible to create a selector which identifies the devices based on user criteria. For example, suppose you need to create a selector which identifies all devices for the users who have a @gmail.com email address and live in Chicago. consider the schemas below. Notice the Users
table schema below has the address
column, which is a relation to the Address
table. The address table schema has the city
column:
The Users table schema:
The Address table schema:
With the database schema defined as shown above, a query which selects devices for the users with a @gmail.com
email address who live in Chicago
is:
ownerId IN (Users[email like '%@gmail.com' and address.city = 'Chicago'].objectId)
The structure of the query is based on the "searching with subquery" feature. A query inside of the square brackets of the Users[]
block selects all the users matching the query's condition. Then Users[].objectId
gets a collection of the objectId
values for all the selected users. Finally, the ownerId IN ()
part of the query selects all the devices from the DeviceRegistration
table which have ownerId
value in the collection of user's object IDs.
Recipient Count¶
For all options defining the audience, Backendless Console calculates its size and displays it in the section above the phone image. The audience is recalculated when any of the parameters on the "WHO will get it" change, this includes operating system, channel or selector: