Integration
A step-by-step guide to integrate drop-in inbox / feed in applications like Angular, Vuejs, VanillaJS etc.
End of Support for @suprsend/web-inbox. Migrate to @suprsend/web-components
We have upgraded authentication of inbox from HMAC to JWT as it is more secure. Please migrate to newer SDK if you are on old one.
There are 2 ways in which you can implement inbox functionality:
- Drop-in components: Pre-built UI with many customizable options which require minimal effort to build.
- Headless implementation: For more advanced usecases where you want to build UI/UX from scratch.
This guide help you integrate drop-in components in your non-react frameworks (angular, vuejs, vanillajs etc). If you want to build your own UI (headless) instead of using drop-in components please refer docs.
Integration
Integrate using script tag
This integration is used in Vanillajs, Django, Laravel, ruby etc where npm is not used.
Integrate as npm Package
This integration is used in framework based applications like angular, vuejs etc.
Removing Instance
Components will be removed automatically if you navigate away from the page (on unmounting). If you want to remove them manually, you can use below methods.
Update config options
Refreshing expired JWT user token
If your JWT token has TTL (expires) you can call your backend api to get refreshed token and update existing token with new one.
Accessing other instance methods
SDK internally calls new SuprSend()
when you call initSuprSend()
then you can access instance using window.suprsend.client
. This instance has methods like preferences, webpush, event and user updates.
Config Options
To customise SuprSend components you can pass config object.
Parameter | Description |
---|---|
publicApiKey | public api key is mandatory field without which error will be thrown by SuprSendProvider. You can get this from SuprSend Dashboard. |
distinctId | Unique identifier to identify a user across platform. If a value is passed SDK will create user and authenticate user. If null value is passed authenticated user’s instance data will be cleared in your application, kind of logout. |
userToken | Mandatory when enhanced security mode is on. This is ES256 JWT token generated in your server-side. Refer docs to create userToken. |
refreshUserToken | This function is called by SDK internally to get new userToken before existing token is expired. The returned JWT token string is used as the new userToken. |
userAuthenticationHandler | This callback will be called after authenticating user internally when you pass distinctId field to give you back the response of user creation api call. |
host | Customise the host url. |
vapidKey | This key is needed only if you are implementing WebPush notifications. You can get it in SuprSend Dashboard —> Vendors —> WebPush |
swFileName | This key is needed only if you are implementing WebPush notifications and want to customise default serviceworker.js file name with your own service worker file name. |
For further component specific customisations please refer to the docs.