{"_id":"@alertwise/alertwise-web-sdk","_rev":"2-013f30cca13d52e802f1a7dd9a1f7336","name":"@alertwise/alertwise-web-sdk","dist-tags":{"latest":"1.2.2"},"versions":{"1.2.0":{"name":"@alertwise/alertwise-web-sdk","version":"1.2.0","keywords":["alertwise","notifications","web-sdk"],"author":{"name":"AlertWise Solutions LLP"},"license":"MIT","_id":"@alertwise/alertwise-web-sdk@1.2.0","maintainers":[{"name":"alertwise","email":"admin@alertwise.net"}],"homepage":"https://github.com/alertwise-admin/alertwise-web-sdk#readme","bugs":{"url":"https://github.com/alertwise-admin/alertwise-web-sdk/issues"},"dist":{"shasum":"7c19bcf4063066ed653fc1a43b8705e6ad18954f","tarball":"https://registry.npmjs.org/@alertwise/alertwise-web-sdk/-/alertwise-web-sdk-1.2.0.tgz","fileCount":41,"integrity":"sha512-2bV6eVEorOjB7goarDKETtZwVwSnc1z27FLhyltQrTzrh7/AGSlV18ry/ZdxfQq6d4vt3+XP1GzADslFZXdGzA==","signatures":[{"sig":"MEYCIQDSIkYOUPyx5jsnHgiyLqEeKfHepd8ZgUI2KluviGO3LAIhAPMCbn03wEm4drormmJVGo8+6Q8tLmVbwea+bePmZGKF","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":166441},"main":"dist/alert-wise.js","types":"dist/index.d.ts","gitHead":"9bd1f00832720dfe09df68ff894c5134c0db7d85","scripts":{"test":"jest","build":"npm run clean && tsc --emitDeclarationOnly && webpack --mode=production","clean":"rimraf dist","serve":"webpack serve --mode=development","start":"webpack serve --mode=development","watch":"webpack --watch","build:dev":"webpack --mode=development"},"_npmUser":{"name":"alertwise","email":"admin@alertwise.net"},"repository":{"url":"git+https://github.com/alertwise-admin/alertwise-web-sdk.git","type":"git"},"_npmVersion":"11.5.1","description":"AlertWise is a push notification service for web and mobile apps. This SDK makes it easy to integrate your website with AlertWise Push Notifications. https://alertwise.net","directories":{},"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^30.0.3","rimraf":"^5.0.10","postcss":"^8.4.47","ts-jest":"^29.4.0","webpack":"^5.101.3","prettier":"^3.3.3","ts-loader":"^9.5.1","typescript":"^5.6.3","@types/jest":"^30.0.0","@types/uuid":"^10.0.0","webpack-cli":"^6.0.1","autoprefixer":"^10.4.20","postcss-loader":"^8.1.1","webpack-dev-server":"^5.2.2","html-webpack-plugin":"^5.6.0","clean-webpack-plugin":"^4.0.0","terser-webpack-plugin":"^5.3.10","jest-environment-jsdom":"^30.0.2","node-polyfill-webpack-plugin":"^4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/alertwise-web-sdk_1.2.0_1758783723059_0.11825382747664093","host":"s3://npm-registry-packages-npm-production"}},"1.2.2":{"name":"@alertwise/alertwise-web-sdk","version":"1.2.2","main":"dist/alert-wise.js","types":"dist/index.d.ts","scripts":{"clean":"rimraf dist","build":"npm run clean && webpack --mode=production","build:dev":"webpack --mode=development","start":"webpack serve --mode=development","test":"jest","watch":"webpack --watch","serve":"webpack serve --mode=development"},"description":"AlertWise is a push notification service for web and mobile apps. This SDK makes it easy to integrate your website with AlertWise Push Notifications. https://alertwise.net","author":{"name":"AlertWise Solutions LLP"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/alertwise-admin/alertwise-web-sdk.git"},"bugs":{"url":"https://github.com/alertwise-admin/alertwise-web-sdk/issues"},"keywords":["alertwise","notifications","web-sdk"],"publishConfig":{"access":"public"},"devDependencies":{"@types/jest":"^30.0.0","@types/uuid":"^10.0.0","autoprefixer":"^10.4.20","clean-webpack-plugin":"^4.0.0","html-webpack-plugin":"^5.6.0","jest":"^30.0.3","jest-environment-jsdom":"^30.0.2","node-polyfill-webpack-plugin":"^4.0.0","postcss":"^8.4.47","postcss-loader":"^8.1.1","prettier":"^3.3.3","rimraf":"^5.0.10","terser-webpack-plugin":"^5.3.10","ts-jest":"^29.4.0","ts-loader":"^9.5.1","typescript":"^5.6.3","webpack":"^5.101.3","webpack-cli":"^6.0.1","webpack-dev-server":"^5.2.2"},"_id":"@alertwise/alertwise-web-sdk@1.2.2","gitHead":"1e85225e30dbb3c55f7d96495b163529cf982781","homepage":"https://github.com/alertwise-admin/alertwise-web-sdk#readme","_nodeVersion":"22.14.0","_npmVersion":"11.5.1","dist":{"integrity":"sha512-mhjz6enY2Dua6h2ztETnpeovW4YC2iD74lDKA2J7B3ehMKwAROoo6xQv0mLR+tBjJ7Qy6El5P0qgDaT1DqLLvw==","shasum":"1009b1c7473af9a7f4995e61a95ce313c669ec82","tarball":"https://registry.npmjs.org/@alertwise/alertwise-web-sdk/-/alertwise-web-sdk-1.2.2.tgz","fileCount":51,"unpackedSize":169232,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIAYAGKe7lcvWRu+bUKSL12nvtsv+7trnah8/lQYtyADHAiBp+684wnoYYL2mTMbiROwiW3zT2aiZdUzNu7Xm93l0Jg=="}]},"_npmUser":{"name":"alertwise","email":"admin@alertwise.net"},"directories":{},"maintainers":[{"name":"alertwise","email":"admin@alertwise.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/alertwise-web-sdk_1.2.2_1763708009171_0.5060883960472182"},"_hasShrinkwrap":false}},"time":{"created":"2025-09-25T07:02:03.000Z","modified":"2025-11-21T06:53:29.595Z","1.2.0":"2025-09-25T07:02:03.295Z","1.2.2":"2025-11-21T06:53:29.388Z"},"bugs":{"url":"https://github.com/alertwise-admin/alertwise-web-sdk/issues"},"author":{"name":"AlertWise Solutions LLP"},"license":"MIT","homepage":"https://github.com/alertwise-admin/alertwise-web-sdk#readme","keywords":["alertwise","notifications","web-sdk"],"repository":{"type":"git","url":"git+https://github.com/alertwise-admin/alertwise-web-sdk.git"},"description":"AlertWise is a push notification service for web and mobile apps. This SDK makes it easy to integrate your website with AlertWise Push Notifications. https://alertwise.net","maintainers":[{"name":"alertwise","email":"admin@alertwise.net"}],"readme":"# AlertWise Web SDK\r\n\r\n[![NPM version](https://img.shields.io/npm/v/@alertwise/alertwise-web-sdk.svg)](https://www.npmjs.com/package/@alertwise/alertwise-web-sdk)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n\r\nThe official AlertWise Web SDK for integrating web push notifications into your website.\r\n\r\n[AlertWise](https://alertwise.net) is a powerful push notification service for web and mobile apps. This SDK makes it\r\nincredibly easy to integrate your website with AlertWise, enabling you to engage with your users through timely and\r\nrelevant push notifications.\r\n\r\n## Features\r\n\r\n- **Easy Integration**: Get up and running in minutes with a simple initialization script.\r\n- **Customizable Prompts**: Choose from a variety of pre-built, customizable opt-in prompts (Banner, Bell, Pop-up, etc.)\r\n  to match your site's design.\r\n- **Subscription Widgets**: Add persistent widgets to allow users to subscribe or unsubscribe at any time.\r\n- **Audience Segmentation**: Group subscribers into segments for targeted messaging.\r\n- **Event Tracking**: Track user interactions and trigger automated notification campaigns.\r\n- **Cross-Browser Support**: Works seamlessly across all major browsers that support web push notifications.\r\n- **In-App Browser Handling**: Gracefully handles scenarios where your site is opened in a social media in-app browser.\r\n\r\n## Installation\r\n\r\nYou can integrate the AlertWise Web SDK in two ways: using the CDN or by installing it as an npm package.\r\n\r\n### 1. Using CDN\r\n\r\nThe easiest way to get started is to add the following script tag to the `<head>` section of your website's HTML file.\r\n\r\n```html\r\n\r\n<script src=\"https://cdn.alertwise.net/alertwise/integrate/service-worker.js\" async></script>\r\n```\r\n\r\n### 2. Using npm/yarn\r\n\r\nIf you are using a bundler like Webpack or Rollup, you can install the SDK from npm.\r\n\r\n```bash\r\n  npm install @alertwise/alertwise-web-sdk\r\n```\r\n\r\nor\r\n\r\n```bash\r\n  yarn add @alertwise/alertwise-web-sdk\r\n```\r\n\r\nThen, import it into your main application file:\r\n\r\n```javascript\r\nimport '@alertwise/alertwise-web-sdk';\r\n```\r\n\r\n## Quick Start\r\n\r\nAfter installing the SDK, you need to initialize it with your Application ID.\r\n\r\n### 1. Add the Service Worker\r\n\r\nWeb push notifications require a service worker file.\r\n\r\n1. Download the `service-worker.js` file from the SDK. You can get it from the CDN\r\n   link: https://cdn.alertwise.net/alertwise/integrate/service-worker.js.\r\n2. Place this `service-worker.js` file in the **root directory** of your website.\r\n\r\nIf you cannot place the file in the root directory, you can specify a different path during initialization.\r\n\r\n### 2. Initialize the SDK\r\n\r\nAdd the following initialization code to your website. If you're using the CDN, place it just before the closing\r\n`</body>` tag.\r\n\r\n```html\r\n\r\n<script>\r\n    // This array will hold commands until the SDK is fully loaded.\r\n    window.alertwise = window.alertwise || [];\r\n\r\n    // Initialize AlertWise with your App ID\r\n    alertwise.push(['init', {\r\n        appId: 'YOUR_APP_ID'\r\n        // Add other configuration options here if needed\r\n    }]);\r\n</script>\r\n```\r\n\r\nReplace `'YOUR_APP_ID'` with the Application ID you obtained from your AlertWise dashboard.\r\n\r\nThat's it! The SDK will now automatically handle showing the opt-in prompt based on the settings you've configured in\r\nyour AlertWise dashboard.\r\n\r\n## Configuration\r\n\r\nThe `init` command accepts a configuration object with the following options:\r\n\r\n| Option                        | Type      | Required | Description                                                                                      |\r\n|-------------------------------|-----------|----------|--------------------------------------------------------------------------------------------------|\r\n| `appId`                       | `string`  | **Yes**  | Your unique Application ID from the AlertWise dashboard.                                         |\r\n| `serviceWorkerUrl`            | `string`  | No       | The path to your service worker file. Defaults to `/service-worker.js`.                          |\r\n| `scope`                       | `string`  | No       | The scope of the service worker registration. Defaults to `/`.                                   |\r\n| `isSubscriptionOnSubDomain`   | `boolean` | No       | Set to `true` if you are using a custom subdomain for subscriptions. Defaults to `false`.        |\r\n| `isUniversalSubscriptionLink` | `boolean` | No       | Set to `true` if you are using a universal subscription link. Defaults to `false`.               |\r\n| `language`                    | `string`  | No       | Manually set the language for the prompts, overriding the browser's default. (e.g., 'en', 'es'). |\r\n| `defaultNotificationImage`    | `string`  | No       | A URL for a default notification icon if one is not provided in a campaign.                      |\r\n| `alertwiseApiUrl`             | `string`  | No       | For self-hosted or enterprise plans, you can specify a custom API endpoint.                      |\r\n\r\n**Example with more options:**\r\n\r\n```javascript\r\nalertwise.push(['init', {\r\n    appId: 'YOUR_APP_ID',\r\n    serviceWorkerUrl: '/custom-sw.js'\r\n}]);\r\n```\r\n\r\n## API Reference\r\n\r\nOnce initialized, you can interact with the SDK using the `alertwise` global object.\r\n\r\n### `alertwise.push(command)`\r\n\r\nThis is the main method for interacting with the SDK.\r\n\r\n- **Initialization**: `alertwise.push(['init', { appId: '...' }])`\r\n- **Function Execution**: You can push a function to be executed once the SDK is ready.\r\n\r\n```javascript\r\nalertwise.push(function () {\r\n    console.log('AlertWise SDK is ready!');\r\n    // You can now safely use other API methods\r\n    alertwise.getSubscriberId().then(id => {\r\n        console.log('Subscriber ID:', id);\r\n    });\r\n});\r\n```\r\n\r\n### `alertwise.subscribe()`\r\n\r\nManually trigger the subscription process. This will show the browser's native permission prompt.\r\n\r\n```javascript\r\n// Example: Trigger subscription from a custom button click\r\ndocument.getElementById('my-subscribe-button').addEventListener('click', function () {\r\n    alertwise.subscribe();\r\n});\r\n```\r\n\r\n### `alertwise.unsubscribe()`\r\n\r\nUnsubscribe the current device from receiving push notifications.\r\n\r\n```javascript\r\nalertwise.unsubscribe();\r\n```\r\n\r\n### `alertwise.getPermission()`\r\n\r\nReturns a `Promise<NotificationPermission>` with the current notification permission status (`'granted'`, `'denied'`, or\r\n`'default'`).\r\n\r\n```javascript\r\nalertwise.getPermission().then(permission => {\r\n    console.log('Current permission status:', permission);\r\n});\r\n```\r\n\r\n### `alertwise.getSubscriberId()`\r\n\r\nReturns a `Promise<string | undefined>` with the unique ID of the current subscriber.\r\n\r\n```javascript\r\nalertwise.getSubscriberId().then(subscriberId => {\r\n    if (subscriberId) {\r\n        console.log('User is subscribed with ID:', subscriberId);\r\n    } else {\r\n        console.log('User is not subscribed.');\r\n    }\r\n});\r\n```\r\n\r\n### `alertwise.addSegment(segmentId)`\r\n\r\nAdd the current subscriber to one or more segments.\r\n\r\n- `segmentId`: `string | string[]` - A single segment ID or an array of segment IDs.\r\n\r\n```javascript\r\n// Add to a single segment\r\nalertwise.addSegment('premium_users');\r\n\r\n// Add to multiple segments\r\nalertwise.addSegment(['newsletter_subscribers', 'product_updates']);\r\n```\r\n\r\n### `alertwise.removeSegment(segmentId)`\r\n\r\nRemove the current subscriber from one or more segments.\r\n\r\n- `segmentId`: `string | string[]` - A single segment ID or an array of segment IDs.\r\n\r\n```javascript\r\nalertwise.removeSegment('premium_users');\r\n```\r\n\r\n## Events\r\n\r\nThe SDK dispatches `CustomEvent` objects on the `window` for various actions. You can listen for these events to trigger\r\nyour own application logic.\r\n\r\n| Event Name                          | Description                                                                                                         |\r\n|-------------------------------------|---------------------------------------------------------------------------------------------------------------------|\r\n| `AlertWise.onReady`                 | Fired when the SDK has been successfully initialized.                                                               |\r\n| `AlertWise.onSubscribe`             | Fired when a user successfully subscribes. The `event.detail` object contains `subscriber` and `subscription` info. |\r\n| `AlertWise.onUnsubscribe`           | Fired when a user successfully unsubscribes.                                                                        |\r\n| `AlertWise.onPermissionGranted`     | Fired when the user grants notification permission.                                                                 |\r\n| `AlertWise.onPermissionDenied`      | Fired when the user denies notification permission.                                                                 |\r\n| `AlertWise.onNotificationDisplayed` | Fired when a notification is displayed to the user.                                                                 |\r\n| `AlertWise.onNotificationClick`     | Fired when a user clicks on a notification.                                                                         |\r\n| `AlertWise.onNotificationClose`     | Fired when a user closes a notification.                                                                            |\r\n| `AlertWise.onSDKError`              | Fired when an error occurs within the SDK.                                                                          |\r\n\r\n**Example: Listening for the `onSubscribe` event**\r\n\r\n```javascript\r\nwindow.addEventListener('AlertWise.onSubscribe', function (event) {\r\n    console.log('User subscribed!', event.detail);\r\n    const subscriberId = event.detail.subscriber.id;\r\n    // You can now associate this subscriberId with your internal user ID\r\n});\r\n```\r\n\r\n## License\r\n\r\nSee the LICENSE file for details.\r\n","readmeFilename":"README.md"}