Aller au contenu principal
Version: 5.x.x

Google Mobile Ads

This guide shows you how to integrate our BlueStack mediation adapter of Google Mobile Ads SDK with your current Android app and set up additional request parameters.

Release notes can be found here

Supported ad formats

  • Banners
  • Interstitials
  • Native Ads
  • Rewarded Video

Requirements

  • Android SDK 4.4 (API level 19) or later
  • Google Play services 21.1.0 or later

Set up Google Ad Manager

The following steps are needed to add us as a Demand partner in Ad Manager. These changes need to be set up in Google Ad Manager.

Add a new Ad Network

First you need to add us as an Ad Network in Google Ad Manager

  1. Under Admin, go to Companies
  2. Click the New Company button and select Ad Network
  3. For the name, you can use BlueStack, but you are free to enter what you want here
  4. For Ad Network, please select Improve Digital
  5. Don't forget to enable the Medation toggle
  6. Other fields can be ignored
  7. Press Save

New ad network

Add Yield Groups

Next we need to add some yield groups. The basic rule is that for each available format you add one yield group (so one for Banner, one for Interstitial, etc.) If you already have Yield Groups set up you can skip this step.

  1. Under Delivery, go to Yield Groups
  2. Click the New Yield Group button
  3. Insert any name you wish to use
  4. Select the correct Ad Format
  5. Inventory type should be set to Mobile App
  6. For Banner, select at least one size that best fits
  7. Please make sure your app's placements are targetted for this Yield Group New yield group

Add A Yield Partner and Define a custom event

Now you have to add us as a Yield partner in the Yield Group you just created, or on a yield group you already have set before.

  1. Open the Yield Group you want to add us as a partner
  2. Scroll down on the page and click the Add yield partner button
  3. As yield partner, choose the company you added in [Add a new Ad Network]
  4. Select integration type Custom Event
  5. Select Platform Android
  6. Select Status Active
  7. Default CPM will be provided by your Azerion representative
  8. For Label, use: GADBlueStackMediationAdapter
  9. For Class Name, use: com.azerion.GADBlueStackMediationAdapter
  10. As parameter, please enter the placement ID provided by your Azerion representative that matches the format you intend to use this yield group for
  11. Repeat for each Yield group / format

Add yield partner

Set up BlueStack Mediation adapter in Application

SDK Integration

Add BlueStack Core SDK:

In the main build.gradle of your project, you must declare the Bluestack repository:

allprojects {
repositories {
google()
mavenCentral()
}
}

In the build.gradle of to your application module, you can now import the Bluestack Google Adapter SDK by declaring it in the dependencies section:

dependencies {
implementation 'com.azerion:bluestack-sdk-core:5.1.4'
implementation 'com.azerion:bluestack-google-adapter:5.1.4.0'
}

Initialize the BlueStack Core SDK

See the Set Up Sdk Section

Bluestack Mediation

See the Mediation Partners

Set up Ad Formats

No additional code is required for integration. may now use MNG DFP Adapter to show Interstitial Ads and Banner Ads the same way it's described in the DFP Documentation.The adapter code and the setup you did on your Google Ad Manager UI will allow MNG Ads to deliver ads.

Native Ads

  1. Assumes that your ad layout is in a file call ad_unit_dfp.xml for exemple in the res/layout folder.

  2. Assumes you have a MAdvertiseNativeContainer in your View layout where the ad is to be placed.

    <com.mngads.views.MAdvertiseNativeContainer
android:id="@+id/native_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

  1. The following code demonstrates how to build an AdLoader that can load native ads:
AdLoader adLoader = new AdLoader.Builder(context, "YOUR PLACEMENT ID") 
.forNativeAd(nativeAd -> {

// This method sets the text, images and the native ad, etc into the ad view.

NativeAdView mAdView = (NativeAdView) getLayoutInflater()
.inflate(R.layout.ad_native, null);
displayNativeAd(nativeAd, mAdView);


})
.withAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(@NotNull LoadAdError errorCode) {

// Handle the failure by logging, altering the UI...

}
})
.withNativeAdOptions(adOptions)
.build();

AdManagerAdRequest.Builder adRequestBuilder = new AdManagerAdRequest.Builder();
adRequestBuilder.addNetworkExtrasBundle(GADBlueStackMediationAdapter.class, getExtrasData());
adLoader.loadAd(adRequestBuilder.build());


  1. Once you have loaded an ad, all that remains is to display it to your users.
private void displayNativeAd(NativeAd nativeAd, NativeAdView nativeAdView) {

/* Display Texts Ad */
// Locate the text view
TextView nativeAdTitle = nativeAdView.findViewById(R.id.nativeAdTitle);
TextView nativeAdContext = nativeAdView.findViewById(R.id.nativeAdContext);
TextView nativeAdCallToAction = nativeAdView.findViewById(R.id.nativeAdCallToAction);

// Set its text
nativeAdTitle.setText(nativeAd.getHeadline());
nativeAdContext.setText(nativeAd.getBody());
nativeAdCallToAction.setText(nativeAd.getCallToAction());

// Register it
nativeAdView.setCallToActionView(nativeAdCallToAction);
nativeAdView.setHeadlineView(nativeAdTitle);
nativeAdView.setBodyView(nativeAdContext);


/* Display Icon Ad */

if(nativeAd.getIcon()!=null)
{
if (nativeAd.getIcon().getUri() != null && !nativeAd.getIcon().getUri().toString().isEmpty()) {
Glide.with(this).load(nativeAd.getIcon().getUri())
.into((ImageView) nativeAdView.findViewById(R.id.nativeAdIcon));
}
else
{
nativeAdView.setIconView(nativeAdView.findViewById(R.id.nativeAdIcon));
}

}
else
{
nativeAdView.setIconView(nativeAdView.findViewById(R.id.nativeAdIcon));
}

/* Display Media Ad */

if(nativeAd.getImages()!=null)
{
if (nativeAd.getImages().size() > 0 && nativeAd.getImages().get(0) != null ) {
Glide.with(this).load(nativeAd.getImages().get(0).getUri())
.into((ImageView) nativeAdView.findViewById(R.id.nativeAdImage));
}
else
{
nativeAdView.setImageView(nativeAdView.findViewById(R.id.mediaContainer));
}
}
else
{
nativeAdView.setImageView(nativeAdView.findViewById(R.id.mediaContainer));
}


// Register the NativeAdObject.
nativeAdView.setStoreView(mMAdvertiseNativeContainer);
nativeAdView.setNativeAd(nativeAd);

// Ensure that the parent view doesn't already contain an ad view and place the AdView into the parent.
frameLayout.removeAllViews();
frameLayout.addView(nativeAdView);
}

Rewarded video Ads

  1. The following code demonstrates how to load a rewarded ad:

AdManagerAdRequest.Builder adRequestBuilder = new AdManagerAdRequest.Builder();
adRequestBuilder.addNetworkExtrasBundle(GADBlueStackMediationAdapter.class, getExtrasData());

RewardedAd.load(context, DFP_REWARDED_AD_UNIT,
adRequestBuilder.build(), new RewardedAdLoadCallback() {

@Override
void onAdLoaded(RewardedAd rewarded) {
rewarded.fullScreenContentCallback = new FullScreenContentCallback(){

@Override
void onAdFailedToShowFullScreenContent(AdError adError) {
// Handle the failure by logging, altering the UI...
}
}
};
@Override
void onAdFailedToLoad(LoadAdError error) {
// Handle the failure by logging, altering the UI...
}
}
);


  1. Once you have loaded an ad, all that remains is to display it to your users.
private void displayRewardedAd(){
mRewardedAd.show(activity, new OnUserEarnedRewardListener(){
@Override
void onUserEarnedReward(RewardItem var1){
...
}
});
}

Custom targeting / Keywords

If you need to send your custom key-value pairs. You can specify key-value-targeting and keywords information in the ad request as follows:

AdManagerAdRequest request = new AdManagerAdRequest.Builder()
.addKeyword("Keyword")
.addCustomTargeting("key1", "value1")
.addCustomTargeting("key2", "value2")
.build();

and you must send your custom key-value pairs also as follows:

1- Create a bundle of the extras :

Bundle extras = new Bundle();
extras.putString("customTargeting","key1=value1;key2=value2");
extras.putString("keywords","key1=value1;key2=value2");

2- Add the extras to the addNetworkExtrasBundle() method as follows:

AdManagerAdRequest adRequest = new AdManagerAdRequest.Builder();
adRequest.addNetworkExtrasBundle(GADBlueStackMediationAdapter.class,extras)
.build();

The GADBlueStackMediationAdapter value corresponds to custom event adapter class name.