Setup

Custom events let you add waterfall mediation for an ad network that isn't a supported ad network . You do this by implementing a custom event adapter for the ad network you want to integrate.

You can find a full sample custom event project in our GitHub repo .

Prerequisites

Before you can create custom events, you must first integrate one of the following ad format into your app:

Create a custom event in the UI

A custom event must first be created in the AdMob UI. See the instructions in Add a custom event .

You need to supply the following:

Class Name

The fully-qualified name of the class that implements the custom event adapter—for example, SampleCustomEvent ; or if your class is implemented in Swift, MediationExample.SampleCustomEventSwift .

Target name is required if you have multiple targets in your project or if the project name is different from the target name. With the target name, it would look like this: appName_targetName.className . In addition, remember to replace any non-alphanumeric characters such as dashes with underscores. Example .

Label

A unique name defining the ad source.

Parameter

An optional string argument passed to your custom event adapter.

Implement GADMediationAdapter

The first step to creating a custom event is implementing the GADMediationAdapter protocol as shown by the SampleCustomEvent class in our example .

It is the responsibility of this class to receive messages from AdMob and delegate the responsibility of creating the correct ad format.

Initialize the adapter

When Google Mobile Ads SDK initializes, setUpWithConfiguration:completionHandler: is invoked on all supported third-party adapters and custom events configured for the app within the AdMob UI. Use this method to perform any necessary setup or initialization on the required third-party SDK for your custom event.

Swift

  import 
  
 GoogleMobileAds 
 class 
  
 SampleCustomEvent 
 : 
  
 NSObject 
 , 
  
 MediationAdapter 
  
 { 
  
 static 
  
 func 
  
 setUpWith 
 ( 
  
 _ 
  
 configuration 
 : 
  
 MediationServerConfiguration 
 , 
  
 completionHandler 
 : 
  
 @ 
 escaping 
  
 GADMediationAdapterSetUpCompletionBlock 
  
 ) 
  
 { 
  
 // This is where you will initialize the SDK that this custom event is built 
  
 // for. Upon finishing the SDK initialization, call the completion handler 
  
 // with success. 
  
 completionHandler 
 ( 
 nil 
 ) 
  
 } 
 } 
 

Objective-C

  #import "SampleCustomEvent.h" 
 @implementation 
 SampleCustomEvent 
 + 
 ( 
 void 
 ) 
 setUpWithConfiguration: 
 ( 
 nonnull 
  
 GADMediationServerConfiguration 
  
 * 
 ) 
 configuration 
  
 completionHandler 
 :( 
 nonnull 
  
 GADMediationAdapterSetUpCompletionBlock 
 ) 
 completionHandler 
  
 { 
  
 // This is where you initialize the SDK that this custom event is built 
  
 // for. Upon finishing the SDK initialization, call the completion handler 
  
 // with success. 
  
 completionHandler 
 ( 
 nil 
 ); 
 } 
 

Report version numbers

All custom events must report to Google Mobile Ads SDK both the version of the custom event adapter itself and the version of the third-party SDK the custom event interfaces with. Versions are reported as GADVersionNumber objects:

Swift

  static 
  
 func 
  
 adSDKVersion 
 () 
  
 - 
>  
 VersionNumber 
  
 { 
  
 let 
  
 versionComponents 
  
 = 
  
 String 
 ( 
 SampleSDKVersion 
 ). 
 components 
 ( 
  
 separatedBy 
 : 
  
 "." 
 ) 
  
 if 
  
 versionComponents 
 . 
 count 
  
> = 
  
 3 
  
 { 
  
 let 
  
 majorVersion 
  
 = 
  
 Int 
 ( 
 versionComponents 
 [ 
 0 
 ]) 
  
 ?? 
  
 0 
  
 let 
  
 minorVersion 
  
 = 
  
 Int 
 ( 
 versionComponents 
 [ 
 1 
 ]) 
  
 ?? 
  
 0 
  
 let 
  
 patchVersion 
  
 = 
  
 Int 
 ( 
 versionComponents 
 [ 
 2 
 ]) 
  
 ?? 
  
 0 
  
 return 
  
 VersionNumber 
 ( 
  
 majorVersion 
 : 
  
 majorVersion 
 , 
  
 minorVersion 
 : 
  
 minorVersion 
 , 
  
 patchVersion 
 : 
  
 patchVersion 
 ) 
  
 } 
  
 return 
  
 VersionNumber 
 () 
 } 
 static 
  
 func 
  
 adapterVersion 
 () 
  
 - 
>  
 VersionNumber 
  
 { 
  
 let 
  
 versionComponents 
  
 = 
  
 String 
 ( 
 SampleAdSDK 
 . 
 SampleAdSDKVersionNumber 
 ). 
 components 
 ( 
  
 separatedBy 
 : 
  
 "." 
 ) 
  
 var 
  
 version 
  
 = 
  
 VersionNumber 
 () 
  
 if 
  
 versionComponents 
 . 
 count 
  
 == 
  
 4 
  
 { 
  
 version 
 . 
 majorVersion 
  
 = 
  
 Int 
 ( 
 versionComponents 
 [ 
 0 
 ]) 
  
 ?? 
  
 0 
  
 version 
 . 
 minorVersion 
  
 = 
  
 Int 
 ( 
 versionComponents 
 [ 
 1 
 ]) 
  
 ?? 
  
 0 
  
 version 
 . 
 patchVersion 
  
 = 
  
 Int 
 ( 
 versionComponents 
 [ 
 2 
 ]) 
  
 * 
  
 100 
  
 + 
  
 Int 
 ( 
 versionComponents 
 [ 
 3 
 ]) 
  
 } 
  
 return 
  
 version 
 } 
 

Objective-C

  + 
 ( 
 GADVersionNumber 
 ) 
 adSDKVersion 
  
 { 
  
 NSArray 
  
 * 
 versionComponents 
  
 = 
  
 [ 
 SampleSDKVersion 
  
 componentsSeparatedByString 
 : 
 @"." 
 ]; 
  
 GADVersionNumber 
  
 version 
  
 = 
  
 { 
 0 
 }; 
  
 if 
  
 ( 
 versionComponents 
 . 
 count 
  
> = 
  
 3 
 ) 
  
 { 
  
 version 
 . 
 majorVersion 
  
 = 
  
 [ 
 versionComponents 
 [ 
 0 
 ] 
  
 integerValue 
 ]; 
  
 version 
 . 
 minorVersion 
  
 = 
  
 [ 
 versionComponents 
 [ 
 1 
 ] 
  
 integerValue 
 ]; 
  
 version 
 . 
 patchVersion 
  
 = 
  
 [ 
 versionComponents 
 [ 
 2 
 ] 
  
 integerValue 
 ]; 
  
 } 
  
 return 
  
 version 
 ; 
 } 
 + 
 ( 
 GADVersionNumber 
 ) 
 adapterVersion 
  
 { 
  
 NSArray 
  
 * 
 versionComponents 
  
 = 
  
 [ 
 SampleCustomEventAdapterVersion 
  
 componentsSeparatedByString 
 : 
 @"." 
 ]; 
  
 GADVersionNumber 
  
 version 
  
 = 
  
 { 
 0 
 }; 
  
 if 
  
 ( 
 versionComponents 
 . 
 count 
  
 == 
  
 4 
 ) 
  
 { 
  
 version 
 . 
 majorVersion 
  
 = 
  
 [ 
 versionComponents 
 [ 
 0 
 ] 
  
 integerValue 
 ]; 
  
 version 
 . 
 minorVersion 
  
 = 
  
 [ 
 versionComponents 
 [ 
 1 
 ] 
  
 integerValue 
 ]; 
  
 version 
 . 
 patchVersion 
  
 = 
  
 [ 
 versionComponents 
 [ 
 2 
 ] 
  
 integerValue 
 ] 
  
 * 
  
 100 
  
 + 
  
 [ 
 versionComponents 
 [ 
 3 
 ] 
  
 integerValue 
 ]; 
  
 } 
  
 return 
  
 version 
 ; 
 } 
 

Request ad

To request an ad, refer to the instructions specific to the ad format:

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