In-House Mediation

Integration

🚧

Requirements

Min Android SDK version - 16 (4.1, Jelly Bean)

repositories {
    // Add BidMachine maven repository
    maven {
        url 'https://artifactory.bidmachine.io/bidmachine'
    }
}
 
dependencies {
    implementation "io.bidmachine:ads:2.6.0"
}

Set Java version to 8:

android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

🚧

Supported version of Android Gradle Plugin

  • 3.3.3
  • 3.4.3
  • 3.5.4
  • 3.6.4
  • 4.0.1
  • or higher

Device Advertising ID

In mobile apps, there are no cookies. Instead, Ad Manager uses user-resettable identifiers provided by the mobile device's operating system. Typical advertising IDs are AdID (Android) and IDFA (Apple). Mobile advertising IDs allow developers and marketers to track activity for advertising purposes. They're also used to enhance serving and targeting capabilities.

Add Play Services Ads Identifier dependency:

implementation "com.google.android.gms:play-services-ads-identifier:17.0.0"

Network security configuration

Android 9.0 (API 28) blocks cleartext (non-HTTPS) traffic by default, which can prevent ads from being served correctly.

❗️

Failure to comply with this configuration may result in lower display rate, fill rate, rendering errors, and as a result - lower revenue

  1. Add a Network Security Configuration file to your AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest>
    <application android:networkSecurityConfig="@xml/network_security_config" />
</manifest>
  1. In your network_security_config.xml file, add base-config that sets cleartextTrafficPermitted to true:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
        </trust-anchors>
    </base-config>
    <debug-overrides>
        <trust-anchors>
            <certificates src="user" />
        </trust-anchors>
    </debug-overrides>
</network-security-config>

Initialization

Initialize SDK, and set your SourceId.

📘

To get your SOURCE_ID, visit our website or contact the support.

BidMachine.initialize(@NonNull Context, "<YOUR_SOURCE_ID>");

// or with InitializationCallback
BidMachine.initialize(@NonNull Context, "<YOUR_SOURCE_ID>", @Nullable InitializationCallback);
BidMachine.initialize(Context, "<YOUR_SOURCE_ID>")

// or with InitializationCallback
BidMachine.initialize(Context, "<YOUR_SOURCE_ID>", InitializationCallback?)

Enable logs if required:

BidMachine.setLoggingEnabled(boolean);
BidMachine.setLoggingEnabled(Boolean)

Enable test mode:

BidMachine.setTestMode(boolean);
BidMachine.setTestMode(Boolean)

Set your endpoint before initialization if required:

BidMachine.setEndpoint(@NonNull String);
BidMachine.setEndpoint(String)

SDK can automatically track user device location to serve better ads. To make it work for Android 6.0, you should request android.permission.ACCESS_COARSE_LOCATION and android.permission.ACCESS_FINE_LOCATION:

ActivityCompat.requestPermissions(@NonNull Activity, new String[]{
        Manifest.permission.ACCESS_COARSE_LOCATION,
        Manifest.permission.ACCESS_FINE_LOCATION
}, REQ_CODE);
ActivityCompat.requestPermissions(Activity, arrayOf<String>(
    Manifest.permission.ACCESS_COARSE_LOCATION,
    Manifest.permission.ACCESS_FINE_LOCATION
), REQ_CODE)

Request parameters

User Restriction Parameters

ParamTypeDescription
GDPR Consent StringStringGDPR consent string (if applicable), indicating the compliance with the IAB standard Consent String Format of the Transparency and ConsentFramework technical specifications.
Subject to GDPRBooleanFlag indicating if GDPR regulations apply The General Data Protection Regulation (GDPR) is a regulation of the European Union.
CoppaBooleanFlag indicating if COPPA regulations apply. The Children's Online Privacy Protection Act (COPPA) was established by the U.S. Federal Trade Commission.
US Privacy StringStringCCPA string if applicable, compliant with the IAB standard CCPA String Format
GPP StringStringGPP string if applicable, compliant with the IAB standard GPP String Format
GPP IdsList<Integer>GPP ids

Code Example:

// Set COPPA
BidMachine.setCoppa(@Nullable Boolean);

// Set subject to GDPR
BidMachine.setSubjectToGDPR(@Nullable Boolean);

// Set consent config
BidMachine.setConsentConfig(boolean, @Nullable String);

// Set CCPA
BidMachine.setUSPrivacyString(@Nullable String);

// Set GPP
BidMachine.setGPP(@Nullable String, @Nullable List<Integer>);
// Set COPPA
BidMachine.setCoppa(Boolean?)

// Set subject to GDPR
BidMachine.setSubjectToGDPR(Boolean?)

// Set consent config
BidMachine.setConsentConfig(Boolean, String?)

// Set CCPA
BidMachine.setUSPrivacyString(String?)

// Set GPP
BidMachine.setGPP(String?, List<Int>?)

COPPA

To help ensure compliance with COPPA you must indicate whether a user falls within an age-restricted category. To pass COPPA to BidMachine, use:

BidMachine.setCoppa(@Nullable Boolean);
BidMachine.setCoppa(Boolean?)

GDPR

The Publisher needs to send a boolean flag indicating if GDPR applies to the current user.
If so, the Publisher also needs to collect user consent prior to requesting any ads from the Exchange server. More information about collecting consent is here.

SDK has public methods to transfer GDPR data. Also, SDK automatically retrieves GDPR from SharedPreference. If you would like to pass GDPR according to IAB standards, please add it in SharedPreference.

When using several methods of data transfer at once, priority is given to the SDK public method, then TCF 2.0, then TCF 1.0.

Some adapters don't have a public API for the GDPR data to be passed to them. Such adapters will read GDPR from the SharedPreference.

GDPR Applies

SDK public method:

BidMachine.setSubjectToGDPR(@Nullable Boolean);
BidMachine.setSubjectToGDPR(Boolean?)

Example TFC 2.0:

PreferenceManager.getDefaultSharedPreferences(Context)
        .edit()
        .putInt("IABTCF_gdprApplies", <GDPR APPLIES>)
        .apply();
PreferenceManager.getDefaultSharedPreferences(Context)
        .edit {
            putInt("IABTCF_gdprApplies", <GDPR APPLIES>)
        }

Example TFC 1.0:

PreferenceManager.getDefaultSharedPreferences(Context)
        .edit()
        .putString("IABConsent_SubjectToGDPR", "<GDPR APPLIES>")
        .apply();
PreferenceManager.getDefaultSharedPreferences(Context)
        .edit {
            putString("IABConsent_SubjectToGDPR", "<GDPR APPLIES>")
        }

GDPR Consent String

SDK public method

BidMachine.setConsentConfig(boolean, @Nullable String);
BidMachine.setConsentConfig(Boolean, String?)

Example TCF 2.0:

PreferenceManager.getDefaultSharedPreferences(Context)
        .edit()
        .putString("IABTCF_TCString", "<GDPR CONSENT STRING>")
        .apply();
PreferenceManager.getDefaultSharedPreferences(Context)
        .edit {
            putString("IABTCF_TCString", "<GDPR CONSENT STRING>")
        }

Example TCF 1.0:

PreferenceManager.getDefaultSharedPreferences(Context)
        .edit()
        .putString("IABConsent_ConsentString", "<GDPR CONSENT STRING>")
        .apply();
PreferenceManager.getDefaultSharedPreferences(Context)
        .edit {
            putString("IABConsent_ConsentString", "<GDPR CONSENT STRING>")
        }

CCPA

To pass CCPA U.S. Privacy String to BidMachine, use:

BidMachine.setUSPrivacyString(@Nullable String);
BidMachine.setUSPrivacyString(String?)

Also, SDK automatically retrieves CCPA U.S. Privacy String from SharedPreference. If you would like to pass CCPA U.S. Privacy String according to IAB standards, please add it in SharedPreference. More information here and here.

PreferenceManager.getDefaultSharedPreferences(Context)
        .edit()
        .putString("IABUSPrivacy_String", "<IAB CCPA U.S. PRIVACY STRING>")
        .apply();
PreferenceManager.getDefaultSharedPreferences(Context)
        .edit {
            putString("IABUSPrivacy_String", "<IAB CCPA U.S. PRIVACY STRING>")
        }

Some adapters don't have a public API for the CCPA U.S. Privacy String to be passed to them. Such adapters will read this from the SharedPreference.

GPP

📘

API added in version 2.4.0

To pass GPP to BidMachine, use:

BidMachine.setGPP(@Nullable String, @Nullable List<Integer>);
BidMachine.setGPP(String?, List<Int>?)

Also, SDK automatically retrieves GPP from SharedPreference. If you would like to pass GPP according to IAB standards, please add it in SharedPreference. More information here and here

PreferenceManager.getDefaultSharedPreferences(Context)
        .edit()
        .putString("IABGPP_HDR_GppString", "<IAB GPP STRING>")
        .putString("IABGPP_GppSID", "<IAB GPP IDs STRING>")
        .apply();
PreferenceManager.getDefaultSharedPreferences(Context)
        .edit {
            putString("IABGPP_HDR_GppString", "<IAB GPP STRING>")
            putString("IABGPP_GppSID", "<IAB GPP IDs STRING>")
        }

Publisher

To pass information about the publisher, use the public method:

BidMachine.setPublisher(@Nullable Publisher);
BidMachine.setPublisher(Publisher?)
ParamTypeDescription
IdStringPublisher ID
NameStringPublisher name
DomainStringPublisher domain
CategoryStringPublisher content category

Code Example:

Publisher publisher = new Publisher.Builder()
        .setId(@Nullable String)
        .setName(@Nullable String)
        .setDomain(@Nullable String)
        .addCategory(@Nullable String)
        .addCategories(@Nullable List<String>)
        .build();

// Sets publisher information
BidMachine.setPublisher(publisher);
val publisher = Publisher.Builder()
        .setId(String?)
        .setName(String?)
        .setDomain(String?)
        .addCategory(String?)
        .addCategories(List<String>?)
        .build()

// Sets publisher information
BidMachine.setPublisher(publisher)

Targeting Parameters

ParamTypeDescription
User IdStringVendor-specific ID for the user.
GenderEnumGender, one of the following:
Female, Male, Omitted.
Year of BirthIntegerYear of birth as a 4-digit integer (e.g. - 1990).
KeywordsString[]List of keywords, interests, or intents (separated by comma if you use .xml).
Device LocationLocationLocation of the device. It may not be the location sent to the server, as it is compared to the current device location at the time, when it was received.
CountryStringCountry of the user's domicile (i.e. not necessarily their current location).
CityStringCity of the user's domicile (i.e. not necessarily their current location).
ZipStringZip of the user's domicile (i.e. not necessarily their current location).
Store UrlStringApp store URL for an installed app; for IQG 2.1 compliance.
Store CategoryStringSets App store category definitions (e.g. - "games").
Store Sub CategoryString[]Sets App Store Subcategory definitions. The array is always capped at 3 strings.
Framework NameStringSets app framework definitions.
PaidBooleanDetermines, if the app version is free or paid version of the app.
External User IdsList<ExternalUserId>Set external user ID list.
Blocked Advertiser IAB CategoryString[]Block list of content categories by IDs.
Blocked Advertiser DomainString[]Block list of advertisers by their domains (e.g., “example.com”).
Blocked ApplicationString[]Block list of apps where ads are disallowed. These should be bundle or package names (e.g., “com.foo.mygame”) and should NOT be app store IDs (e.g., not iTunes store IDs).

Code Example:

TargetingParams targetingParams = new TargetingParams()
        .setUserId(@Nullable String)
        .setGender(@Nullable Gender)
        .setBirthdayYear(@Nullable Integer)
        .setKeywords(@Nullable String[])
        .setDeviceLocation(@Nullable Location)
        .setCountry(@Nullable String)
        .setCity(@Nullable String)
        .setZip(@Nullable String)
        .setStoreUrl(@Nullable String)
        .setStoreCategory(@Nullable String)
        .setStoreSubCategories(@Nullable String[])
        .setFramework(@Nullable String)
        .setPaid(@Nullable Boolean)
        .setExternalUserIds(@Nullable List<ExternalUserId>)
        .addBlockedAdvertiserIABCategory(@NonNull String)
        .addBlockedAdvertiserDomain(@NonNull String)
        .addBlockedApplication(@NonNull String);
