braze-inc / braze-react-native-sdk

Public repo for the Braze React Native SDK
https://www.braze.com
Other
64 stars 84 forks source link

[Feature]: Add a method to read user's push notification subscription type #256

Closed nabn closed 3 months ago

nabn commented 7 months ago

What problem are you facing?

Braze SDK allows changing the subscription type to "subscribed"/"unsubscribed"

Braze.setPushNotificationSubscriptionType('subscribed');

but a way to read what the value is set to couldn't be found in the docs.

For context, this is to build a toggle in the settings for the preference.

Workarounds

This setting can be tracked at the consumer level, but would be prone to drift.

Ideal Solution

Ideally there'd be a method in the sdk such as

    Braze.getPushNotificationSubscriptionType();

that would return the current setting for this preference.

Other Information

The api docs list an option to get status for email and sms, but not for push notification.

jerielng commented 7 months ago

Hey @nabn, we wouldn't be able to provide a getter method for the user's attribute values. The SDK does not persist any of these values locally, since these setter methods are designed simply to update the user's attributes through the SDK to be persisted on the backend platform.

However, you should be able to retrieve these values from the backend by referring to these docs here. The Rest API export option should get you what you need, if you were to export that user's profile via their ID and check the push_subscribe field.

As a side note, could you clarify what you mean by but would be prone to drift.?

nabn commented 7 months ago

Thanks @jerielng. Out of curiosity, is there a limitation we can't read the setting from braze services?

As a side note, could you clarify what you mean by but would be prone to drift.?

Our workaround at the moment is to keep track of the setting client-side. However if a customer changes their preference on a different device, then it'll get out of sync on other devices. We could keep track of this at our apis to prevent this, but were wondering if this is a feature in Braze.

What's the best api to get subscription status for a device id? Is there any alternative implementation you recommend to achieve this?

jerielng commented 7 months ago

Hey @nabn, I would recommend taking a look at this page for further details on how push subscription states work and what does/does not cause them to change. The SDK only changes this value automatically under one scenario:

Braze will automatically move a user’s opt-in state to Opted-In if a user accepts an OS-level push prompt.

If you wish to disable this behavior, you can do so by disabling the optInWhenPushAuthorized configuration (iOS) (Android). In all other cases, it will only change if you manually call setPushNotificationSubscriptionType.

That API I linked also allows you to pass the device ID, so you can use that instead of the user ID. Please refer to the Request body section to see all the available parameters you can use.

jerielng commented 3 months ago

Closing out this issue due to inactivity. The above resources should illustrate how to keep track of a user's push subscription state. If you would need further assistance, feel free to reach out to our support team at support@braze.com. Thank you!