Integrating Native Ads

Document created by david.simerly on Oct 20, 2017Last modified by david.simerly on May 9, 2018
Version 18Show Document
  • View in full screen mode

PubMatic SDKs 

PubMatic iOS SDK 

Getting Started

Integrating Banner Ads

Integrating Interstitial Ads

Rich Media (MRAID 2.0) Support

➤  Integrating Native Ads

Header Bidding With DFP

Passing Targeting Information

SDK Debugging

PubMatic iOS API Reference 

Native advertising is a form of online advertising in which the ad is rendered with the same look and feel as the page or application in which it displays. Native ads are not render-ready ads, meaning you must render the assets obtained in the response to make them match the look and feel of the target page/template.


You'll need to follow the instructions in Getting Started before proceeding with the following integration steps. You'll also find a useful example integration in SampleApp included in the SDK download bundle.



Display Native Ads

Use the following steps to integrate Native ads with your app:


Step 1: Import PubMatic Native ad header file

#import "PMNativeAd.h"


The import statements may differ for different integration methods


Step 2: Setup Native ad

A. Create instance of PMNativeAd.

B. Set PMNativeAd's delegate property to your PMNativeAdDelegate object in your view controller:


self.nativeAd =[PMNativeAd new] ;
self.nativeAd.delegate = self;


Step 3: Create Native ad request

Native ads consist of separate assets, so you have the option to choose the required asset types for the request based on your requirements.


A. Title asset: Title of Native ad.

B. Data assets: Data asset having subtypes like: Description, Rating, CTA, Phone, Price, and so on.

C. Image assets: Image assets having subtypes like: Logo, Icon, or Main image.


Use the following example to build a PMNativeAdRequest with your own selected Native ad asset types:


 // Creating Native ad request
PMNativeAdRequest * adRequest = [[PMNativeAdRequest alloc] initWithPublisherId:@"<#PUB_ID#>"

// Instantiate Asset to be requested in Native ad request along with attributes
// Requesting for Title asset in application
PMNativeTitleAssetRequest *titleAsset = [[PMNativeTitleAssetRequest alloc] initWithId:1
[adRequest addAsset:titleAsset];

// Requesting for Icon image Asset of respective attributes
PMNativeImageAssetRequest *imageAsset = [[PMNativeImageAssetRequest alloc] initWithId:2
                                                                                width:50 height:50];
[adRequest addAsset:imageAsset];

// Requesting for Cover image Asset of respective attributes
imageAsset = [[PMNativeImageAssetRequest alloc] initWithId:3
                                                     width:329 height:100];
[adRequest addAsset:imageAsset];

// Requesting for Data asset of type CTA Text in application
PMNativeDataAssetRequest *dataAsset = [[PMNativeDataAssetRequest alloc] initWithId:4
[adRequest addAsset:dataAsset];

// Requesting for Data asset of type description in application
dataAsset = [[PMNativeDataAssetRequest alloc] initWithId:5
[adRequest addAsset:dataAsset];

// Requesting for Data asset of type star rating in application
dataAsset = [[PMNativeDataAssetRequest alloc] initWithId:6
[adRequest addAsset:dataAsset];


Step 4: Request Native ad

Send the adRequest using loadRequest: from the nativeAd instance:


[self.nativeAd loadRequest:adRequest];


Step 5: Receiving delegate callbacks & parsing responses

PubMatic SDK provides Native ad updates via PMNativeAdDelegate callbacks; for example, get assets required to render Native ads using the nativeAdDidRecieveAd: callback.


The example below assumes the following outlets for rendering respective assets:


  • titleLabel—A UILabel for title text.
  • iconImageView—A UIImageView for icon image.
  • mainImageView—A UIImageView for main image.
  • ctaLabel—A UILabel for call to action text.
  • descriptionLabel—A UILabel for descrioption text.
  • ratingView & starRatingViewContainer—custom views for displaying rating data.
  • nativeAdView—A container UIView for 'Native Ad'.


- (void)nativeAdDidRecieveAd:(PMNativeAd *)nativeAd
    for (PMNativeAssetResponse *asset in nativeAd.adAssetResponseArray)
        @try {
            switch (asset.assetId) {
                case 1:
                    PMNativeTitleAssetResponse *titleAsset = (PMNativeTitleAssetResponse *) asset;
                    self.titleLabel.text = titleAsset.text;                   
                case 2:
                    PMNativeImageAssetResponse *imageAsset = (PMNativeImageAssetResponse *) asset;
                    [nativeAd loadInImageView:self.iconImageView withURL:[imageAsset.imageURL description]];
                case 3:
                    PMNativeImageAssetResponse *imageAsset = (PMNativeImageAssetResponse *) asset;
                    [nativeAd loadInImageView:self.mainImageView withURL:[imageAsset.imageURL description]];
                case 4:
                    PMNativeDataAssetResponse *dataAsset = (PMNativeDataAssetResponse *) asset;
                    [self.ctaLabel setText:dataAsset.value];

                case 5:
                    PMNativeDataAssetResponse *dataAsset = (PMNativeDataAssetResponse *) asset;
                    self.descriptionLabel.text = dataAsset.value;                   

                case 6:
                    PMNativeDataAssetResponse *dataAsset = (PMNativeDataAssetResponse *) asset;
                        self.ratingView.rate=[dataAsset.value floatValue];
                        self.starRatingViewContainer.hidden = NO;



                    NSLog(@"Unexpected Asset found for Asset Id : %ld",(long)asset.assetId);
        @catch (NSException *exception) {

            NSLog(@"Unexpected Asset found for Asset Id : %ld",(long)asset.assetId);
        @finally {

   typeof (self) weakSelf = self;

    /* Important: You must call this method when response rendering completes.
       This method sets tap gestures on the ad container; required to trigger
       click trackers when the user taps/clicks the ad.

   [nativeAd trackViewForInteractions:self.nativeAdView withViewController:weakSelf];


- (void)nativeAd:(PMNativeAd*)nativeAd didFailToReceiveAdWithError:(PMError*)error{

- (void)nativeAdDidClick:(PMNativeAd *)nativeAd{      


See PubMatic SDK Error Codes for a detailed description of the PMError object used in the nativeAd:didFailToReceiveAdWithError: callback.


Step 6: Tracking—IMPORTANT

You must call the trackViewForInteractions:withViewController: method in PMNativeAdwhen the Native ad completes rendering. This method enables tap gestures on the Native ad container; that is, the parent view of your ad asset views. This is required to trigger click trackers when the user taps or clicks the ad.