安装
国家预防机制
您可以使用国家防范机制在项目中安装 SDK :
npm install @adhese/sdk
使用量
要使用 SDK, 您需要创建 Adhese 实例, 用您的账户 ID 配置 :
const adhese = createAdhese({
account: 'your-account-id',
});
自动在页面上找到槽
SDK可以自动找到页面上的所有槽并加载. 这是最容易开始的方法:
const adhese = createAdhese({
account: 'your-account-id',
findDomSlotsOnLoad: true,
});
通过查找带有 adunit 课。 要件必须具有:
data-format="YOUR_FORMAT" 属性设置在元素上,以便知道需要获取哪种格式.
示例 DOM 插槽 :
<div class="adunit" data-format="billboard"></div>
在 DOM 准备好之前获取槽
如果你想在DOM准备好之前取出槽,你可以通过 initialSlots 选项 createAdhese
函数。 如果您想要尽快启动获取进程, 这一点特别有用 。 下边是
需要事先知道哪个档位会出现在网页上.
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',
},
],
});
示例 HTML :
<div id="slot-1" class="adunit" data-format="billboard"></div>
<div id="slot-2" class="adunit" data-format="leaderboard"></div>
选项
这个 createAdhese 函数接受以下选项:
| 选项 | 类型 | 默认 | 说明 |
|---|---|---|---|
account* 联合国 | string | - 说吧 | 您的 Adhese 账户 ID |
host | string | 'https://{{account}}.ads.adhese.eu' | Adhese API 主机 |
poolHost | string | 'https://{{account}}.pool.adhese.eu' | 阿德塞游泳池主机 |
location | string | window.location.pathname | 页面位置. 用于确定当前页面位置标识符 . |
requestType | 'GET' 或者说 'POST' | 'POST' | 用于 Adhese API 请求的请求Ads 类型 。 这也可以是 GET 或者说 POST。 。 。 . POST 是默认的,并且提供了最多的选项. GET 比较有限,因为它需要通过数据作为搜索参数,但可以在下列环境中使用: POST 不允许提出请求. |
debug | boolean | false | 启用调试模式 |
findDomSlotsOnLoad | boolean | false | 自动在页面上找到槽并加载 |
parameters | Record<string, string, Array<string>> | {} | 附加参数随每项请求一起发送. 确保参数的密钥只包含 2 字符键. |
consent | boolean | false | 用户同意跟踪 |
initialSlots | Array<Slot> | [] | 在DOM准备好之前要取的槽 |
logReferrer | boolean | true | 将登录 document.referrer 给Adhese API的 BASE64 与 re 参数. |
logUrl | boolean | true | 将登录 location.href 给Adhese API的 BASE64 与 ur 参数. |
eagerRendering | boolean | false | 广告一收到就会制作 总而言之,建议保留这个 false 为了更好的表现. |
queries | Record<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)',} | 将用于确定设备类型和屏幕大小。 匹配的查询密钥将在 dt 财务报告和审定财务报表 br 参数. |
plugins | ReadonlyArray<(context: AdheseContext) => void> | [] | Adhese 实例所用的插件 。 这些插件使用Adhese语境调用,并在Adhese语境初始化期间运行. |
* 必需