Detect subscription state using Javascript

This example shows how to detect subscription state from page and change it's content. For example you can hide/display subscription button. Detailed documentation can be found here.

Subscription state: ALLOWED
Subscription state: DENIED
Subscription state: UNSUPPORTED

Example

        <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,
                    step0: "waitClick",
                    clickSelector: "#click-for-subscribe-button"
                })

                sdk.SDKCaller.onPermissionAllowed(() => {
                    console.log("onPermissionAllowed callback")
                    setVisibility('allowed')
                });

                sdk.SDKCaller.onPermissionDenied(() => {
                    console.log("onPermissionDenied callback")
                    setVisibility('denied')
                });

                sdk.SDKCaller.onAlreadySubscribed(() => {
                    console.log("onAlreadySubscribed callback")
                    setVisibility('allowed')
                });

                sdk.SDKCaller.onNotificationUnsupported(() => {
                    console.log("onNotificationUnsupported callback")
                    setVisibility('unsupported')
                });

                sdk.SDKCaller.onPermissionCanNotAsk(() => {
                    // Here we hide element that is used for triggering subscription prompt
                    console.log("onPermissionCanNotAsk callback")
                    document.querySelector('#click-for-subscribe-button').style.display = 'none'
                });

            }
            document.head.append(s)
        </script>