Page tree


To use PubMatic as a client-side demand source, publishers can use third-party mediation support in the DFP SDK to integrate PubMatic iOS SDK for Banner ads. PubMatic provides a client side mediation adapter to integrate the PubMatic SDK with the DFP SDK. Using the guidelines provided below, publishers can easily integrate a PubMatic adapter and DFP SDK into a mobile app with minimal code changes. The following diagram illustrates the call flow of mediation ad serving.

Download the PubMatic Banner Adapter for iOS source code and sample app to use with the steps below.

Mediation Ad Serving Call Flow

  1. DFP SDK, which is integrated into application, requests ad from DFP ad server.
  2. DFP responds back with mediation response containing Custom Event Class names (for example, PMCustomEventBanner) and server parameter containing PubMatic’s ad tag information. We recommend you specify this parameter as <pubId_siteId_adId>.
  3. DFP SDK initializes the PubMatic adapter using the class name when it receives the mediation response, then passes the server parameter.
  4. PubMatic adapter initializes PubMatic SDK with the details received (that is, pubIdsiteId, and adId), from the server parameter.
  5. PubMatic SDK then makes a call to PubMatic ad server requesting an ad.
  6. PubMatic ad server responds with an ad.
  7. PubMatic SDK delegates control to the adapter.
  8. The adapter then hands over rendered ad to DFP SDK and informs the result with standard callbacks.

Configuring the PubMatic Network on DFP Portal

Use the following steps to configure the Custom Event on DFP portal:

  1. Log in to the DFP account.
  2. Navigate to the Delivery > Yield groups tab and create a yield group.
  3. Select the Ad format > Banner and Environment > Mobile app you wish to target with this yield group.
  4. Select inventory Sizes and add Targeting criteria, if any:
  5. Choose Add another yield partner to add PubMatic as a third-party mediation partner. Select Yield partner as PubMatic, if already defined, otherwise, select Create a new yield partner and add PubMatic as a new yield partner.
  6. Select Integration type > Custom event mediation then select Operating system > iOS. You can also enter a Label if needed.
  7. Add the name of your custom event in Class Name (for example, PMCustomEventBanner), then specify PubMatic’s tag in the Parameter field in <pubId_siteId_adId> format. You can also specify Default CPM if needed.
  8. Choose SAVE AND ACTIVATE

Be sure to enter a correct Custom Event Class name and ensure that the parameter is in the exact same format as mentioned above. Any difference between what you enter here and the actual class name in your code could cause the PubMatic adapter to fail initialization.

PubMatic Banner Adapter for DFP SDK

Integrate the DFP SDK (Google-Mobile-Ads-SDK) in your project. This document refers to DFP SDK version 7.28.0.

Monetize your app with ad networks that mediation does not directly support by using DFP Custom Events. Implement a custom event using the GADCustomEventBanner protocol.

Download the PubMatic Banner Adapter for iOS source code and sample app to use with the steps below.
  1. Create a class that implements GADCustomEventBanner in your app; for example, PMCustomEventBanner (here "PM" stands for PubMatic).
  2. Override the -requestBannerAd:parameter:label:request: method and implement code that requests an ad from PubMatic. See the PubMatic SDK Developer Guide, to create an instance of PMBannerAdView view and sending ad requests. Your code may be similar to the following:

    -(void)requestBannerAd:(GADAdSize)adSize parameter:(NSString *)serverParameter label:(NSString *)serverLabel request:(GADCustomEventRequest *)request
    {
        NSArray *params = [serverParameter componentsSeparatedByString:@"_"];
        NSString *pubId = params[0];
        NSString *siteId = params[1];
        NSString *adId = params[2];
    
        if (!(pubId.length && siteId.length && adId.length)) {
            NSDictionary *userInfo = @{NSLocalizedDescriptionKey:NSLocalizedString(@"Invalid pubId/siteId/adId", nil)};
            NSError *error = [NSError errorWithDomain:kGADErrorDomain code:kGADErrorMediationDataError userInfo:userInfo];
            [self.delegate customEventBanner:self didFailAd:error];
            return;
        }
        else
        {
            PMBannerAdRequest *pmBannerAdReq = [[PMBannerAdRequest alloc] initWithPublisherId:pubId siteId:siteId adId:adId];
    
            self.bannerAdView = [[PMBannerAdView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
            self.bannerAdView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
            self.bannerAdView.delegate = self;
            [self.bannerAdView loadRequest:pmBannerAdReq];
        }
    }
  3. Your code must notify DFP when your ad successfully loads by calling the - customEventBanner:didReceiveAd: method on the custom event object’s delegate (accessible via the delegate property), similar to the following:

    -(void)bannerAdViewDidRecieveAd:(PMBannerAdView *)adView
    {
    	NSLog(@"PubMatic Banner Ad received");
    	[self.delegate customEventBanner:self didReceiveAd:adView];
    }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
  4. Your code must also notify the delegate if your ad fails to load by calling the - customEventBanner:didFailAd: method:


    -(void)bannerAdView:(PMBannerAdView *)adView didFailToReceiveAdWithError:(PMError *)error{
        NSLog(@"PubMatic Banner Ad failed");
        NSError *err = [NSError errorWithDomain:kGADErrorDomain code:kGADErrorMediationAdapterError userInfo:error.userInfo];
        [self.delegate customEventBanner:self didFailAd:err];
    }
  5. Optional steps include:

    • Notify the delegate of user interaction events using corresponding delegate methods:

      -customEventBannerWasClicked:

      -customEventBannerWillPresentModal:

      -customEventBannerWillDismissModal:

      -customEventBannerDidDismissModal:

    • Notify the delegate using the - customEventBannerWillLeaveApplication: method if the user leaves the app from a banner ad.

    • Implement the -dealloc method if your custom event requires any sort of cleanup, similar to the sample code below:

      -(void)dealloc{
          [self.bannerAdView reset];
          self.bannerAdView = nil;
      }

Once you've completed these steps, the DFP SDK can automatically instantiate your class when your app runs. You do not need to explicitly instantiate any of these classes in your app's code.

References


⇧ Top