集成安全信号适配器
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
安全信号是在客户端设备上收集并与所选出价方共享的编码数据。本指南介绍了如何使用 IMA SDK 收集安全信号并将其发送到 Google Ad Manager。
如需选择信号和出价方并启用安全信号共享,请参阅与出价方共享安全信号。
使用第三方信号提供商
如需使用安全信号,您必须在网站上部署信号收集器脚本,以收集信号、对其进行编码,并将其传递给 IMA SDK。
您可以自动或手动部署安全信号脚本。
自动部署
在 Ad Manager 中选择信号提供商时,根据您选择的信号提供商,您可能会看到让 Google 代表您部署信号收集脚本的选项。如果您选择此选项,并且您的网站包含 Google 发布商代码,系统会自动加载您选择的信号收集器脚本。
以下示例展示了您在 Ad Manager 界面中可能会看到的内容:

以下是您可能会在网站的 index.html
文件中看到的内容示例:
<script src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
<!-- Load gpt.js, which autoloads all signal provider scripts configured to be
deployed by Google. -->
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<script src="ads.js"></script>
手动部署
如果您在 Ad Manager 中没有看到让 Google 代表您部署信号收集脚本这一选项,或者您未开启此选项,则需要从安全信号提供商处获取脚本链接,并手动将其添加到您的项目中。
以下示例展示了您在 Ad Manager 界面中可能会看到的内容:

以下是您可能会在网站的 index.html
文件中看到的内容示例:
<script src="//imasdk.googleapis.com/js/sdkloader/ima3.js"></script>
<!-- Load signal provider scripts manually, using the unique instructions given by each
signal provider. -->
<script src="//cdn.provider1.com/files/a/e/5/4/7/signalCollector.js"></script>
<script src="//provider2.co.uk/ads/signalcollector/script.min.js"></script>
<script src="/local/path/to/third_party_signal_provider_3.js"></script>
<script src="ads.js"></script>
发送自定义数据
除了使用第三方信号提供商之外,您还可以收集、编码和发送包含自定义数据的信号。您必须先在 Ad Manager 中启用自定义信号,然后才能发送包含自定义数据的安全信号。
以下是 HTML5 项目的步骤:
- 创建一个包含以下属性的对象:
networkCode
和 collectorFunction
。
- 使用您的广告资源网代码填充
networkCode
属性。
- 使用一个函数填充
collectorFunction
属性,该函数会返回一个解析为编码信号的 promise。
在实例化 adsLoader
之前,将对象推送到 googletag.secureSignalProviders
数组,以便 IMA SDK 可以访问该对象来检索和传输编码后的信号:
以下是一个 JavaScript 示例:
console.log("initializing IMA");
adContainer = document.getElementById('ad-container');
adDisplayContainer = new google.ima.AdDisplayContainer(adContainer, videoElement);
const NETWORK_CODE = '21775744923';
/**
* Sample signal collector function.
* @return {!Promise<string>} A promise that resolves to the encoded signals.
*/
const signalCollector = () => {
return new Promise((resolve, reject) => {
resolve("My encoded signal string");
});
};
if (!googletag) googletag = {};
if (!googletag.secureSignalProviders) googletag.secureSignalProviders = [];
googletag.secureSignalProviders.push({
networkCode: NETWORK_CODE,
collectorFunction: signalCollector
});
adsLoader = new google.ima.AdsLoader(adDisplayContainer);
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eSecure signals are encoded data collected on devices and shared with specific bidders to enhance ad targeting.\u003c/p\u003e\n"],["\u003cp\u003eYou can deploy secure signal scripts automatically through Google Ad Manager or manually by including provider scripts in your project.\u003c/p\u003e\n"],["\u003cp\u003eCustom data can be sent as secure signals using a collector function that returns encoded signals, after enabling the feature in Ad Manager.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize secure signals, you need to implement a signal collector script for data collection, encoding, and transmission to the IMA SDK.\u003c/p\u003e\n"]]],[],null,["# Integrate secure signals adapters\n\nSecure signals are encoded data that is collected on the client device and\nshared with select bidders. This guide shows you how to collect and send secure\nsignals to Google Ad Manager using the IMA SDK.\n\nTo select signals and bidders, and enable secure signal sharing, see [Share\nsecure signals with bidders](//support.google.com/admanager/answer/10488752).\n\nUse a third-party signal provider\n---------------------------------\n\nTo use secure signals, you must deploy a signal collector\n\nscript on your site\n\nto collect signals, encode them, and pass them to the IMA SDK.\n\nYou deploy secure signals scripts either automatically or manually.\n\n### Deploy automatically\n\nWhen selecting signal providers in Ad Manager, depending on your selected signal\nproviders, you might get the option to **Ask Google to deploy the signal\ncollection script on your behalf** . If you select this option, and your site\nincludes [Google Publisher Tags](/publisher-tag/guides/get-started), the signal\ncollector scripts you chose are loaded automatically.\n\nHere's an example of what you might see in the [Ad Manager\nUI](//admanager.google.com/):\n\nHere's an example of what you might see in your site's `index.html` file: \n\n \u003cscript src=\"//imasdk.googleapis.com/js/sdkloader/ima3.js\"\u003e\u003c/script\u003e\n \u003c!-- Load gpt.js, which autoloads all signal provider scripts configured to be\n deployed by Google. --\u003e\n \u003cscript async src=\"https://securepubads.g.doubleclick.net/tag/js/gpt.js\"\u003e\u003c/script\u003e\n \u003cscript src=\"ads.js\"\u003e\u003c/script\u003e \n https://github.com/googleads/googleads-ima-html5/blob/857dd5019edba73ca0bd50046ae6a739fa4cd70b/doc_snippets/secure_signals/auto_load.html#L8-L12\n\n### Deploy manually\n\nIf you don't see the option **Ask Google to deploy the signal collection script\non your behalf** in Ad Manager or if you don't turn on this option, you need to\nget a script link from your secure signals provider and manually include it in\nyour project.\n\nHere's an example of what you might see in the [Ad Manager\nUI](//admanager.google.com/):\n\nHere's an example of what you might see in your site's `index.html` file: \n\n \u003cscript src=\"//imasdk.googleapis.com/js/sdkloader/ima3.js\"\u003e\u003c/script\u003e\n \u003c!-- Load signal provider scripts manually, using the unique instructions given by each\n signal provider. --\u003e\n \u003cscript src=\"//cdn.provider1.com/files/a/e/5/4/7/signalCollector.js\"\u003e\u003c/script\u003e\n \u003cscript src=\"//provider2.co.uk/ads/signalcollector/script.min.js\"\u003e\u003c/script\u003e\n \u003cscript src=\"/local/path/to/third_party_signal_provider_3.js\"\u003e\u003c/script\u003e\n \u003cscript src=\"ads.js\"\u003e\u003c/script\u003e \n https://github.com/googleads/googleads-ima-html5/blob/857dd5019edba73ca0bd50046ae6a739fa4cd70b/doc_snippets/secure_signals/manual_load.html#L8-L14\n\nSend custom data\n----------------\n\nIn addition to using a third-party signal provider, you can also collect,\nencode, and send signals with custom data. Before you can send secure signals\nwith custom data, you must turn on custom signals in Ad Manager.\n\nHere are the steps for HTML5 projects:\n\n1. Create an object with these properties: `networkCode` and `collectorFunction`.\n2. Populate the `networkCode` property with your [network code](//support.google.com/admanager/answer/7674889).\n3. Populate the `collectorFunction` property with a function that returns a promise that resolves to your encoded signals.\n\nPush the object to the `googletag.secureSignalProviders` array before\ninstantiating your `adsLoader` so that the IMA SDK can access it to retrieve and\ntransmit your encoded signals:\n\nHere's a javascript example: \n\n console.log(\"initializing IMA\");\n adContainer = document.getElementById('ad-container');\n adDisplayContainer = new google.ima.AdDisplayContainer(adContainer, videoElement);\n\n const NETWORK_CODE = '21775744923';\n\n /**\n * Sample signal collector function.\n * @return {!Promise\u003cstring\u003e} A promise that resolves to the encoded signals.\n */\n const signalCollector = () =\u003e {\n return new Promise((resolve, reject) =\u003e {\n resolve(\"My encoded signal string\");\n });\n };\n if (!googletag) googletag = {};\n if (!googletag.secureSignalProviders) googletag.secureSignalProviders = [];\n googletag.secureSignalProviders.push({\n networkCode: NETWORK_CODE,\n collectorFunction: signalCollector\n });\n\n adsLoader = new google.ima.AdsLoader(adDisplayContainer); \n https://github.com/googleads/googleads-ima-html5/blob/857dd5019edba73ca0bd50046ae6a739fa4cd70b/doc_snippets/secure_signals/auto_load.js"]]