Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nabn opened this issue Apr 2, 2024 · 3 comments
Open

Comments

@nabn
Copy link

nabn commented Apr 2, 2024

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
Copy link
Collaborator

jerielng commented Apr 3, 2024

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
Copy link
Author

nabn commented Apr 4, 2024

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
Copy link
Collaborator

jerielng commented Apr 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants