Pushwoosh Web Push Notification SDK
=========================

[![GitHub release](https://img.shields.io/github/release/Pushwoosh/web-push-notifications.svg)](https://github.com/Pushwoosh/web-push-notifications/releases)
[![npm](https://img.shields.io/npm/v/web-push-notifications.svg)](https://www.npmjs.com/package/web-push-notifications)
![platforms](https://img.shields.io/badge/platforms-Chrome%20%7C%20Firefox%20%7C%20Safari-green.svg)

This guide describes how to use the Pushwoosh Web Push Notification SDK when installed via npm.

## Installation

Install the SDK using npm:

```bash
npm install web-push-notifications --save
```

## Usage Example

```js
import { Pushwoosh } from 'web-push-notifications';
import { PWSubscriptionButtonWidget } from 'web-push-notifications/widget-subscription-button'
import { PWSubscriptionPromptWidget } from './widgets/SubscriptionPrompt/SubscriptionPromptWidget';

const pwInstance = new Pushwoosh();
pwInstance.push(['init', {
  apiToken: 'XXXXXXX', //  Device API Token
  applicationCode: 'XXXXX-XXXXX', // your application code from Pushwoosh Control Panel
  safariWebsitePushID: 'web.com.example.domain', // unique reverse-domain string from Apple Developer Portal (Safari only)
  defaultNotificationTitle: 'Pushwoosh', // default title for push notifications
  defaultNotificationImage: 'https://yoursite.com/img/logo-medium.png', // custom notification image URL
  autoSubscribe: false, // or true. If true, prompts user to subscribe on SDK initialization
  userId: 'user_id', // optional, set custom user ID
  subscribeWidget: {
    enable: true
  },
}]);

pwInstance.push(function(api) {
  console.log('Pushwoosh ready');
});

pwInstance.push(async () => {
  try {
    const widget = new PWSubscriptionButtonWidget(pwInstance)
    await widget.run()
  } catch (error) {
    console.error('Error during Pushwoosh Subscription Button initialization:', error);
  }
});
pwInstance.push(async () => {
  try {
    const widget = new PWSubscriptionPromptWidget(globalPW);
    await widget.run();
  } catch (error) {
    console.error('Error during Pushwoosh Subscription Prompt initialization:', error);
  }
});


```

For more details, see the [official documentation](https://www.pushwoosh.com/docs/web-push-sdk-30).

See an example application with React and Vite: https://github.com/Pushwoosh/websdk-npm-vite-react-example

