Using JavaScript callbacks during subscription process
Notix publisher can observe user behavior during subscription process. All significant events that happen can produce JavaScript callbacks. Website owner can perform different actions for different users with the use of these callbacks basing on users’ subscription statuses.
Possible callback list
onPermissionAllowed
This function is called when web site visitor grants permissions to receive push notifications
Typical reasons that lead to this event:
- user presses "Allow" button
- user grants permissions to send notifications for all web sites
onPermissionDenied
This function is called when web site visitor denies permissions to receive push notifications.
Typical reasons that lead to this event:
- user presses "Deny" button
- user presses "close" button a few times
- user declines receiving push notifications (and ask permissions) for all sites
onAlreadySubscribed
This function is called when web site page loads and visitor has already granted permissions for receiving push notifications. It's called just after page loading, without any user actions.
onNotificationUnsupported
This function is called when web site visitor uses browser that is incompatible with push notifications.
This could be caused by:
- using old browser
- viewing web site using something like Smart TV or other "smart" device
- using rare/exotic browser without implementation of required APIs
onPermissionDefault
This function is called when user presses "cross" on permission dialog, which closes permission request dialog without accepting or declining.
Example
This quite simple example shows how to call a piece of JavaScript code when some event happens with user.
<script> const s = document.createElement("script") s.src = "/tag/enot.min.js" s.onload = (sdk) => { sdk.startInstall({ appId: "10040ee1360a7b45f857499340ae4dd", step0: "skip", }); sdk.SDKCaller.onPermissionAllowed(() => { console.log("onPermissionAllowed callback") }); sdk.SDKCaller.onPermissionDenied(() => { console.log("onPermissionDenied callback") }); sdk.SDKCaller.onAlreadySubscribed(() => { console.log("onAlreadySubscribed callback") }); sdk.SDKCaller.onNotificationUnsupported(() => { console.log("onNotificationUnsupported callback") }); sdk.SDKCaller.onPermissionDefault(() => { console.log("onPermissionDefault callback") }); } document.head.append(s) </script>