val targetingParams = TargetingParams()
        .setUserId(String?)
        .setGender(Gender?)
        .setBirthdayYear(Int?)
        .setKeywords((vararg String)?)
        .setDeviceLocation(Location?)
        .setCountry(String?)
        .setCity(String?)
        .setZip(String?)
        .setStoreUrl(String?)
        .setStoreCategory(String?)
        .setStoreSubCategories((vararg String)?)
        .setFramework(String?
        .setPaid(Boolean?)
        .setExternalUserIds(List<ExternalUserId>?)
        .addBlockedAdvertiserIABCategory(String)
        .addBlockedAdvertiserDomain(String)
        .addBlockedApplication(String)

TargetingParams can be passed with 2 ways:

  • Through global parameters:
BidMachine.setTargetingParams(targetingParams);
BidMachine.setTargetingParams(targetingParams)
  • Through ad request builder:
adRequestBuilder.setTargetingParams(targetingParams);
adRequestBuilder.setTargetingParams(targetingParams)

You can combine global parameters with regular. If you set Global TargetingParams using UserId, and then make a request using TargetingParams with Gender set, both requests will be merged and the resulting TargetingParams will include both UserId and Gender.

📘

Priority is given to the AdRequest parameters.

Price Floor Parameters

ParameterTypeDescription
IdStringUnique floor identifier.
PricedoubleFloor price

If you use the method with only Price provided PriceFloorParams.addPriceFloor(Double), the Id will be generated using UUID.randomUUID().

Code Example:

PriceFloorParams priceFloorParams = new PriceFloorParams()
        // Set Bid Price, in this case id will be generated
        .addPriceFloor(double)
        // Set Bid Id and Price
        .addPriceFloor(@NonNull String, double);
val priceFloorParams = PriceFloorParams()
        // Set Bid Price, in this case id will be generated
        .addPriceFloor(Double)
        // Set Bid Id and Price
        .addPriceFloor(String, Double)

To set up price floor parameters for ad request use setPriceFloorParams method from AdRequest builder according to ads type.

adRequestBuilder.setPriceFloorParams(priceFloorParams);
adRequestBuilder.setPriceFloorParams(priceFloorParams)

Session Ad Parameters

ParamTypeDescription
Session DurationIntegerThe total duration of time a user has spent so far in a specific app session expressed in seconds.
Impression CountIntegerThe count of impressions for a specific placement type in a given app session.
Click RateFloatThe percentage of clicks/impressions per user per placement type over a given number of impressions.
Is User Clicked On Last AdBooleanA boolean value indicating if the user clicked on the last impression in a given session per placement type.
Completion RateFloatThe percentage of successful completions/impressions per user per placement type for a given number of impressions.
This only applies to Rewarded and Video placement types.

Code Example:

SessionAdParams sessionAdParams = new SessionAdParams()
        .setSessionDuration(@Nullable Integer)
        .setImpressionCount(@Nullable Integer)
        .setClickRate(@Nullable Float)
        .setIsUserClickedOnLastAd(@Nullable Boolean)
        .setCompletionRate(@Nullable Float);
val sessionAdParams = SessionAdParams()
        .setSessionDuration(Integer?)
        .setImpressionCount(Integer?)
        .setClickRate(Float?)
        .setIsUserClickedOnLastAd(Boolean?)
        .setCompletionRate(Float?)

To set up session ad parameters for ad request use setSessionAdParams method from AdRequest builder according to ads type.

adRequestBuilder.setSessionAdParams(sessionAdParams);
adRequestBuilder.setSessionAdParams(sessionAdParams)

Custom Parameters

📘

API added in version 1.9.1

Code Example:

CustomParams customParams = new CustomParams()
        .addParam(@NonNull String, @NonNull String)
        .addParams(@NonNull Map<String, String>);
val customParams = CustomParams()
        .addParam(String, String)
        .addParams(Map<String, String>)

To set up custom parameters for ad request use setCustomParams method from AdRequest builder according to ads type.

adRequestBuilder.setCustomParams(customParams);
adRequestBuilder.setCustomParams(customParams)

Placement Id

📘

API added in version 1.7.4

To set up placement id for current impression use setPlacementId method from AdRequest builder according to ads type.

adRequestBuilder.setPlacementId(@Nullable String);
adRequestBuilder.setPlacementId(String?)

Bid Payload

📘

API added in version 1.7.2

To set up bid payload for ad request use setBidPayload method from AdRequest builder according to ads type.

adRequestBuilder.setBidPayload(@Nullable String);
adRequestBuilder.setBidPayload(String?)

Example

Auction result

ParameterTypeDescriptionSample
IdStringWinner bid ID provided in the request."cc5bd14b-aaef-4037-b4f8-879913366e3c"
Demand SourceStringWinner advertising source name."BidMachine Test"
PricedoubleWinner price expressed as CPM.0.023
DealStringId of Price Floor."d6f61bf9-11a8-4172-a77d-4b1ff85a727f"
Creative IdStringWinner creative id."123.13579"
CIDStringWinner Campaign ID or other similar grouping of brand-related ads."123.13587"
Ad DomainString[]Winner advertiser domain (top two levels only e.g., "ford.com").["sample1.com", "sample2.com"]
Network KeyStringWinner network key. This network will be loaded."mraid"
Network ParamsMap<String, String>Client parameters of winner networks.
Creative FormatEnumCreativeFormat, one of the following:
Banner, Video, Native.
CreativeFormat.Video
Custom ParamsMap<String, String>Map that contains additional information about the response.

You can get AuctionResult in two ways:

  • Through AdRequestListener. Use AuctionResult from onRequestSuccess callback
adRequestBuilder.setListener(new <AdRequestObject>.AdRequestListener() {
    @Override
    public void onRequestSuccess(@NonNull <AdRequestObject> adRequest,
                                 @NonNull AuctionResult auctionResult) {
        // Use AuctionResult from onRequestSuccess callback
    }
});
adRequestBuilder.setListener(object : <AdRequestObject>.AdRequestListener {
    override fun onRequestSuccess(adRequest: <AdRequestObject>,
                                  auctionResult: AuctionResult) {
        // Use AuctionResult from onRequestSuccess callback
    }
});
  • Through getter. Each AdRequest has an option to retrieve auction result information after it has been loaded.
adRequest.getAuctionResult();
adRequest.auctionResult;

Win/Loss notifications

📘

API added in version 1.7.7

Call notifyMediationWin/notifyMediationLoss on the AdRequest instance when BidMachine wins/loses the mediation among networks.

  • Win notification:
adRequest.notifyMediationWin();
adRequest.notifyMediationWin()
  • Loss notification:
adRequest.notifyMediationLoss("<WINNER_NETWORK_NAME>", <WINNER_NETWORK_PRICE>);
// or
adRequest.notifyMediationLoss();
adRequest.notifyMediationLoss("<WINNER_NETWORK_NAME>", <WINNER_NETWORK_PRICE>)
// or
adRequest.notifyMediationLoss()

Bid Token

📘

API added in version 1.9.0

With S2S integration, you will need a BidToken that you need to transfer in the request. To get a BidToken, you can use one of 2 methods:

// Must be run on background thread
String bidToken = BidMachine.getBidToken(@NonNull Context);
// Must be run on background thread
val bidToken = BidMachine.getBidToken(Context)

or

BidMachine.getBidToken(@NonNull Context, new BidTokenCallback() {
    @Override
    public void onCollected(@NonNull String bidToken) {
        // The BidToken will be returned on a background thread
    }
});
BidMachine.getBidToken(Context) { bidToken ->
    // The BidToken will be returned on a background thread
}

❗️

Attention

Starting from version 2.2.0 it is recommended to add AdsFormat to the getBidToken method

// Must be run on background thread
String bidToken = BidMachine.getBidToken(@NonNull Context, @Nullable AdsFormat);
// Must be run on background thread
val bidToken = BidMachine.getBidToken(Context, AdsFormat?)

or

BidMachine.getBidToken(@NonNull Context, @Nullable AdsFormat, new BidTokenCallback() {
    @Override
    public void onCollected(@NonNull String bidToken) {
        // The BidToken will be returned on a background thread
    }
});
BidMachine.getBidToken(Context, AdsFormat?) { bidToken ->
    // The BidToken will be returned on a background thread
}

3rd party SDK integration (Header-Bidding)

You can find all integration code examples written in Java and Kotlin here

🚧

All 3rd party networks should be configured and registered before SDK initialization


AdColony

📘

Supported ad types

  • Interstitial
  • Rewarded

Add this to Module-level build.gradle before dependencies:

repositories {
    google()
    mavenCentral() 
}

Add the following dependency to you build.gradle:

dependencies {
    implementation "io.bidmachine:ads.networks.adcolony:2.6.0.11"
}

Configure network:

BidMachine.registerNetworks(
        new AdColonyConfig("YOUR_APP_ID")
                .withMediationConfig(AdsFormat.InterstitialVideo, "YOUR_ZONE_ID")
                .withMediationConfig(AdsFormat.RewardedVideo, "YOUR_ZONE_ID"));
BidMachine.registerNetworks(
    AdColonyConfig("YOUR_APP_ID")
        .withMediationConfig(AdsFormat.InterstitialVideo, "YOUR_ZONE_ID")
        .withMediationConfig(AdsFormat.RewardedVideo, "YOUR_ZONE_ID"))

📘

By default, we provide google as storeId parameter to AdColony network


Amazon

📘

Supported ad types

  • Banner
  • Interstitial
  • Rewarded

🚧

Minimum supported Android version is API Level 19

Add this to Module-level build.gradle before dependencies:

repositories {
    mavenCentral()
}

Add next dependency to you build.gradle:

dependencies {
    implementation "io.bidmachine:ads.networks.amazon:2.6.0.13"
}

Configure network:

BidMachine.registerNetworks(
        new AmazonConfig("YOUR_APP_KEY")
               .withMediationConfig(AdsFormat.Banner_320x50, "YOUR_SLOT_UUID")
               .withMediationConfig(AdsFormat.Banner_300x250, "YOUR_SLOT_UUID")
               .withMediationConfig(AdsFormat.Banner_728x90, "YOUR_SLOT_UUID")
               .withMediationConfig(AdsFormat.InterstitialStatic, "YOUR_SLOT_UUID")
               .withMediationConfig(AdsFormat.InterstitialVideo, "YOUR_SLOT_UUID"));
BidMachine.registerNetworks(
    AmazonConfig("YOUR_APP_KEY")
        .withMediationConfig(AdsFormat.Banner_320x50, "YOUR_SLOT_UUID")
        .withMediationConfig(AdsFormat.Banner_300x250, "YOUR_SLOT_UUID")
        .withMediationConfig(AdsFormat.Banner_728x90, "YOUR_SLOT_UUID")
        .withMediationConfig(AdsFormat.InterstitialStatic, "YOUR_SLOT_UUID")
        .withMediationConfig(AdsFormat.InterstitialVideo, "YOUR_SLOT_UUID"))

🚧

IAB TCFv2

Amazon support only IAB TCFv2.
IAB TCFv1 is not supported, see


Criteo

📘

Supported ad types

  • Banner
  • Interstitial

Add this to Module-level build.gradle before dependencies:

repositories {
    google()
    mavenCentral()
}

Add the following dependency to you build.gradle:

dependencies {
    implementation "io.bidmachine:ads.networks.criteo:2.6.0.12"
}

Configure network:

BidMachine.registerNetworks(
        new CriteoConfig("YOUR_PUBLISHER_ID")
        		.withMediationConfig(AdsFormat.Banner_320x50, "YOUR_AD_UNIT_ID")
                .withMediationConfig(AdsFormat.Banner_300x250, "YOUR_AD_UNIT_ID")
                .withMediationConfig(AdsFormat.Banner_728x90, "YOUR_AD_UNIT_ID")
                .withMediationConfig(AdsFormat.InterstitialStatic, "YOUR_AD_UNIT_ID")
                .withMediationConfig(AdsFormat.InterstitialStatic, "YOUR_AD_UNIT_ID", Orientation.Portrait)
                .withMediationConfig(AdsFormat.InterstitialStatic, "YOUR_AD_UNIT_ID", Orientation.Landscape));
BidMachine.registerNetworks(
    CriteoConfig("YOUR_PUBLISHER_ID")
        .withMediationConfig(AdsFormat.Banner_320x50, "YOUR_AD_UNIT_ID")
        .withMediationConfig(AdsFormat.Banner_300x250, "YOUR_AD_UNIT_ID")
        .withMediationConfig(AdsFormat.Banner_728x90, "YOUR_AD_UNIT_ID")
        .withMediationConfig(AdsFormat.InterstitialStatic, "YOUR_AD_UNIT_ID")
        .withMediationConfig(AdsFormat.InterstitialStatic, "YOUR_AD_UNIT_ID", Orientation.Portrait)
        .withMediationConfig(AdsFormat.InterstitialStatic, "YOUR_AD_UNIT_ID", Orientation.Landscape))

If orientation has been specified for an AdUnit, then that AdUnit will only be used for that particular orientation.

If there is no AdUnit for the current orientation, an AdUnit without specific orientation will be taken.

For example:

BidMachine.registerNetworks(
        new CriteoConfig("YOUR_PUBLISHER_ID")
                .withMediationConfig(AdsFormat.InterstitialStatic, "AD_UNIT_ID_1")
                .withMediationConfig(AdsFormat.InterstitialStatic, "AD_UNIT_ID_2", Orientation.Landscape));
BidMachine.registerNetworks(
    CriteoConfig("YOUR_PUBLISHER_ID")
        .withMediationConfig(AdsFormat.InterstitialStatic, "AD_UNIT_ID_1")
        .withMediationConfig(AdsFormat.InterstitialStatic, "AD_UNIT_ID_2", Orientation.Landscape))

With this configuration:

AD_UNIT_ID_2 will be used, when in landscape orientation
AD_UNIT_ID_1 will be used, when in portrait orientation

Such AdUnits should be indicated at the end, as shown in the examples above.


Google AdManager

📘

Supported ad types

  • Banner
  • Interstitial
  • Rewarded

Add this to Project-level build.gradle before dependencies:

buildscript {
    repositories {
        google()
        mavenCentral()
    }
}

Add this to Module-level build.gradle before dependencies:

repositories {
    google()
    mavenCentral()
}

Add the following dependency to you build.gradle:

dependencies {
    implementation "com.google.android.gms:play-services-ads:20.6.0"
}

Add APPLICATION_ID to AndroidManifest.xml:

<manifest>
    <application>
        <!-- Sample Ad Manager app ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    </application>
</manifest>

📘

If ANRs are observed when loading ad, then you can specify a special flag in AndroidManifest.xml that will move the loading of ad to the background thread.

<manifest>
    <application>
        <meta-data
            android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
            android:value="true"/>
    </application>
</manifest>

Optimize initialization and ad loading


MetaAudience

📘

Supported ad types

  • Banner
  • Interstitial
  • Rewarded
  • Native (Experimental)

Add this to Module-level build.gradle before dependencies:

repositories {
    mavenCentral() 
}

Add the following dependency to you build.gradle:

dependencies {
    implementation "io.bidmachine:ads.networks.meta_audience:2.6.0.15"
}

Update your network_security_config.xml file, add domain-config that sets cleartextTrafficPermitted to true:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">127.0.0.1</domain>
    </domain-config>
</network-security-config>

Configure network:

BidMachine.registerNetworks(
        new MetaAudienceConfig("YOUR_APP_ID")
                .withMediationConfig(AdsFormat.Banner, "YOUR_PLACEMENT_ID")
                .withMediationConfig(AdsFormat.Banner_300x250, "YOUR_PLACEMENT_ID")
                .withMediationConfig(AdsFormat.InterstitialStatic, "YOUR_PLACEMENT_ID")
                .withMediationConfig(AdsFormat.RewardedVideo, "YOUR_PLACEMENT_ID")
                .withMediationConfig(AdsFormat.Native, "YOUR_PLACEMENT_ID"));
BidMachine.registerNetworks(
    MetaAudienceConfig("YOUR_APP_ID")
        .withMediationConfig(AdsFormat.Banner, "YOUR_PLACEMENT_ID")
        .withMediationConfig(AdsFormat.Banner_300x250, "YOUR_PLACEMENT_ID")
        .withMediationConfig(AdsFormat.InterstitialStatic, "YOUR_PLACEMENT_ID")
        .withMediationConfig(AdsFormat.RewardedVideo, "YOUR_PLACEMENT_ID")
        .withMediationConfig(AdsFormat.Native, "YOUR_PLACEMENT_ID"))

🚧

Native (Experimental)

MetaAudience native have two type:

  • Native Banner Ads
  • Native Ads

Native ads may not work correctly if MetaAudience placements were submitted that did not match the selected MediaAssetType. For example, if you want use MediaAssetType.Icon, you need submit placements of Native Banner Ads type, otherwise you need submit placements of Native Ads type.


Mintegral

📘

Supported ad types

  • Banner
  • Interstitial
  • Rewarded

Add the following dependency to you build.gradle:

dependencies {
    implementation "io.bidmachine:ads.networks.mintegral:2.6.0.7"
}

Configure network:

BidMachine.registerNetworks(
        new MintegralConfig("YOUR_APP_ID", "YOUR_APP_KEY")
                .withMediationConfig(AdsFormat.Banner, "YOUR_AD_UNIT_ID")
                .withMediationConfig(AdsFormat.Interstitial, "YOUR_AD_UNIT_ID")
                .withMediationConfig(AdsFormat.Rewarded, "YOUR_AD_UNIT_ID"));
BidMachine.registerNetworks(
    MintegralConfig("YOUR_APP_ID", "YOUR_APP_KEY")
        .withMediationConfig(AdsFormat.Banner, "YOUR_AD_UNIT_ID")
        .withMediationConfig(AdsFormat.Interstitial, "YOUR_AD_UNIT_ID")
        .withMediationConfig(AdsFormat.Rewarded, "YOUR_AD_UNIT_ID"))

myTarget

📘

Supported ad types

  • Banner
  • Interstitial
  • Rewarded

Add the following dependency to you build.gradle:

dependencies {
    implementation "io.bidmachine:ads.networks.my_target:2.6.0.15"
}

Configure network:

BidMachine.registerNetworks(
        new MyTargetConfig()
               .withMediationConfig(AdsFormat.Banner, "YOUR_SLOT_ID")
               .withMediationConfig(AdsFormat.Banner_320x50, "YOUR_SLOT_ID")
               .withMediationConfig(AdsFormat.Banner_300x250, "YOUR_SLOT_ID")
               .withMediationConfig(AdsFormat.Banner_728x90, "YOUR_SLOT_ID")
               .withMediationConfig(AdsFormat.InterstitialStatic, "YOUR_SLOT_ID")
               .withMediationConfig(AdsFormat.RewardedVideo, "YOUR_SLOT_ID"));
BidMachine.registerNetworks(
    MyTargetConfig()
        .withMediationConfig(AdsFormat.Banner, "YOUR_SLOT_ID")
        .withMediationConfig(AdsFormat.Banner_320x50, "YOUR_SLOT_ID")
        .withMediationConfig(AdsFormat.Banner_300x250, "YOUR_SLOT_ID")
        .withMediationConfig(AdsFormat.Banner_728x90, "YOUR_SLOT_ID")
        .withMediationConfig(AdsFormat.InterstitialStatic, "YOUR_SLOT_ID")
        .withMediationConfig(AdsFormat.RewardedVideo, "YOUR_SLOT_ID"))

Pangle

📘

Supported ad types

  • Banner
  • Interstitial
  • Rewarded

Add the following dependency to you build.gradle:

dependencies {
    implementation "io.bidmachine:ads.networks.pangle:2.6.0.7"
}

Configure network:

BidMachine.registerNetworks(
        new PangleConfig("YOUR_APP_ID")
                .withMediationConfig(AdsFormat.Banner, "YOUR_SLOT_ID")
                .withMediationConfig(AdsFormat.Interstitial, "YOUR_SLOT_ID")
                .withMediationConfig(AdsFormat.Rewarded, "YOUR_SLOT_ID"));
BidMachine.registerNetworks(
    PangleConfig("YOUR_APP_ID")
        .withMediationConfig(AdsFormat.Banner, "YOUR_SLOT_ID")
        .withMediationConfig(AdsFormat.Interstitial, "YOUR_SLOT_ID")
        .withMediationConfig(AdsFormat.Rewarded, "YOUR_SLOT_ID"))

Tapjoy

📘

Supported ad types

  • Interstitial
  • Rewarded

Add the following dependency to you build.gradle:

dependencies {
    implementation "io.bidmachine:ads.networks.tapjoy:2.6.0.10"
}

Configure network:

BidMachine.registerNetworks(
        new TapjoyConfig("YOUR_SDK_KEY")
               .withMediationConfig(AdsFormat.InterstitialVideo, "YOUR_PLACEMENT_NAME")
               .withMediationConfig(AdsFormat.RewardedVideo, "YOUR_PLACEMENT_NAME"));
BidMachine.registerNetworks(
    TapjoyConfig("YOUR_SDK_KEY")
        .withMediationConfig(AdsFormat.InterstitialVideo, "YOUR_PLACEMENT_NAME")
        .withMediationConfig(AdsFormat.RewardedVideo, "YOUR_PLACEMENT_NAME"))

Vungle

📘

Supported ad types

  • Banner
  • Interstitial
  • Rewarded

Add this to Module-level build.gradle before dependencies:

repositories {
    google()
    mavenCentral()
}

Add the following dependency to you build.gradle:

dependencies {
    implementation "io.bidmachine:ads.networks.vungle:2.6.0.5"
}

Configure network:

BidMachine.registerNetworks(
        new VungleConfig("YOUR_APP_ID", "YOUR_PUBLISHER_ID")
                .withMediationConfig(AdsFormat.InterstitialVideo, "YOUR_PLACEMENT_ID")
                .withMediationConfig(AdsFormat.RewardedVideo, "YOUR_PLACEMENT_ID"));
BidMachine.registerNetworks(
    VungleConfig("YOUR_APP_ID", "YOUR_PUBLISHER_ID")
        .withMediationConfig(AdsFormat.InterstitialVideo, "YOUR_PLACEMENT_ID")
        .withMediationConfig(AdsFormat.RewardedVideo, "YOUR_PLACEMENT_ID"));