web-push-notifications-lite
v1.0.0
Published
Pushwoosh lite WebSDK
Downloads
2
Maintainers
Readme
Pushwoosh WebSDK Lite
Users subscribe to push notifications through the Pushwoosh endpoint (https://.chrome.pushwoosh.com/) in a separate window, so the SDK works for HTTP and with no need to add a ServiceWorker to your project.
1. Install the WebSDK Lite
1.1. Via html
<script type="text/javascript" src="//cdn.pushwoosh.com/webpush-lite/v1/pushwoosh-web-notifications-lite.js?pw_application_code=####-####&pw_autosubscribe=true" async></script>
1.2. Via npm
npm install web-push-notifications-lite --save
2. Integrate the WebSDK Lite
2.1. Via html
Add the following script to your website’s html:
<script type="text/javascript" src="//cdn.pushwoosh.com/webpush-lite/v1/pushwoosh-web-notifications-lite.js?pw_application_code=####-####&pw_autosubscribe=true" async></script>
where
- pw_application_code – the app code of your app in Pushwoosh,
- pw_autosubscribe – the parameter to enable automatic opening of the subscription window after the script is launched. To initialize the SDK manually, add the onload parameter to the script as follows:
<script type="text/javascript" src="//cdn.pushwoosh.com/webpush-lite/v1/pushwoosh-web-notifications-lite.js" async onload="document.dispatchEvent(new CustomEvent('pushwoosh.sdkload'))"></script>
<script>
document.addEventListener('pushwoosh.sdkload', function () {
window.pushwooshLite.instance.init('####-####', true);
});
</script>
2.2. Via npm
import {instance as pushwooshLite} from 'web-push-notifications-lite';
pushwooshLite.init('####-####', true);
Exports
- klass – a class of PushwooshLite;
- instance – the instance of the PushwooshLite class to use it as a singleton;
- LOCAL_STORAGE_ALLOW_NOTIFICATION_FLAG – a key to flag user interaction with the SDK in localStorage.
Public methods
- init(appCode: string, autosubscribe: boolean) – the method to initialize the SDK, where
- appCode – the app code of your app in Pushwoosh,
- autosubscribe – the parameter to enable automatic opening of the subscription window after the SDK is initialized;
- showSubscriptionWindow() – the method to open the subscription window.