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 extending the RtbAdapter abstract class.

The following example extends the RtbAdapter abstract class:

Java

  public 
  
 class 
 SampleAdapterSnippets 
  
 extends 
  
 RtbAdapter 
  
 { 
  
 

Initialize the adapter

Google Mobile Ads SDK calls the initialize() 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 InitializationCompleteCallback callback.

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 callback to inform Google Mobile Ads SDK that your SDK has initialized successfully:

Java

  @Override 
 public 
  
 void 
  
 initialize 
 ( 
  
 Context 
  
 context 
 , 
  
 InitializationCompleteCallback 
  
 initializationCompleteCallback 
 , 
  
 List<MediationConfiguration> 
  
 configurations 
 ) 
  
 { 
  
 // Add your SDK initialization logic here. 
  
 // Invoke the InitializationCompleteCallback once initialization completes. 
  
 initializationCompleteCallback 
 . 
 onInitializationSucceeded 
 (); 
 } 
  
 

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:

Java

  @Override 
 public 
  
 VersionInfo 
  
 getVersionInfo 
 () 
  
 { 
  
 // If your SDK implements this adapter in the same binary, return 
  
 // the same version as your SDK. 
  
 // return getSDKVersionInfo(); 
  
 // If you built a separate binary for this adapter, return 
  
 // the adapter's version here. 
  
 int 
  
 major 
  
 = 
  
 4 
 ; 
  
 int 
  
 minor 
  
 = 
  
 5 
 ; 
  
 int 
  
 micro 
  
 = 
  
 6 
 ; 
  
 return 
  
 new 
  
 VersionInfo 
 ( 
 major 
 , 
  
 minor 
 , 
  
 micro 
 ); 
 } 
  
 

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

Java

  @Override 
 public 
  
 VersionInfo 
  
 getSDKVersionInfo 
 () 
  
 { 
  
 // Return your SDK's version string here. 
  
 String 
  
 versionString 
  
 = 
  
  SDK_VERSION_STRING 
 
 ; 
  
 String 
 [] 
  
 splits 
  
 = 
  
 versionString 
 . 
 split 
 ( 
 "\\." 
 ); 
  
 if 
  
 ( 
 splits 
 . 
 length 
  
> = 
  
 3 
 ) 
  
 { 
  
 try 
  
 { 
  
 int 
  
 major 
  
 = 
  
 Integer 
 . 
 parseInt 
 ( 
 splits 
 [ 
 0 
 ] 
 ); 
  
 int 
  
 minor 
  
 = 
  
 Integer 
 . 
 parseInt 
 ( 
 splits 
 [ 
 1 
 ] 
 ); 
  
 int 
  
 micro 
  
 = 
  
 Integer 
 . 
 parseInt 
 ( 
 splits 
 [ 
 2 
 ] 
 ); 
  
 return 
  
 new 
  
 VersionInfo 
 ( 
 major 
 , 
  
 minor 
 , 
  
 micro 
 ); 
  
 } 
  
 catch 
  
 ( 
 NumberFormatException 
  
 e 
 ) 
  
 { 
  
 // Fall through to log warning and return 0.0.0. 
  
 } 
  
 } 
  
 Log 
 . 
 w 
 ( 
  
 TAG 
 , 
  
 String 
 . 
 format 
 ( 
  
 "Unexpected SDK version format: %s. Returning 0.0.0 for SDK version." 
 , 
  
 versionString 
 )); 
  
 return 
  
 new 
  
 VersionInfo 
 ( 
 0 
 , 
  
 0 
 , 
  
 0 
 ); 
 } 
  
 

Replace SDK_VERSION_STRING 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 SignalCallbacks.onSuccess() method:

Java

  @Override 
 public 
  
 void 
  
 collectSignals 
 ( 
 RtbSignalData 
  
 rtbSignalData 
 , 
  
 SignalCallbacks 
  
 signalCallbacks 
 ) 
  
 { 
  
 // Add your signal collection logic here. 
  
 String 
  
 signals 
  
 = 
  
  SAMPLE_SIGNAL_PLACEHOLDER 
 
 ; 
  
 // Return the signals as a string to the Google Mobile Ads SDK. 
  
 signalCallbacks 
 . 
 onSuccess 
 ( 
 signals 
 ); 
 } 
  
 

Replace SAMPLE_SIGNAL_PLACEHOLDER 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, pass an error to the signalCallbacks.onFailure() method.

Obfuscate signals

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

Create a Mobile Website
View Site in Mobile | Classic
Share by: