To use PubMatic as a client-side demand source, publishers can use third-party mediation support in MoPub SDK to integrate PubMatic iOS SDK for Banner, Interstitial ads. PubMatic provides a client-side mediation adapter to integrate PubMatic SDK with MoPub SDK. Publishers can easily integrate PubMatic adapter and MoPub SDK into mobile applications with minimal code changes.
This document provides guidelines for writing PubMatic adapters for MoPub.
The following diagram illustrates the call flow of mediation ad serving.
Mediation Ad Serving Call Flow
- MoPub SDK integrated with the application, requests an ad from the MoPub ad server.
- MoPub ad server responds back with mediation response containing Custom Event Class name (refer to section below) and server extra parameters containing PubMatic’s pubId, siteId & adId.
- When the mediation response is received, MoPub SDK initializes PubMatic adapter using class name, and passes all server extra parameters.
- PubMatic adapter initializes PubMatic SDK with server extra parameters.
- PubMatic SDK then makes call to PubMatic ad server requesting ad.
- PubMatic ad server responds with the ad.
- PubMatic SDK delegates control to the adapter.
- Adapter then hands over rendered ad to MoPub SDK & informs the result with standard callbacks.
Configuring the PubMatic Network on MoPub Portal
Use the following steps to configure a Custom Event on the MoPub portal:
- Log in to your MoPub account.
- Navigate to the Networks tab and click Add a Network.
- On the Add a network pop-up, click Custom Native Network. (Please note that Native network does not have any relation with Native ad format.)
Give a suitable name to PubMatic custom network.
In the Set Up Your Inventory section, add the custom event class and data only for the native ad unit for which you want to enable PubMatic network.
In the custom event class field add the class name for the respective subclass of the MoPub CustomEvent class.
Use the steps below to add the Custom Event Class Data field in JSON containing PubMatic placement details:
For all ad formats: Enter pubId, siteId & adId provided by your PubMatic account manager, in the following format.
Please enter the Custom Event Class name and data exactly in the same format mentioned above. Any changes in these may cause failure in initializing PubMatic adapter.
- Save the network. Please note that it may take from 15 to 30 minutes for MoPub ad server to reflect this change.
PubMatic Banner adapter for MoPub SDK
Integrate MoPub SDK in your project. This document is refers to MoPub SDK version 4.11.1
- Create a subclass of
MPBannerCustomEventin your application; for example,
PMBannerCustomEvent(here PM stands for PubMatic)
-requestAdWithSize:customEventInfo:method and implement code that requests an Ad. Please refer to the PubMatic SDK Guide to create instance of
PMBannerAdViewview and sending an Ad request. Please refer to the following code:
When your ad loads successfully, you must notify MoPub of the event by calling the
- bannerCustomEvent:didLoadAd:method on the custom event object’s delegate (accessible via the delegate property). See the following code:
Similarly, you must notify the delegate when your ad fails to load by calling
(Optional) Notify the delegate of user interaction events via the corresponding delegate methods:
If your implementation calls
-bannerCustomEventWillBeginAction:, it must also call
Once you've completed these steps, the MoPub SDK will be able to automatically instantiate your MPBannerCustomEvent subclass when your application is running. You do not need to instantiate any of these subclasses in your application code.(Optional) Notify the delegate if the user leaves the application from a banner via the - bannerCustomEventWillLeaveApplication: method.
(Optional) Implement the
-deallocmethod if your custom event requires any sort of cleanup. See sample code below.
Finally, on the MoPub web interface, create a network with the "Custom Native Network" type. Place the class name of your custom event (for example,
PMBannerCustomEvent) in the “Custom Event Class" column.
Once you've completed these steps, the MoPub SDK will be able to automatically instantiate your
MPBannerCustomEvent subclass when your application is running. You do not need to instantiate any of these subclasses in your application code.
PubMatic Interstitial Adapter for MoPub SDK
Integrate MoPub SDK in your project. This document is created referring to MoPub SDK version 4.11.1
- Create a subclass of MPInterstitialCustomEvent in your application; for example,
-requestInterstitialWithCustomEventInfo:method and implement code that requests an interstitial. Please refer PubMatic SDK Guide to create instance of
PMInterstitialAdViewand sending Ad request. See code below.
-showInterstitialFromRootViewController:and implement code that displays PubMatic interstitial Ad. See code below.
You must notify MoPub of all of the following interstitial lifecycle events, by calling the corresponding methods on the custom event object’s delegate (accessible via the delegate property), See code below:
All of the methods above are required. If the ad network you are trying to use does not provide callbacks for one/more of these events, you should still call the custom event method at an appropriate time.
For example, if an ad network only provides an
adDidDisappearcallback, your custom event should fire both
- (Optional) If the ad network is capable of notifying you when a user interacts or taps on an ad, you should forward this information to the MoPub SDK so that MoPub can provide accurate analytics. You can do so by calling the
interstitialCustomEventDidReceiveTapEvent:method on the custom event delegate.
(Optional) Implement the -dealloc method if your custom event requires any sort of cleanup. Please refer code below.
On the MoPub web interface, create a network with the "Custom Native Network" type. Place the class name of your custom event (for example,
YourInterstitialCustomEvent), in the "Custom Class" column.
Once you've completed these steps, the MoPub SDK will be able to automatically instantiate your MPInterstitialCustomEvent subclass when your application is running. You do not need to instantiate any of these subclasses in your application code.
MPInterstitialCustomEventobject on every ad call, so you can safely make changes to the custom event object's internal state without affecting subsequent ad calls.