Pre-Requisites
- Integration of JavaScript SDK
- Configure preference categories on SuprSend dashboard
Understanding preference structure
This is how a typical preference page will look like:
- Category-level preference settings (Sections)
- Overall Channel-level preference

Preferences data structure
1.1 Sections
This contains the name, description, and subcategories. We have to loop through the sections list and for every section item if there is a name and description present, then show the heading, and if a subcategories list is present, loop through that subcategories list and show all subcategories under that section heading. Subcategories can exist without sections as the section is an optional field. In that case, the section’s name will not be available. For sections where the name is not present, you can directly show its subcategories list without showing Heading for the section in UI.
1.2 Categories (sections -> sub-categories)
This is the place where the user sets his category-level preferences. While looping through the subcategories list for every subcategory item, show the name and description in UI.
1.3 Category channels (sections -> sub-categories -> channels)
This contains a list of channels, channel preference status and whether it’s editable or not. While looping through the subcategory list for every subcategory item we have to loop through its channels list and for every channel to show channel level checkbox.
2. Overall channel preferences
It’s a list of all channel-level preferences. We have to loop through the list and for each item, show the UI as given in the below image.
Integration
Get preferences data
Use this method to get preferences data and create the preferences UI by following the above sections. This method should be called first before any update preference methods.
If you are passing
tenantId in preference methods, make sure it matches scope.tenant_id passed while creating userToken else error will be thrown due to scope mismatching.
Returns: Promise<ApiResponse>
Update category preference
Calling this method will opt-in/opt-out user from that category. When the category is editable and the switch is toggled you can call this method.Promise<ApiResponse>

Update channel preference in category
Calling this method will opt-in/opt-out users from that category-level channel. When the category’s channel checkbox is editable and the user clicks on the checkbox you can call this method.Promise<ApiResponse>

Update overall channel preference
This method updated the channel-level preference of the user.Promise<ApiResponse>

Event listeners
All preferences update api’s are optimistic updates. Actual API call will happen in background with 1 second debounce. Since its a background task SDK provides event listeners to get updated preference data based on API call status. Listen to this event listeners and update the UI accordingly.Example
For understanding purpose we have added simple example of preferences implementation in React. You could refer this headless example and design the preferences in your Angular or Vue.js etc. If you want to implement in react please refer @suprsend/react.Example.js
