React OneSignal
![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)
This is a JavaScript module that can be used to easily include OneSignal code in a website or app that uses React for its front-end codebase.
OneSignal is the world's leader for Mobile Push Notifications, Web Push, and In-App Messaging. It is trusted by 800k businesses to send 5 billion Push Notifications per day.
You can find more information on OneSignal here.
Install
You can use yarn
or npm
.
Yarn
yarn add react-onesignal
npm
npm install --save react-onesignal
Usage
Simply initialize OneSignal with your token:
import OneSignal from 'react-onesignal';
OneSignal.initialize('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx');
Advanced Usage
Player ID
Player ID is an important information on OneSignal.
You can use getPlayerId
to obtain it.
const playerId = await OneSignal.getPlayerId();
Notification Permission Management
To manage notifications:
- Use
notificationPermission
to see all possible states. - Use
getNotificationPermission
to check current notification permissions. - Use
registerForPushNotifications
to ask for notification permissions.
const permissions = OneSignal.notificationPermission;
const currentState = await OneSignal.getNotificationPermission();
await OneSignal.registerForPushNotifications();
User Email Tracking
You can use setEmail
and getEmailId
to track user email.
OneSignal.setEmail('my_email@example.com');
const emailId = await OneSignal.getEmailId();
Contributing
Pull requests are welcome! If you have any feedback, issue or suggestion, feel free to open a new issue so we can talk about it 💬.
License
MIT © pedro-lb