Skip to main content

Introduction

This guide explains how to integrate Criteo Direct Bidding for App solution to your Android app with in-house auction logic.

Prerequisites

SDK Initialization

Initialize Criteo SDK in your Application class by using Criteo.Builder() method. This needs to be done only once. Criteo.Builder() method takes 2 parameters:

Parameter

Type

Description

application

Application

Application Object

criteoPublisherId

String

Your Criteo Publisher ID.
Contact your Criteo representative to get your Criteo Publisher ID.

Use adUnits() method on the builder and pass List<AdUnit> object to initialize all ad units that Criteo will monetize.

Banner - Load Criteo Bids

Load Criteo bids using loadBid() method that takes 2 parameters:

Parameter

Type

Description

adUnit

BannerAdUnit

BannerAdUnit object for this request

bidResponseListener

BidResponseListener

A listener object that will be executed when a response is received, or timed out.

On the onResponse() callback, non-null Bid object indicates bid availability from Criteo. Retrieve Criteo's CPM bid price with getPrice() method.

Banner - Displaying Banner

Add CriteoBannerView into your XML layout.

<com.criteo.publisher.CriteoBannerViewandroid:id="@+id/criteoBannerView"android:layout_width="match_parent"android:layout_height="wrap_content" />

When Criteo wins your auction, call loadAd() method and pass the previously obtained Bid object in your code to display Criteo banner.

Banner - Displaying Banner Continued

Alternatively, create a CriteoBannerView object programatically. When Criteo wins your auction, call loadAd() method and pass the previously obtained Bid object, and add it as a subview in your layout.

Banner - Destroying Banner View

Make sure to destroy CriteoBannerView object when your Activity is destroyed.

Banner - Setting Ad Listener

You can optionally add an Ad Listener to your CriteoBannerView object in order to handle callbacks when banner view has loaded, failed to load, or there's a click resulting in the user leaving the application, by calling setCriteoBannerAdListener() with a CriteoBannerAdListener object as parameter, before loading the ad.

Interstitial - Load Criteo Bids

Load Criteo bids using loadBid() method that takes 2 parameters:

Parameter

Type

Description

adUnit

InterstitialAdUnit

InterstitialAdUnit object for this request

bidResponseListener

BidResponseListener

A listener object that will be executed when a response is received, or timed out.

On the onResponse() callback, non-null Bid object indicates bid availability from Criteo. Retrieve Criteo's CPM bid price with getPrice() method.

Interstitial - Loading Interstitial Ads

When Criteo wins your auction, you can request for Interstitial Ad by passing the previously obtained Bid object into loadAd() method of a CriteoInterstitial object. This will prefetch an Interstitial Ad that you can later display in your app.

Interstitial - Displaying Interstitial Ads

Display previously-loaded Interstitial ad by calling show() method. Make sure to always check whether the Interstitial ad has been loaded using isAdLoaded() before presenting Criteo Interstitial ad to the user.

Interstitial - Setting Ad Listener

You can optionally add an Ad Listener to your CriteoInterstitial object in order to handle callbacks when Interstitial view has loaded, failed to load, opened, closed or there's a click resulting in the user leaving the application, by calling setCriteoInterstitialAdListener() with a CriteoInterstitialAdListener object as parameter, before loading the ad.

Advanced Native

Advanced Native enables you to render your native ads using UI components that are native to the platform.

Prerequisites

This guide assumes that you have initialized Criteo SDK according to the In-House Bidding integration guide.

Advanced Native with a Simple Layout - Load Criteo Bids

Load Criteo bids using loadBid() method that takes 2 parameters:

Parameter

Type

Description

adUnit

NativeAdUnit

NativeAdUnit object for this request

bidResponseListener

BidResponseListener

A listener object that will be executed when a response is received, or timed out.

On the onResponse() callback, non-null Bid object indicates bid availability from Criteo. Retrieve Criteo's CPM bid price with getPrice() method.

Advanced Native with a Simple Layout - Native Loader

When Criteo wins your auction, create a CriteoNativeLoader object that will be an entry point and responsible for loading Criteo Native ads.

Parameter

Type

Description

nativeAdListener

CriteoNativeAdListener

See Native Ad Listener section below

nativeRenderer

CriteoNativeRenderer

See Native Renderer section below

Finally, call loadAd() method on the native loader object and pass the previously obtained Bid object to load your native ad.

Advanced Native with a Simple Layout - Native Ad Listener

Create an inner class (in an Activity or Fragment) that implements CriteoNativeAdListener in order to render native ad in the onAdReceived() listener, and optionally handle other native ad events.

In the sample code below, we have MyNativeAdListener class and on onAdReceived() method we are getting a reference to a FrameLayout element in our layout file that acts as a native ads container. Call createNativeRenderedView() from CriteoNativeAd object passed on the listener in order to create a rendered native view inside the container. Finally, add the native view into the container.

Advanced Native with a Simple Layout - Native Layout and Renderer

Define native ad layout in an XML file that contains all native assets you'd like to display. The native layout may look like this:

Advanced Native with a Simple Layout - Native Layout and Renderer Continued

Next, declare a static class that implements CriteoNativeRenderer in order to create a native view from the layout and render the native assets.

There are 2 methods that you need to override. First, you need to inflate your native ad XML layout into the provided ViewGroup in creativeNativeView() method.

Then, in renderNativeView() you will be able to fill the view with native ad elements. Criteo uses CriteoMediaView in order to display images. Please use CriteoMediaView instead of ImageView in your layout file, Criteo SDK provides a helper method setMediaInView() in order to fill the view with media assets.

The following native assets are available via a getter method on CriteoNativeAd object:

Native Asset

Method

Return Value

Recommended View

Ad Title

getTitle()

String

TextView

Ad Description

getDescription()

String

TextView

Ad Price

getPrice()

String

TextView

Ad Image

getProductMedia()

CriteoMedia

CriteoMediaView

Call To Action

getCallToAction()

String

Button

Advertiser Domain

getAdvertiserDomain()

String

TextView

Advertiser Name

getAdvertiserDescription()

String

TextView

Advertiser Logo

getAdvertiserLogoMedia()

CriteoMedia

CriteoMediaView

Legal Text

getLegalText()

String

TextView

Advanced Native with a Simple Layout - Image Loader

Criteo SDK uses Picasso as a default image loader. If, for some reasons, you want to use a different image loader implementation, you can do so by calling the setImageLoader static method.

Example using Glide: