The medium layout ad is a mediation of standard units that can be configured from the PubNative dashboard. The medium layout ad view contains a predefined set of components such as, icon, banner, title, description, CTA and disclosure view. You can choose the specific ad type from the PubNative dashboard (i.e. banner only, description-banner-icon or title-icon-description etc.).

The predefined size for the medium layout ad view is 300 x 250.

153

Medium Layout Example

Getting Started

  • Before integrating medium ad layouts in to your app, you’ll need to go through the steps in our Getting Started Guide, create an account on the PubNative Dashboard, and integrate the SDK into your project.
  • Add a medium layout ad unit to your app in the PubNative Dashboard
  • Make sure you have added the ad network SDKs you wish to use to your app

Integration

1. Create Layout

You can create a predefined medium layout ad request using PNMediumLayout

PNMediumLayout layout = new PNMediumLayout();

2. Integrate Lifecycle Callbacks

You can track the load process, user interaction and ad behavior with callbacks using setLoadListener(<YOUR_LISTENER>) method. You need to set listener as

layout.setLoadListener(new PNMediumLayout.LoadListener() {

    @Override
    public void onPNLayoutLoadFinish(PNLayout layout) {
       // layout returned

    }

    @Override
    public void onPNLayoutLoadFail(PNLayout layout, Exception exception) {
       // ad request failed
    }
});

3. Load Ad

To load a medium layout advertisement

layout.load(<CONTEXT>, "<YOUR_APP_TOKEN_HERE>", "<YOUR_PLACEMENT_NAME_HERE>");

Once an ad is loaded, You will get a fully created view that can be placed in any ViewGroup.

4. Use the ad

Once the load callback is over, this layout returns as a result an initialised view that can be used inside your own ad container. Impressions and clicks are tracked directly from the SDK, but you need to call startTracking method so the layout starts listening for clicks and checking the ad in the screen. You can extract the view using getView(Context) method.

Any interaction with this methods without a previously loaded layout will do nothing.

PNMediumLayoutView layoutView = layout.getView(<CONTEXT>);
// Inject the view into your viewContainer
layout.startTrackingView();

It is highly recommended that if you have a scrolling view and you want to stop tracking the ad view (which is recommended when the ad disappears from the screen), you can use the stopTrackingView() method

layout.stopTrackingView();