Example: Using redirects during subscription process
During subscription process there are a lot of callbacks that are described here. They can be used for any purposes such as logging or controlling subscription flow. In this example we solve common task - redirect all users that could not be subscribed to certain pages.
Example 1: Use one callback for all events
Using onPermissionCanNotAsk is a good idea when you want to redirect user on the same page in any case when he is not able to subscribe.
<script>
var s = document.createElement("script")
s.src = "https://notix.io/ent/current/enot.min.js"
s.onload = function (sdk) {
sdk.startInstall({
appId: "YOUR-APP-ID-HERE",
loadSettings: true
})
// Here is callback for redirecting user in any case
// when we can not ask permissions to display push notifications
sdk.SDKCaller.onPermissionCanNotAsk(() => {
window.location.replace("https://notix.co/?redirect=onPermissionCanNotAsk")
});
}
document.head.append(s)
</script>
Example 2: Use separate callback for each events
<script>
var s = document.createElement("script")
s.src = "https://notix.io/ent/current/enot.min.js"
s.onload = function (sdk) {
sdk.startInstall({
appId: "YOUR-APP-ID-HERE",
loadSettings: true
})
// This function is called when web site visitor grants permissions to receive push notifications
// or these permissions were granted earlier
sdk.SDKCaller.onPermissionAllowed(() => {
window.location.replace("https://notix.co/?redirect=onPermissionAllowed")
});
// This function is called when web site visitor denies permissions to receive push notifications
// or these permissions were rejected/denied earlier
sdk.SDKCaller.onPermissionDenied(() => {
window.location.replace("https://notix.co/?redirect=onPermissionDenied")
});
// 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.
sdk.SDKCaller.onAlreadySubscribed(() => {
window.location.replace("https://notix.co/?redirect=onAlreadySubscribed")
});
// This function is called when web site visitor uses browser
// that is incompatible with push notifications
sdk.SDKCaller.onNotificationUnsupported(() => {
window.location.replace("https://notix.co/?redirect=onNotificationUnsupported")
});
}
document.head.append(s)
</script>