Checking audiences

If you need to check if a user is in a specific audience you can use the available variable Txt.inAudiences. This variable will contain an array of Audience objects that the user is currently a member of.

// example output of the audiences list
[
    {
        "duration": 2592000000,
        "ruleName": "Everyone",
        "readOnly": true,
        "joinDate": 1757407967108,
        "sessionId": "395df9eb-f3b1-7bd8-1499-41c663aca218",
        "ruleId": "0be4b18e-9079-4c22-85cc-d97c0f75a52b"
    },
    {
        "duration": 2592000000,
        "ruleName": "Desktop",
        "readOnly": true,
        "joinDate": 1757407967108,
        "sessionId": "395df9eb-f3b1-7bd8-1499-41c663aca218",
        "ruleId": "5773a5eb-4971-4d1b-b328-6c2879a91b42"
    }
]

You could use this information in for example, the AI actions custom javascript to determine if you want to show the action to the end user based on an audience they are in.

Here is an example how that would work as a "Display only if rule matches" condition on an action:

return Txt.inAudiences.some((a) => a.ruleId === 'c1f79991-5f8d-40df-8c5a-4a17ce59fcaa') //make sure to replace the audienceId with a valid audienceId from your own audiences in your account