# JavaScript (web)

### Installation

```shell
$ npm install --save @progressively/sdk-js
```

### Usage

#### Create an SDK instance

```javascript
import { Progressively } from "@progressively/sdk-js";

const options = {
  apiUrl: "your url server",
  websocketUrl: "your url server for websockets",
};

const sdk = Progressively.init("YOUR_ENVIRONMENT_CLIENT_KEY", options);
```

The `options` object can also receive other (optional) attributes such as **fields** and **initialFlags**

**fields** is an option that allows passing data about your users to restrain the audience eligibility. For instance, you can set an email field, and in Progressively's dashboard, you can create a rule that only targets people that matches that field:

```javascript
const options = {
  apiUrl: "your url server",
  websocketUrl: "your url server for websockets",
  fields: {
    email: "@progressively.com",
  },
};
```

**initialFlags** is an option that is mostly used for server-side rendering. You should not directly use it in your code, except if you are building a server integration that does not yet.

#### Load the flags

```javascript
sdk.loadFlags();
```

#### Listen to WebSockets updates

```javascript
sdk.onFlagUpdate((nextFlags) => {}, optionalUserId);
```

#### Disconnect the WebSockets

```javascript
sdk.disconnect();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://progressively.gitbook.io/docs/developpers/sdks/javascript-web.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
