@adhese/sdk

中文文档
1.13.2发布于 2026/11/05GPL-3.0TypeScriptESM + CJS构建来源已验证近 30 天下载 6835

Adhese SDK

原始使用文档
文档目录6 节
  1. Installation
  2. NPM
  3. Usage
  4. Automatically find slots on the page
  5. Fetching slots before DOM is ready
  6. Options

Installation

NPM

You can install the SDK into your project using NPM:

npm install @adhese/sdk

Usage

To use the SDK, you need to create an Adhese instance and configure it with your account ID:

const adhese = createAdhese({
  account: 'your-account-id',
});

Automatically find slots on the page

The SDK can automatically find all slots on the page and load them. This is the easiest way to get started:

const adhese = createAdhese({
  account: 'your-account-id',
  findDomSlotsOnLoad: true,
});

Slots are found by looking for elements with the adunit class. The element is required to have a data-format="YOUR_FORMAT" attribute set on the element to know which format needs to be fetched.

Example DOM slots:

<div class="adunit" data-format="billboard"></div>

Fetching slots before DOM is ready

If you want to fetch slots before the DOM is ready, you can pass the initialSlots option to the createAdhese function. This is particularly useful if you want to start the fetching process as soon as possible. Downside is that you need to know which slots are going to be on the page on beforehand.

const adhese = createAdhese({
  account: 'your-account-id',
  initialSlots: [
    {
      containingElement: 'slot-1', // ID of the element that contains the slot
      format: 'billboard',
    },
    {
      containingElement: 'slot-2', // ID of the element that contains the slot
      format: 'leaderboard',
    },
  ],
});

Example HTML:

<div id="slot-1" class="adunit" data-format="billboard"></div>
<div id="slot-2" class="adunit" data-format="leaderboard"></div>

Options

The createAdhese function accepts the following options:

OptionTypeDefaultDescription
account*string-Your Adhese account ID
hoststring'https://{{account}}.ads.adhese.eu'The Adhese API host
poolHoststring'https://{{account}}.pool.adhese.eu'The Adhese pool host
locationstringwindow.location.pathnameThe page location. This is used to determine the current page location identifier.
requestType'GET' or 'POST''POST'The requestAds type to use for the Adhese API requests. This can be either GET or POST. POST is the default and offers the most options. GET is more limited as it needs pass its data as search parameters but can be used in environments where POST requests are not allowed.
debugbooleanfalseEnable debug mode
findDomSlotsOnLoadbooleanfalseAutomatically find slots on the page and load them
parametersRecord<string, string, Array<string>>{}Additional parameters to send with each request. Make sure that the keys of a parameter only contain 2 characters.
consentbooleanfalseUser consent for tracking
initialSlotsArray<Slot>[]Slots to fetch before the DOM is ready
logReferrerbooleantrueWill log the document.referrer to the Adhese API in a BASE64 string with the re parameter.
logUrlbooleantrueWill log the location.href to the Adhese API in a BASE64 string with the ur parameter.
eagerRenderingbooleanfalseWill render the ad as soon as it is fetched. In general it is recommended to keep this false for better performance.
queriesRecord<string, string>{phone: '(max-width: 768px) and (pointer: coarse)',tablet: '(min-width: 769px) and (max-width: 1024px) and (pointer: coarse)',desktop: '(min-width: 1025px) and (pointer: fine)',}Will be used to determine the device type and screen size. The matching query key will be passed in the dt and br parameter.
pluginsReadonlyArray<(context: AdheseContext) => void>[]The plugins that are used for the Adhese instance. These plugins are called with the Adhese context and run during the initialization of the Adhese instance.

* Required

版本与发布记录

@adhese/sdk 共发布 250 个版本,首次发布于 2024/03/22;过去 12 个月发布了 71 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.13.2latest2026/11/05今天
1.13.2-nightly-20261105093040nightly2026/11/051 天前
1.13.12026/10/2710 天前
1.13.1-nightly-202610270804472026/10/2710 天前
1.13.1-nightly-202610270758582026/10/2710 天前
1.13.02026/10/2115 天前

关于 @adhese/sdk 的常见问题

@adhese/sdk 是什么?

Adhese SDK

如何安装 @adhese/sdk?

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

@adhese/sdk 支持 TypeScript 吗?

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

@adhese/sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@adhese/sdk 可以商用吗?

@adhese/sdk 使用 GPL-3.0 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以 GPL-3.0 兼容许可开源,并附带专利与反锁定条款。仅内部使用不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@adhese/sdk 的下载量有多少?

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

@adhese/sdk 还在维护吗?

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