Adzerk JavaScript/ Typescript 决定 SDK
用于 Adzerk 决定和用户DB API 的 JavaScript 软件开发工具
可使用的客户端或服务器侧为 TypeScript 或 JavaScript !
安装
通过国家预防机制的服务器
要求数 节点.js v20 或更高级.
npm install --save @adzerk/decision-sdk
通过 CDN 客户端
总是获取最新版本 :
<script src="https://unpkg.com/@adzerk/decision-sdk/dist/adzerk-decision-sdk.js"></script>
使用固定版本 :
<script src="https://unpkg.com/@adzerk/[email protected]/dist/adzerk-decision-sdk.js"></script>
实例
API 证书和必要的ID
- 网络ID: 登录到 Adzerk 用户界面 使用右上角的"circle-i"帮助菜单查找网络ID( C) 。 所有 SDK 操作都需要.
- 站点代号: 去 管理网站页面 寻找现场身份 获取广告决定时需要 .
- 代理类型 ID: 转到 Ad大小页面 查找 Ad Type 标识。 获取广告决定时需要 .
- API 密钥: 跳转到 API 密钥页面 找到活动的 API 密钥 。 写入 UserDB 时需要 .
- 用户密钥: 用户 DB ID 是 为每个用户指定或生成。 。 。 .
获取临时决定
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 });
});
记录印象并点击
与上面的获取示例一起使用 .
// 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"]}`);
});
用户DB: 读取用户记录
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));
用户DB: 设置自定义属性
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);
用户DB:忘记用户记录
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");
决定解释者
" 决定解释者 " 回复了关于 " 决定API " 请求的信息,解释为什么每个候选人的广告被选中或未被选中.
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 });
});
响应返回一个带有放置,桶,rtb日志以及结果信息的决定对象.
{
"div0": {
"placement": {},
"buckets": [],
"rtb_log": [],
"results": []
}
}
"放置"对象代表可以送达广告的决定. 解释者请求可以在请求中有多个位置. "buckets"阵列包含频道和优先级信息. "rtb logs"阵列包含实时竞价信息. "结果"阵列中包含了曾经和没有服役的候选广告列表,并附有简短的解释. |
日志
我们的伐木实施要足够灵活,以适应任何共同的节点JS伐木框架.
构建客户端实例时,登录器作为匿名函数传递,包含三个参数:
level: 任意之一debug, (中文(简体) ),info, (中文(简体) ),warn,或errormessage: 要日志的信件metadata: 与日志调用相关的任何额外元数据
若无 logger 作为论据提供 调试 库将默认使用.
最简单的整合方式是写出一个函数,处理从Adzerk SDK Logger中将数据转换成您在其余应用程序中使用的任何日志框架:
import { Client } from "@adzerk/decision-sdk";
const logger = (lvl, msg, meta) =>
console.log(`[${lvl}] ${msg} [${JSON.stringify(meta)}]\n`);
let client = new Client({ logger });
文档
捐款
报告问题
- 对于此 SDK 的错误修正和改进, 请使用 Github 打开一个问题 或者送我们一个 拉动请求。 。 。 .
- 有关Adzerk功能的问题或问题,请 联系人 Adzerk 支持。 。 。 .
构建/ 运行测试
要安装依赖关系并运行与此 SDK 相关的架构, 请使用 :
npm install
npm run build
npm run test