JSPM

  • Created
  • Published
  • Downloads 1031
  • Score
    100M100P100Q144830F
  • License MIT

Pushwoosh web push notifications

Package Exports

  • web-push-notifications
  • web-push-notifications/npm.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (web-push-notifications) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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