# Initial configuration

### Introduction

To enable browser-based push notifications, you must integrate the OneSignal SDK into your web application. This allows Thalamus to identify unique users via a `playerId`.

The integration follows a two-step process:

1. Initialize OneSignal: Use the SDK to enable push notifications on your website.
2. Associate Player ID: Sync the generated `playerId` with a Thalamus consumer (using the API methods documented previously).

> For more detailed information on the provider's capabilities, refer to the [OneSignal Documentation](https://documentation.onesignal.com/docs).

***

### Client-Side Implementation (JavaScript)

Add the following script to the `<head>` section of every page where users can subscribe to notifications.

#### Required Variables

| **Variable**     | **Type** | **Description**                                                                                               |
| ---------------- | -------- | ------------------------------------------------------------------------------------------------------------- |
| `appid`          | String   | Required. The OneSignal App ID provided by Thalamus.                                                          |
| `urlAddPlayerId` | String   | Required. The endpoint on your server that will handle the association logic (See Server-Side Documentation). |

#### Integration Code (Javascript)

```
<script src="https://code.jquery.com/jquery-3.3.1.min.js" async=""></script>
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>

<script>
    var OneSignal = window.OneSignal || [];
    var appid = "876203bc-1517-42ac-8eea-ad98e4aa7515"; // Replace with your App ID
    var urlAddPlayerId = "www.example.com/add-player-id.php";

    var sendPlayerId = function(playerId) {
        if (!playerId) return;

        $.ajax(urlAddPlayerId, {
            method: 'POST',
            data: {
                playerid: playerId,
                appid: appid
            }
        })
        .then(
            function success(response) {
                console.log('Success: Player ID synced. ' + response);
            },
            function fail(data, status) {
                console.log('Error: Sync failed. Status: ' + status);
            }
        );
    };

    OneSignal.push(function() {
        OneSignal.init({
            appId: appid,
        });

        OneSignal.getUserId(sendPlayerId);
    });
</script>
```
