You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/web-push.md
+84-84Lines changed: 84 additions & 84 deletions
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,6 @@ import notificationPopup from '@site/static/notificationPopup.png';
7
7
import notificationPreferences from '@site/static/notificationPreferences.png';
8
8
import webConsoleServiceWorker from '@site/static/webConsoleServiceWorker.png';
9
9
import notificationPreferencesReact from '@site/static/notificationPreferencesReact.png'
10
-
11
10
import notificationPreferencesPopupReact from '@site/static/notificationPreferencesPopupReact.png'
12
11
13
12
Web Push Notifications allow you to engage users directly through their web browsers, even when they're not on your website. This guide will walk you through setting up Web Push Notifications using NotificationAPI.
@@ -45,49 +44,13 @@ import TabItem from '@theme/TabItem';
| clientId\*| string | Your NotificationAPI account clientId. You can get it from [here](https://app.notificationapi.com/environments). |
80
-
| userId\*| string | The unique ID of the user in your system. |
81
-
| userIdHash | string | Only used for [Secure Mode](/guides/secure-mode). |
82
-
| websocket | string | Only if you want to specify your region, for example, if your account is in Canada region you must pass 'wss://ws.ca.notificationapi.com'. |
83
-
| language | string | The language used for the pre-built UI widgets. Supported: `en-US`, `es-ES`, `fr-FR`, `it-IT`, `pt-BR`|
84
-
| customServiceWorkerPath | string | Path to your service worker file if it's not at the root (e.g., '/custom/path/notificationapi-service-worker.js'). |
85
-
86
-
<sup>\*</sup> Required parameters
87
-
88
-
For more information please checkout our [vanilla JS SDK](/reference/js-client#setup--initialization) guide.
89
-
90
-
</TabItem>
91
54
92
55
<TabItemvalue="react">
93
56
```shell title="1. Install"
@@ -109,7 +72,6 @@ import { NotificationAPIProvider } from '@notificationapi/react';
109
72
// user={{
110
73
// id: "abcd-1234", // logged in userId
111
74
// }}
112
-
playSoundOnNewNotification={true} // Allow the user to hear default sound on new notification
113
75
>
114
76
{/* your protected routes */}
115
77
</NotificationAPIProvider>
@@ -131,6 +93,43 @@ For more information please checkout our [React SDK](/reference/react-sdk#setup)
131
93
132
94
</TabItem>
133
95
96
+
<TabItem value="vanilla">
97
+
98
+
```shell title="1. Install"
99
+
npm install notificationapi-js-client-sdk
100
+
# yarn add notificationapi-js-client-sdk
101
+
# pnpm add notificationapi-js-client-sdk
102
+
```
103
+
104
+
```js title="2. Import"
105
+
import NotificationAPI from 'notificationapi-js-client-sdk';
| clientId\* | string | Your NotificationAPI account clientId. You can get it from [here](https://app.notificationapi.com/environments). |
121
+
| userId\* | string | The unique ID of the user in your system. |
122
+
| userIdHash | string | Only used for [Secure Mode](/guides/secure-mode). |
123
+
| websocket | string | Only if you want to specify your region, for example, if your account is in Canada region you must pass 'wss://ws.ca.notificationapi.com'. |
124
+
| language | string | The language used for the pre-built UI widgets. Supported: `en-US`, `es-ES`, `fr-FR`, `it-IT`, `pt-BR` |
125
+
| customServiceWorkerPath | string | Path to your service worker file if it's not at the root (e.g., '/custom/path/notificationapi-service-worker.js'). |
126
+
127
+
<sup>\*</sup> Required parameters
128
+
129
+
For more information please checkout our [vanilla JS SDK](/reference/js-client#setup--initialization) guide.
130
+
131
+
</TabItem>
132
+
134
133
<TabItem value="umd">
135
134
136
135
```html title="1. Add to HTML, before </head>"
@@ -177,13 +176,25 @@ The service worker manages background tasks and is essential for receiving push
**Option 1: Rely on NotificationAPI Pre-Built component (Recommended)** If you are using our react SDK to show in-app notifications. You can simply rely on our SDK to ask your users to opt in for web push notification.
226
+
227
+
1. Place the `<NotificationPopup />` component inside the `NotificationAPIProvider` component. For more information on the component please checkout our [React SDK](/reference/react-sdk#popup) guide.
This would prompt the browser to ask for permission to show notifications. Alternatively, you can place the `<NotificationPreferencesPopup />` component inside the `NotificationAPIProvider` component. For more information on the component please checkout our [React SDK](/reference/react-sdk#preferences-popup) guide.
238
+
239
+
**Option 2: Using built-in method** You can place the code inside a component which is inside the `NotificationAPIProvider` provided by the React SDK and call the `askForWebPushPermission` function when the user interacts with your application.
**Option 1: Rely on NotificationAPI Pre-Built component (Recommended)** If you are using our react SDK to show in-app notifications. You can simply rely on our SDK to ask your users to opt infor web push notification.
255
-
256
-
1. Place the `<NotificationPopup />` component inside the `NotificationAPIProvider` component. For more information on the component please checkout our [React SDK](/reference/react-sdk#popup) guide.
This would prompt the browser to ask for permission to show notifications. Alternatively, you can place the `<NotificationPreferencesPopup />` component inside the `NotificationAPIProvider` component. For more information on the component please checkout our [React SDK](/reference/react-sdk#preferences-popup) guide.
267
-
268
-
**Option 2: Using built-in method** You can place the code inside a component which is inside the `NotificationAPIProvider` provided by the React SDK and call the `askForWebPushPermission`functionwhen the user interacts with your application.
Copy file name to clipboardExpand all lines: docs/reference/react-sdk.md
+21-3Lines changed: 21 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -133,6 +133,24 @@ For example, the web push service worker is placed at `public/service` folder an
133
133
</App>;
134
134
```
135
135
136
+
### webPushOptInMessage
137
+
138
+
The `webPushOptInMessage` controls whether the browser automatically prompts users for notification permissions (true or 'AUTOMATIC') or suppresses the prompt (false).
139
+
140
+
```jsx
141
+
<App>
142
+
<NotificationAPIProvider
143
+
userId="abcd-1234"// logged in userId
144
+
clientId="abc123"// your clientId found on the dashboard
145
+
webPushOptInMessage={true}
146
+
>
147
+
148
+
<!-- your protected routes -->
149
+
150
+
</NotificationAPIProvider>
151
+
</App>;
152
+
```
153
+
136
154
## In-App Notification Components
137
155
138
156
### Popup
@@ -541,12 +559,12 @@ To request permission for notifications, place the following code inside an asyn
541
559
notificiationapi.setWebPushOptIn(true);
542
560
```
543
561
544
-
## webPushOptInMessage
562
+
## setWebPushOptInMessage
545
563
546
-
This can be used to control the opt-in message for web push notifications. It can be set to either 'AUTOMATIC' or a boolean value.
564
+
The `setWebPushOptInMessage` controls whether the browser automatically prompts users for notification permissions (true or 'AUTOMATIC') or suppresses the prompt (false). It can be set to either 'AUTOMATIC' or a boolean value. It is an alternative to `webPushOptInMessage` inside the `<NotificationAPIProvider />` component.
0 commit comments