Secure signals are encoded data that is collected on the client device and shared with select bidders. This guide shows you how to collect and send secure signals to Google Ad Manager using the IMA SDK.
The secure signals API requires version 3.18.1 or higher of the IMA SDK for iOS.
To select signals and bidders, and enable secure signal sharing, see Share secure signals with bidders.
Use a third-party signal provider
To use secure signals, you must deploy a signal collector adapter class in your app to collect signals, encode them, and pass them to the IMA SDK.
Follow your third-party provider's instructions to set up an account with them, include frameworks, and set up their secure signals adapter in your app.
The IMA SDK for iOS automatically initializes each secure signals adapter, without any additional changes to your code.
Here's an example of how you might add a secure signals adapter to your project:
Send custom data
In addition to using a third-party signal provider, you can also collect, encode, and send signals with custom data. Before you can send secure signals with custom data, you must turn on custom signals in Ad Manager.
For each stream request, do the following:
- Create an
IMASecureSignals
object containing your encoded custom data as a string. - Add the
IMASecureSignals
object to your stream request by setting theIMAStreamRequest.secureSignals
attribute:
Objective-C
app/ViewController.m
- (void)requestStream {
// Create a stream request. Use one of "Livestream request" or "VOD request",
// depending on your type of stream.
IMAStreamRequest *request;
if (kStreamType == StreamTypeLive) {
// Livestream request. Replace the asset key with your value.
request = [[IMALiveStreamRequest alloc] initWithAssetKey:kLiveStreamAssetKey
networkCode:kNetworkCode
adDisplayContainer:self.adDisplayContainer
videoDisplay:self.imaVideoDisplay
userContext:nil];
} else {
// VOD request. Replace the content source ID and video ID with your values.
request = [[IMAVODStreamRequest alloc] initWithContentSourceID:kVODContentSourceID
videoID:kVODVideoID
networkCode:kNetworkCode
adDisplayContainer:self.adDisplayContainer
videoDisplay:self.imaVideoDisplay
userContext:nil];
}
IMASecureSignals *signals =
[[IMASecureSignals alloc] initWithCustomData:@"My encoded signal string"];
request.secureSignals = signals;
[self.adsLoader requestStreamWithRequest:request];
}
Swift
app/ViewController.swift
func requestStream() {
// Create a stream request. Use one of "Livestream request" or "VOD request".
let signals = IMASecureSignals(customData: "My encoded signal string")
if ViewController.requestType == StreamType.live {
// Livestream request.
let request = IMALiveStreamRequest(
assetKey: ViewController.assetKey,
networkCode: ViewController.networkCode,
adDisplayContainer: adDisplayContainer!,
videoDisplay: imaVideoDisplay,
userContext: nil)
request.secureSignals = signals
adsLoader?.requestStream(with: request)
} else {
// VOD stream request.
let request = IMAVODStreamRequest(
contentSourceID: ViewController.contentSourceID,
videoID: ViewController.videoID,
networkCode: ViewController.networkCode,
adDisplayContainer: adDisplayContainer!,
videoDisplay: imaVideoDisplay,
userContext: nil)
request.secureSignals = signals
adsLoader?.requestStream(with: request)
}
}