集成安全信号适配器
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
安全信号是在客户端设备上收集并与所选出价方共享的编码数据。本指南介绍了如何使用 IMA SDK 收集安全信号并将其发送到 Google Ad Manager。
安全信号 API 需要使用 4.8.2 或更高版本的 IMA SDK for tvOS。
如需选择信号和出价方并启用安全信号共享,请参阅与出价方共享安全信号。
使用第三方信号提供商
如需使用安全信号,您必须在应用中部署信号收集器适配器类,以收集信号、对其进行编码,然后将其传递给 IMA SDK。
按照第三方提供商的说明,向其设置账号,包括框架,并在应用中设置其安全信号适配器。
tvOS 版 IMA SDK 会自动初始化每个安全信号适配器,而无需对代码进行任何其他更改。
以下示例展示了如何向项目添加安全信号适配器:

发送自定义数据
除了使用第三方信号提供商之外,您还可以收集、编码和发送包含自定义数据的信号。您必须先在 Ad Manager 中启用自定义信号,然后才能发送包含自定义数据的安全信号。
针对每个广告请求,创建一个 IMASecureSignals
对象,其中包含以字符串形式编码的自定义数据。然后,通过调用 IMAAdsRequest.secureSignals
属性,将 IMASecureSignals
对象添加到广告请求中。
以下是 Objective-C 和 Swift 示例:
Objective-C
BasicExample/ViewController.m
...
- (void)requestAds {
// Create an ad display container for ad rendering.
IMAAdDisplayContainer *adDisplayContainer =
[[IMAAdDisplayContainer alloc] initWithAdContainer:self.videoView
viewController:self
companionSlots:nil];
// Create an ad request with our ad tag, display container, and optional user context.
IMAAdsRequest *request = [[IMAAdsRequest alloc] initWithAdTagUrl:kTestAppAdTagUrl
adDisplayContainer:adDisplayContainer
contentPlayhead:self.contentPlayhead
userContext:nil];
IMASecureSignals *signals =
[[IMASecureSignals alloc] initWithCustomData:@"My encoded signal string"];
request.secureSignals = signals;
[self.adsLoader requestAdsWithRequest:request];
}
...
Swift
BasicExample/ViewController.swift
...
private func requestAds() {
// Create ad display container for ad rendering.
let adDisplayContainer = IMAAdDisplayContainer(
adContainer: videoView, viewController: self, companionSlots: nil)
// Create an ad request with our ad tag, display container, and optional user context.
let request = IMAAdsRequest(
adTagUrl: ViewController.testAppAdTagURL,
adDisplayContainer: adDisplayContainer,
contentPlayhead: contentPlayhead,
userContext: nil)
let signals = IMASecureSignals(customData: "My encoded signal string")
request.secureSignals = signals
adsLoader.requestAds(with: request)
}
...
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eSecure signals, encoded data from client devices, are shared with specific bidders to enhance ad targeting.\u003c/p\u003e\n"],["\u003cp\u003eYou need to integrate a signal collector adapter and the IMA SDK (version 4.8.2 or higher for tvOS) to collect and send secure signals to Google Ad Manager.\u003c/p\u003e\n"],["\u003cp\u003eUtilize a third-party signal provider or, if eligible for a limited beta, send custom data as secure signals after enabling it in Ad Manager.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the provided code examples (Objective-C and Swift) for implementation guidance on adding secure signals to your ad requests.\u003c/p\u003e\n"]]],[],null,["Secure 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\nThe secure signals API requires version 4.8.2\nor higher of the IMA SDK for tvOS.\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\nTo use secure signals, you must deploy a signal collector\n\nadapter class in your app\n\nto collect signals, encode them, and pass them to the IMA SDK.\n\n\u003cbr /\u003e\n\nFollow your third-party provider's instructions to set up an account with them,\n\n[include frameworks](//developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/IncludingFrameworks.html),\n\nand set up their secure signals adapter in your app.\n\nThe IMA SDK for tvOS automatically\ninitializes each secure signals adapter, without any additional changes to your\ncode.\n\nHere's an example of how you might add a secure signals adapter to your project:\n\n\u003cbr /\u003e\n\nSend custom data\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\n\u003cbr /\u003e\n\nFor each ad request, create an `IMASecureSignals` object containing your\nencoded custom data as a string. Then, add the `IMASecureSignals` object to\nyour ad request by calling the `IMAAdsRequest.secureSignals` attribute.\n\nHere are samples in Objective-C and Swift: \n\nObjective-C\n\n**BasicExample/ViewController.m** \n\n ...\n - (void)requestAds {\n // Create an ad display container for ad rendering.\n IMAAdDisplayContainer *adDisplayContainer =\n [[IMAAdDisplayContainer alloc] initWithAdContainer:self.videoView\n viewController:self\n companionSlots:nil];\n // Create an ad request with our ad tag, display container, and optional user context.\n IMAAdsRequest *request = [[IMAAdsRequest alloc] initWithAdTagUrl:kTestAppAdTagUrl\n adDisplayContainer:adDisplayContainer\n contentPlayhead:self.contentPlayhead\n userContext:nil];\n IMASecureSignals \\*signals =\n \\[\\[IMASecureSignals alloc\\] initWithCustomData:@\"My encoded signal string\"\\];\n request.secureSignals = signals;\n [self.adsLoader requestAdsWithRequest:request];\n }\n ...\n\nSwift\n\n**BasicExample/ViewController.swift** \n\n ...\n private func requestAds() {\n // Create ad display container for ad rendering.\n let adDisplayContainer = IMAAdDisplayContainer(\n adContainer: videoView, viewController: self, companionSlots: nil)\n // Create an ad request with our ad tag, display container, and optional user context.\n let request = IMAAdsRequest(\n adTagUrl: ViewController.testAppAdTagURL,\n adDisplayContainer: adDisplayContainer,\n contentPlayhead: contentPlayhead,\n userContext: nil)\n let signals = IMASecureSignals(customData: \"My encoded signal string\")\n request.secureSignals = signals\n adsLoader.requestAds(with: request)\n }\n ..."]]