---
updatedAt: 2026-08-01T11:27:33.000Z
agentTools:
  projectIndex: https://dev.kevel.com/llms.txt
---

# JavaScript Decision SDK

This page describes the JavaScript Software Development Kit for Kevel Decision & UserDB APIs. You will find examples that you can use for client-side and server-side applications using TypeScript or JavaScript.

* [Open Source on Github](https://github.com/adzerk/adzerk-decision-sdk-js)
* [NPM Package](https://www.npmjs.com/package/@adzerk/decision-sdk)

## Installation

### Server-Side via NPM

```shell
npm install --save @adzerk/decision-sdk
```

### Client-Side via CDN

To fetch the latest version of the Decision SDK from the CDN, add the script tag below.

```html
<script src="https://unpkg.com/@adzerk/decision-sdk/dist/adzerk-decision-sdk.js"></script>
```

If you are pinning to a fixed version, use this instead:

```html
<script src="https://unpkg.com/@adzerk/decision-sdk@1.0.0-beta.2/dist/adzerk-decision-sdk.js"></script>
```

## Examples

### Fetching an Ad Decision

```javascript
import { Client } from "@adzerk/decision-sdk";

// Demo network, site, and ad type IDs; find your own via the Kevel UI!
let client = new Client({ networkId: 23, siteId: 667480 });

let request = {
  placements: [{ adTypes: [5] }],
  user: { key: "abc" },
  keywords: ["keyword1", "keyword2"]
};

client.decisions.get(request).then(response => {
  console.dir(response, { depth: null });
});
```

### Recording Impression & Clicks

Use with the fetch ad example above.

```javascript
// Impression pixel; fire when user sees the ad
client.pixels.fire({ url: decision.impressionUrl });

// Click pixel; fire when user clicks on the ad
// status: HTTP status code
// location: click target URL
client.pixels.fire({ url: decision.clickUrl }).then(r => {
  console.log(`status ${r["status"]}; location: ${r["location"]}`);
});
```

### UserDB: Reading User Record

```javascript
import { Client } from "@adzerk/decision-sdk";

// Demo network ID; find your own via the Kevel UI!
let client = new Client({ networkId: 23 });
client.userDb.read("abc").then(response => console.log(response));
```

### UserDB: Setting Custom Properties

```javascript
import { Client } from "@adzerk/decision-sdk";

// Demo network ID; find your own via the Kevel UI!
let client = new Client({ networkId: 23 });

let props = {
  favoriteColor: "blue",
  favoriteNumber: 42,
  favoriteFoods: ["strawberries", "chocolate"]
};

client.userDb.setCustomProperties("abc", props);
```

### UserDB: Forgetting User Record

```javascript
import { Client } from "@adzerk/decision-sdk";

const apiKey = process.env.ADZERK_API_KEY;

// Demo network ID and API key; find your own via the Kevel UI!
let client = new Client({ networkId: 23, apiKey });
client.userDb.forget("abc");
```

### Decision Explainer

```javascript
import { Client } from "@adzerk/decision-sdk";

const apiKey = process.env.ADZERK_API_KEY;

// Demo network, site, and ad type IDs; find your own via the Kevel UI!
let client = new Client({ networkId: 23, siteId: 667480 });

let request = {
  placements: [{ adTypes: [5] }],
  user: { key: "abc" },
  keywords: ["keyword1", "keyword2"]
};

const options = {
  includeExplanation: true,
  apiKey
};

client.decisions.get(request, options).then(response => {
  console.dir(response, { depth: null });
});
```

### Using CNAME

When using CNAME, you can use this syntax, where your CNAME is `engine.yourdomain.com`:

```javascript
let client = new AdzerkDecisionSdk.Client({ networkId: 10328, siteId: 1157752, host: "engine.yourdomain.com" });
```

### Sending User Agent When Firing Impression Pixels

To send a user agent when firing impression pixels, use the following:

```javascript
client.pixels.fire(
  { url: 'pixel url here' },
  { userAgent: navigator.userAgent }
)
```