web-push-notifications
TypeScript icon, indicating that this package has built-in type declarations

3.45.0 • Public • Published

Pushwoosh Web Push Notification SDK

GitHub release npm platforms

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

Installation

Install the SDK using npm:

npm install web-push-notifications --save

Usage Example

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.

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

Package Sidebar

Install

npm i web-push-notifications

Weekly Downloads

1,152

Version

3.45.0

License

MIT

Unpacked Size

679 kB

Total Files

101

Last publish

Collaborators

  • pushwoosh-max