@adzerk/decision-sdk

中文文档
1.0.0-beta.30发布于 2026/06/17Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 3.7万

SDK for interacting with Adzerk's Decision API

原始使用文档
文档目录16 节
  1. Installation
  2. Server-Side via NPM
  3. Client-Side via CDN
  4. Examples
  5. API Credentials & Required IDs
  6. Fetching an Ad Decision
  7. Recording Impression & Clicks
  8. UserDB: Reading User Record
  9. UserDB: Setting Custom Properties
  10. UserDB: Forgetting User Record
  11. Decision Explainer
  12. Logging
  13. Documentation
  14. Contributing
  15. Reporting Issues
  16. Building / Running Tests

Adzerk JavaScript/Typescript Decision SDK

JavaScript Software Development Kit for Adzerk Decision & UserDB APIs

Usable client or server-side as TypeScript or JavaScript!

Installation

NPM Package

Server-Side via NPM

Requires Node.js v20 or higher.

npm install --save @adzerk/decision-sdk

Client-Side via CDN

Always fetches the latest version:

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

Using a fixed version:

<script src="https://unpkg.com/@adzerk/[email protected]/dist/adzerk-decision-sdk.js"></script>

Examples

API Credentials & Required IDs

  • Network ID: Log into Adzerk UI & use the "circle-i" help menu in upper right corner to find Network ID. Required for all SDK operations.
  • Site ID: Go to Manage Sites page to find site IDs. Required when fetching an ad decision.
  • Ad Type ID: Go to Ad Sizes page to find Ad Type IDs. Required when fetching an ad decision.
  • API Key: Go to API Keys page find active API keys. Required when writing to UserDB.
  • User Key: UserDB IDs are specified or generated for each user.

Fetching an Ad Decision

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

// Demo network, site, and ad type IDs; find your own via the Adzerk 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.

// 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

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

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

UserDB: Setting Custom Properties

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

// Demo network ID; find your own via the Adzerk 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

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

const apiKey = process.env.ADZERK_API_KEY;

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

Decision Explainer

The Decision Explainer returns information on a Decision API request explaining why each candidate ad was or was not chosen.

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 Adzerk 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 });
});

The response returns a decision object with placement, buckets, rtb logs, and result information.

{
  "div0": {
    "placement": {},
    "buckets": [],
    "rtb_log": [],
    "results": []
  }
}

The "placement" object represents a decision in which an ad may be served. A Explainer Request can have multiple placements in the request. The "buckets" array contains channel and priority information. The "rtb_logs" array contains information about Real Time Bidding. The "results" array contains the list of candidate ads that did and did not serve, along with a brief explanation. |

Logging

Our logging implementation is meant to be flexible enough to fit into any common NodeJS logging framework.

When constructing a client instance, the logger is passed in as an anonymous function with three parameters:

  • level: Any one of debug, info, warn, or error
  • message: The message to log
  • metadata: Any additional metadata related to the logging call

If no logger is provided as an argument, the debug library will be used by default.

The easiest way to integrate is to write a function that handles translating the data from the Adzerk SDK Logger into whatever logging framework you're using in the rest of your application:

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

const logger = (lvl, msg, meta) =>
  console.log(`[${lvl}] ${msg} [${JSON.stringify(meta)}]\n`);

let client = new Client({ logger });

Documentation

Contributing

Reporting Issues

Building / Running Tests

To install dependencies and run the builds associated with this SDK, please use:

npm install
npm run build
npm run test

版本与发布记录

@adzerk/decision-sdk 共发布 30 个版本,首次发布于 2020/04/29;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.0.0-beta.30latest2026/06/174 个月前
1.0.0-beta.292026/03/177 个月前
1.0.0-beta.282025/10/181.1 年前
1.0.0-beta.272025/04/101.6 年前
1.0.0-beta.262025/01/311.8 年前
1.0.0-beta.252023/10/043 年前

关于 @adzerk/decision-sdk 的常见问题

@adzerk/decision-sdk 是什么?

SDK for interacting with Adzerk's Decision API

如何安装 @adzerk/decision-sdk?

在项目目录运行 npm install @adzerk/decision-sdk,或使用 pnpm add / yarn add / bun add。

@adzerk/decision-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adzerk/decision-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adzerk/decision-sdk 可以商用吗?

@adzerk/decision-sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adzerk/decision-sdk 的下载量有多少?

根据 npm 官方下载统计,@adzerk/decision-sdk 在 2026/10/05 – 2026/11/03 这 30 天内被下载 36,699 次,日均约 1,223 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adzerk/decision-sdk 还在维护吗?

最新版本 1.0.0-beta.30 发布于 2026/06/17(4 个月前);至今共发布 30 个版本,其中过去 12 个月发布了 2 个;首次发布于 2020/04/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。