Develop a secure signal adapter

If you have a signal provider SDK that generates real-time bidding (RTB) signals, you can develop a secure signal adapter to let Google Mobile Ads SDK collect signals from your SDK.

Google Mobile Ads SDK forwards your signals to selected participating Authorized Buyers and Open Bidding buyers.

The following diagram illustrates the request-response lifecycle for secure signal collection:

A secure signal adapter is responsible for adapter initialization and signal collection.

Implement a secure signal adapter

Implement a secure signal adapter for Google Mobile Ads SDK to collect signals from your SDK.

This guide covers how to implement a secure signal adapter by implementing the GADRTBAdapter protocol.

The following example implements the GADRTBAdapter protocol:

Objective-C

@interface SampleAdapterSnippets : NSObject <GADRTBAdapter>
@end

Initialize the adapter

Google Mobile Ads SDK calls the setUpWithConfiguration:completionHandler: method when Google Mobile Ads SDK instantiates your secure signal adapter. Use this method to initialize your SDK.

When your SDK initializes fully and is ready for Google Mobile Ads SDK to collect signals, call the GADMediationAdapterSetUpCompletionBlock completion block.

If your secure signals adapter doesn't call back, Google Mobile Ads SDK doesn't collect signals from your secure signal adapter.

The following example calls the completion handler to inform Google Mobile Ads SDK that your SDK has initialized successfully:

Objective-C

+ (void)setUpWithConfiguration:(GADMediationServerConfiguration *)configuration
             completionHandler:(GADMediationAdapterSetUpCompletionBlock)completionHandler {
  // Add your SDK initialization logic here.

  // Invoke the completionHandler once initialization completes. Pass a nil
  // error to indicate initialization succeeded.
  completionHandler(nil);
}

Report adapter and SDK version

Your secure signal adapter must report both your adapter version and your SDK version. Google Mobile Ads SDK uses these versions for reporting and troubleshooting.

If your SDK implements this adapter in the same binary, you can return the same version for both the adapter and SDK versions.

The following example returns the version of your secure signal adapter:

Objective-C

+ (GADVersionNumber)adapterVersion {
  // If your secure signals SDK implements this adapter in the same binary
  // return the same version as your SDK.
  // return [self adSDKVersion];

  // If you built a separate binary for this secure signals adapter, return
  // the adapter's version here.
  GADVersionNumber version = {};
  version.majorVersion = 4;
  version.minorVersion = 5;
  version.patchVersion = 6;
  return version;
}

The following example returns the version of your SDK that your secure signal adapter interacts with:

Objective-C

+ (GADVersionNumber)adSDKVersion {
  // Return your SDK's version string here.
  NSString *versionString = kSDKVersionString;
  NSArray<NSString *> *components = [versionString componentsSeparatedByString:@"."];
  GADVersionNumber version = {};
  if (components.count == 3) {
    version.majorVersion = components[0].integerValue;
    version.minorVersion = components[1].integerValue;
    version.patchVersion = components[2].integerValue;
  } else {
    NSLog(@"Unexpected version string: %@. Returning 0.0.0 for adSDKVersion.", versionString);
  }
  return version;
}

Replace kSDKVersionString with your SDK version string.

Collect signals

On every ad request, Google Mobile Ads SDK collects signals simultaneously from all adapters on a background thread.

The following example collects and returns signals to Google Mobile Ads SDK by calling the GADRTBSignalCompletionHandler completion handler:

Objective-C

- (void)collectSignalsForRequestParameters:(GADRTBRequestParameters *)params
                         completionHandler:(GADRTBSignalCompletionHandler)handler {
  // Add your signal collection logic here.
  NSString *signals = kSampleSignalPlaceholder;

  // Return the signals as a string to the Google Mobile Ads SDK.
  handler(signals, nil);
}

Replace kSampleSignalPlaceholder with your secure signal string.

Signal collection must complete within one second. If signal collection takes longer than one second, consider caching signals in your secure signal adapter or your SDK when you initialize the adapter.

If your secure signal adapter fails to collect signals, call the completion handler with nil signals and an NSError object.

Obfuscate signals

When you share secure signals with bidders and curation partners, you must obfuscate the signals.

Return a nil value for ad network extras

Secure signal adapters don't require additional network extras parameters.

The following example +networkExtrasClass method returns a nil value:

Objective-C

+ (nullable Class<GADAdNetworkExtras>)networkExtrasClass {
  // Network extras are not applicable because signal providers do not request ads.
  return nil;
}