@bonniernews/bn-google-ad-manager-api

中文文档
1.1.1发布于 2026/10/05ISCTypeScriptCommonJS近 30 天下载 2380

This repo is a fork of https://github.com/thewizarodofoz/google-ad-manager-api to update dependencies, functionality and add typing for the different gam services.

原始使用文档
文档目录8 节
  1. Features
  2. Install
  3. Usage
  4. Step #1
  5. Step #2:
  6. Step #3
  7. Step #4
  8. Notes

This repo is a fork of https://github.com/thewizarodofoz/google-ad-manager-api to update dependencies, functionality and add typing for the different gam services.

We have tried to keep the overall structure intact, but we moved the authorization to its own step for readability reasons. Checkout Step #2 for the change and Step #3 for code removal.

BN Google Ad Manager Node Api

A modern wrapper around Google's Ad Manager API.

Features

  • Promise based - use Promise or async/await
  • Non opinionated about auth mechanisms - obtain a token however you like
  • Typed (TypeScript-ish)

Install

npm i @BonnierNews/bn-google-ad-manager-api

Usage

Step #1

Obtain an access token in whatever way you like, for example using Google Auth Library's JSON Web Tokens mechanism:

const { auth } = require("google-auth-library");

const keys = {
  type: "service_account",
  project_id: "...",
  private_key_id: "...",
  private_key: "...",
  client_email: "...",
  client_id: "...",
  auth_uri: "https://accounts.google.com/o/oauth2/auth",
  token_uri: "https://oauth2.googleapis.com/token",
  auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
  client_x509_cert_url: "...",
};

const client = auth.fromJSON(keys);
client.scopes = ["https://www.googleapis.com/auth/dfp"];
await client.authorize();

Step #2:

Create a client and authorize it with the google auth credentials token from step #1:

import { DFPClient, GAMClient } from "@BonnierNews/bn-google-ad-manager-api";

// To maintain backwards compatability we keep the DFP client intact with the option to use our own client.
// Both have the same functions

const dfpClient = new DFPClient();
await dfpClient.authorize({ networkCode: "...", apiVersion: "v201805", accessToken: client.credentials.access_token });

// or with gamClient
const gamClient = new GAMClient();
await gamClient.authorize({ networkCode: "...", apiVersion: "v201805", accessToken: client.credentials.access_token });

Step #3

Use the client to create a service.

const lineItemService = await dfpClient.getService("LineItemService");

// or

const lineItemService = await gamClient.getService("LineItemService");

Step #4

Invoke service methods:

const res = await lineItemService.getLineItemsByStatement({
  filterStatement: {
    query: "WHERE name LIKE 'prebid%'",
  },
});

console.log(res.results[0].id);

Notes

  • The Ad Manager API returns an rval field for each method invocation. To make things easier for us, this package will return the content of that field. For example, invocation of LineItemService.getLineItemsByStatement will return a LineItemPage object directly.
  • Google auth tokens have expiration dates and they need to be updated or refreshed in some way. Because authentication management is outside the scope of this package, make sure to always pass the new tokens to the services instances using service.setToken.

版本与发布记录

@bonniernews/bn-google-ad-manager-api 共发布 7 个版本,首次发布于 2023/11/14;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.1.1latest2026/10/051 个月前
1.1.02026/09/082 个月前
1.0.42025/09/081.2 年前
1.0.32025/05/231.5 年前
1.0.22024/02/272 年前
1.0.12024/01/182 年前

关于 @bonniernews/bn-google-ad-manager-api 的常见问题

@bonniernews/bn-google-ad-manager-api 是什么?

This repo is a fork of https://github.com/thewizarodofoz/google-ad-manager-api to update dependencies, functionality and add typing for the different gam services.

如何安装 @bonniernews/bn-google-ad-manager-api?

在项目目录运行 npm install @bonniernews/bn-google-ad-manager-api,或使用 pnpm add / yarn add / bun add。

@bonniernews/bn-google-ad-manager-api 支持 TypeScript 吗?

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

@bonniernews/bn-google-ad-manager-api 支持 ESM 还是 CommonJS?

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

@bonniernews/bn-google-ad-manager-api 可以商用吗?

@bonniernews/bn-google-ad-manager-api 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bonniernews/bn-google-ad-manager-api 的下载量有多少?

根据 npm 官方下载统计,@bonniernews/bn-google-ad-manager-api 在 2026/10/09 – 2026/11/07 这 30 天内被下载 2,380 次,日均约 79 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bonniernews/bn-google-ad-manager-api 还在维护吗?

最新版本 1.1.1 发布于 2026/10/05(1 个月前);至今共发布 7 个版本,其中过去 12 个月发布了 2 个;首次发布于 2023/11/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。