Add OneSignal tags to user profile

If you’d like to be able to segment your users based on specific interests or categories when sending push notifications you can use the nativeFunctions.onesignalSendTags() functions to add tags to your users in OneSignal.

If a user enables an option on your website, to receive promotional messages, for example, you could trigger the native function to add the “promotions” tag into his OneSignal profile.

Later on, when sending promotions to your users, you would then be able to target all those users who have the “promotions” tag in their profiles.

Here is an example on how to trigger the native function:

<script type="text/javascript">
    // Get the user agent and convert it to lowercase for case-insensitive comparison
    var userAgent = navigator.userAgent.toLowerCase();

    // Add a tag directly if the user agent contains 'canvas'
    function addTag() {
        try {
            // Check if the user agent contains the string "canvas"
            if (userAgent.indexOf('canvas') > -1) {
                nativeFunctions.onesignalSendTags("promotions");
            }
        } catch (ex) {
            console.log(ex.message);
        }
    }
</script>

You can find more details on how to use tags in OneSignal, here: https://documentation.onesignal.com/docs/add-user-data-tags