When using the /createTargetedMessage API call, you might need to create complex filters (devices_filter) that target users within a specific Application Group based on tags that are set individually for each application (app-specific tags).
To achieve this, you need to construct the devices_filter string using specific functions and operators:
- Specify Applications: Use the
A("APP_CODE")function for each application within your target Application Group. Combine these using the+operator (logical OR). - Specify App-Specific Tags: Use the
AT("APP_CODE", "TAG_NAME", OPERATOR, VALUE)function to target devices based on a tag set within a specific application.APP_CODE: The code of the specific application.TAG_NAME: The name of the app-specific tag (e.g.,"AccountID","NotificationCategories").OPERATOR: The comparison operator (e.g.,IN,NOTIN,EQ,NOTSET). Make sure to use the correct operator for the tag type (e.g.,INorNOTINfor List tags,EQfor String/Integer tags).NOTSETchecks if the tag has never been set for the device in that specific app.VALUE: The value to compare against. ForIN/NOTIN, this should be an array (e.g.,["value1"]). ForNOTSET, a value is not typically needed or used in the same way, check documentation for exact syntax per operator.
- Combine Conditions:
- Use the
*operator (logical AND) to combine different tag conditions. - Use the
+operator (logical OR) to combine alternative conditions for the same tag (like checking if a tag isINa list ORNOTSET) or to combine checks across different apps. - Use parentheses
()to group conditions correctly.
- Use the
Important: You must explicitly list the conditions for each application within the group when dealing with app-specific tags. You cannot simply reference the Application Group code within the tag condition itself.
Example Structure:
Let's say you have an Application Group containing APP_CODE_1, APP_CODE_2, and APP_CODE_3. You want to target users where:
- The app-specific List tag
AccountIDcontains"user_account_value" - AND the app-specific List tag
NotificationCategorieseither does NOT contain"category_to_exclude"OR theNotificationCategoriestag isNOTSET.
The devices_filter would look like this:
"devices_filter": "(A(\"APP_CODE_1\") + A(\"APP_CODE_2\") + A(\"APP_CODE_3\")) * (AT(\"APP_CODE_1\", \"AccountID\", IN, [\"user_account_value\"]) + AT(\"APP_CODE_2\", \"AccountID\", IN, [\"user_account_value\"]) + AT(\"APP_CODE_3\", \"AccountID\", IN, [\"user_account_value\"])) * ((AT(\"APP_CODE_1\", \"NotificationCategories\", NOTIN, [\"category_to_exclude\"]) + AT(\"APP_CODE_1\", \"NotificationCategories\", NOTSET)) * (AT(\"APP_CODE_2\", \"NotificationCategories\", NOTIN, [\"category_to_exclude\"]) + AT(\"APP_CODE_2\", \"NotificationCategories\", NOTSET)) * (AT(\"APP_CODE_3\", \"NotificationCategories\", NOTIN, [\"category_to_exclude\"]) + AT(\"APP_CODE_3\", \"NotificationCategories\", NOTSET)))"
Explanation of the example:
(A(\"APP_CODE_1\") + A(\"APP_CODE_2\") + A(\"APP_CODE_3\")): Targets devices in any of the three apps.*: AND condition.(AT(...) + AT(...) + AT(...)): Checks ifAccountIDmatches in any of the apps (OR logic between apps for the same condition).*: AND condition.((AT(...) + AT(...)) * (AT(...) + AT(...)) * (AT(...) + AT(...))): This part is slightly complex. It ensures theNotificationCategoriescondition (NOTIN the excluded category OR NOTSET) is met within the same app where theAccountIDmatched. The outer*operators here effectively act like an AND across the apps for this combined condition check, ensuring the device meets the criteria within at least one app context fully.
Remember to replace placeholders like APP_CODE_1, TAG_NAME, OPERATOR, and VALUE with your actual application codes, tag names, desired operators, and values. Ensure proper escaping of quotes (\") if the filter string is part of a JSON payload.
Comments
0 comments
Please sign in to leave a comment.