# Web Push Notifications

This section will cover how you can setup Web Push as a channel on Growlytics. Before you start, make sure you've integrated the [Browser SDK](https://docs.growlytics.in/integration/browser/installation), setup will not work otherwise.

{% hint style="info" %}
Supported browsers are: Chrome, Firefox, Microsoft Edge, and Opera
{% endhint %}

## Step 1: Generate WebPush Credentials

To send web push notifications, VAPID credentials are required according to [specification](https://tools.ietf.org/html/draft-thomson-webpush-vapid-02)s. Growlytics takes care of generating credentials for you. But if you already have used credentials elsewhere, you can configure the same credentials.

* Login to Growlytics dashboard.
* At the top right corner, click on *Integrations*  > *Web Push Notification*
* Click on Generate VAPID keys if you don't already have the keys else you can provide the VAPID public and private keys in input box.
* Click on save changes.

## Step 2: Configure Browser Sdk

Web Push requires service worker to be registered. &#x20;

Add service worker script in your project. You can use Growlytics provided service worker template or if you already have service worker implemented in your project you can add Growlytics's service worker script.

* Download service worker file from [here](https://static.growlytics.in/web_push/growlytics_sw_template.js). Add this service worker file at root of your project with any name  like `growlytics-sw.js`.&#x20;
* Once, you have added service worker file in your project, inform Growlytics to use that service worker file by providing URL of that file against  `serviceWorkerFile`attribute at g`rowlyticsSettings` variable which is being used in the Growlytics script. An example is given below. &#x20;

```javascript
// Initialize Growlytics
let growlyticsSettings = {
    
    //.... Other Growlytics Settings
    
    // Configure push notifications, For more details, visit https://docs.growlytics.in/channels/web-push-notifications
    webPushEnabled: true, // Enable/disable web push module, disabled if not provided
    // Fully qualified URL of service worker file
    serviceWorkerFile: 'service worker file location'
};
```

{% hint style="info" %}
Also make sure `webPushEnabled` flag is set to true in `growlyticsSettings`variable being passed to Growlytics script.
{% endhint %}

## **Step 3: Requesting User Permissions**

If you have disabled auto-request permission at page load from dashboard, you can also use `requestNotificationPermission()`method anytime to ask for notification permission. An example is given below.

```javascript
Growlytics.requestNotificationPermission();
```

With the above integration steps, you should be able to send push notifications to users using Growlytics campaigns.

## Additional Notes

Payload structure of web push notification sent from Growlytics will have following structure.

| Key         | Data Type | Description                                                                                             |
| ----------- | --------- | ------------------------------------------------------------------------------------------------------- |
| glytcs\_pnf | boolean   | If this field is present, means notification is received from Growlytics.                               |
| glytcs\_id  | string    | Notification tracking id used by Growlytics.                                                            |
| glytcs\_icn | string    | Url of an notification icon. If given, this URL will be used to show small application in notification. |
| glytcs\_img | string    | Url of an notification Image. If given, this URL will be used to show large image in notification.      |
| glytcs\_tl  | string    | Notification title, must be present or app name will be used as title.                                  |
| glytcs\_msg | string    | Notification body, must be present, if not provided, notification will not be shown.                    |
| glytcs\_dl  | string    | If present, this is a deep link that must be followed at the time of notification open.                 |
