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.
Display Native Ads
Use the following steps to integrate Native ads with your app.
Step 1: Setup Native Ad
Be sure to pass the
Activity context to the new instance of
Step 2: 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.
- Title asset: Title of Native Ad.
- Data assets: Data asset having subtypes like:
Price, and so on.
- Image assets: Image assets having subtypes like:
Use the following example to build a
PMNativeAdRequest with your own selected Native ad asset types:
Step 3: Request Native Ad
loadRequest() from the
Step 4: Callback Events Using Listener
PubMatic SDK provides Native ad updates via
NativeRequestListener callbacks; for example, get assets required to render Native ads using the
The example below assumes the following
Views for rendering respective assets:
ImageViewfor icon image.
ImageViewfor main image.
TextViewfor title text.
TextViewfor call to action text.
TextViewfor description text.
RatingBarto display rating data.
RelativeLayoutfor 'Native Ad'.
PMErrorobject used in the
Step 5: Invoke Impression Tracking—IMPORTANT
You must call the
trackViewForInteractions() method in
PMNativeAd when the Native ad completes rendering. Pass the instance of the
ViewGroup container layout in which Native ads are rendered. Calling This method enables tap gestures on the Native ad container. This is required to trigger click trackers when the user taps or clicks the ad.
Step 6: Deallocating Native Ad Resources
Be sure to deallocate the
PMNativeAd instance before its
Fragment is destroyed: