Admob Mediation Amazon Ads

1,424 views
Skip to first unread message

tabletopco...@gmail.com

unread,
Dec 17, 2016, 10:39:11 AM12/17/16
to Google Mobile Ads SDK Developers
Hey all,

I have spent days trying to figure this out. I would like to have Amazon Mobile Ads mediated through Admob, but Amazon is not currently supported. As such, I created a Custom Event, a CustomEventBanner and CustomEventBannerListener. I've gone through the Admob tutorial as well as the Amazon page about mediation. For some reason it just doesn't seem to be working correctly. I can see through the Admob Mediation report that requests are being made, but I have 0 impressions (which I imagine means I did something wrong). Any chance someone can help me with the implementation. I'm sure the information would be valuable to others attempting to do the same. 

Here is what I have so far:
public class AmazonBannerAd implements CustomEventBanner {
private static final String AMAZON_APPKEY = "1af21e56f2f64e12b1288283723db030";
private AdLayout mAdLayout;

private AdLayout getAdLayout(Context context) {
if (mAdLayout == null) {
mAdLayout = new AdLayout(context, com.amazon.device.ads.AdSize.SIZE_AUTO);

FrameLayout.LayoutParams mLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
mAdLayout.setLayoutParams(mLayoutParams);
}
return mAdLayout;
}

@Override
public void requestBannerAd(Context context,
final CustomEventBannerListener customEventBannerListener,
String s,
AdSize adSize,
MediationAdRequest mediationAdRequest,
Bundle bundle) {
// Sets up Amazon App Key
AdRegistration.setAppKey(AMAZON_APPKEY);

// Amazon Mobile Ads Code
AdRegistration.enableLogging(true);
AdRegistration.enableTesting(false);

// Initialize Amazon AdView
mAdLayout = new AdLayout(context);

final AdLayout adLayout = getAdLayout(context);

mAdLayout.setListener(new AmazonBannerAdListener(customEventBannerListener, adLayout));

AdTargetingOptions options = new AdTargetingOptions();
options.enableGeoLocation(true);

mAdLayout.loadAd(options);
}

@Override
public void onDestroy() {
if (mAdLayout != null) {
mAdLayout.destroy();
mAdLayout = null;
}
}

@Override
public void onPause() {
}

@Override
public void onResume() {
}
}

And the Listener:

public class AmazonBannerAdListener implements AdListener {
private CustomEventBannerListener customEventBannerListener;
private AdLayout mAdLayout;

public AmazonBannerAdListener(CustomEventBannerListener listener, AdLayout adLayout) {
this.customEventBannerListener = listener;
this.mAdLayout = adLayout;
}

@Override
public void onAdLoaded(Ad ad, AdProperties adProperties) {
customEventBannerListener.onAdLoaded(mAdLayout);
}

@Override
public void onAdFailedToLoad(Ad ad, AdError adError) {
switch (adError.getCode()) {
case NETWORK_ERROR:
customEventBannerListener.onAdFailedToLoad(AdRequest.ERROR_CODE_NETWORK_ERROR);
break;
case NETWORK_TIMEOUT:
customEventBannerListener.onAdFailedToLoad(AdRequest.ERROR_CODE_NETWORK_ERROR);
break;
case NO_FILL:
customEventBannerListener.onAdFailedToLoad(AdRequest.ERROR_CODE_NO_FILL);
break;
case INTERNAL_ERROR:
customEventBannerListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INTERNAL_ERROR);
break;
case REQUEST_ERROR:
customEventBannerListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INVALID_REQUEST);
break;
default:
customEventBannerListener.onAdFailedToLoad(AdRequest.ERROR_CODE_INTERNAL_ERROR);
break;
}
}

@Override
public void onAdExpanded(Ad ad) {
customEventBannerListener.onAdClicked();
}

@Override
public void onAdCollapsed(Ad ad) {
customEventBannerListener.onAdClosed();
}

@Override
public void onAdDismissed(Ad ad) {
customEventBannerListener.onAdClosed();
}
}

Thank you!

Chris Feldman (Mobile Ads SDK Team)

unread,
Dec 19, 2016, 10:57:13 AM12/19/16
to Google Mobile Ads SDK Developers
Hi,

Despite the fact that you're not registering any impressions, are you able to load and view ads in your app? This will help determine if your problem is implementation related.

I'm also wondering if you might be using ProGuard. ProGuard is known to sometimes strip out the custom event class. If that is the case, you can use this tool to reverse engineer your APK and ensure that your custom event class is present. Another thing I noticed is that nowhere in your code do I see you set your ad unit ID. You need to make sure you're doing that. 

Please send me your ad unit ID so I can do some more investigation. In the meantime, I suggest taking a look at our mediation example on GitHub.

Regards,
Chris Feldman
Mobile Ads SDK Team

tabletopco...@gmail.com

unread,
Dec 19, 2016, 11:42:13 AM12/19/16
to Google Mobile Ads SDK Developers
Thanks for getting back to me. The way I currently have the app set up is to load Admob ads on one activity to test out mediation and the other activities use Amazon Ads. I am able to load Admob ads on the activity in question (both test ads on my testing device and live ads on devices from other users). The other activities are able to load the Amazon Ads without problem. It seems to me that the mediation is requesting an Amazon Ad, something goes wrong, and then the Admob ad is displayed. 

I am using ProGuard with the two classes mentioned in the tutorials excluded. I don't know anything about ProGuard, so it is possible that it may be part of the problem. 

As for sending the Ad Unit Id, is there a good way to send that or is it okay to just post it here? I didn't want to post it if having it available to the public would be a problem. 

Thank you for your patience and assistance. 

Chris Feldman (Mobile Ads SDK Team)

unread,
Dec 19, 2016, 12:54:17 PM12/19/16
to Google Mobile Ads SDK Developers
Hi,

I suggest sending your ad unit ID in a private message. If you'd like, you can also send a zip of your app that I can debug directly.

Regards,
Chris Feldman
Mobile Ads SDK Team

Chris Feldman (Mobile Ads SDK Team)

unread,
Dec 19, 2016, 2:47:16 PM12/19/16
to Google Mobile Ads SDK Developers
Hi,

I received your ad unit ID and your files offline, thank you for sending everything. It looks like you're not making all of the correct callbacks on your custom banner. You need the following callbacks:

MethodWhen to call
onAdLoaded()The banner request succeeded.
onAdFailedToLoad()The banner request failed.
onAdClicked()The banner was clicked.
onAdOpened()The banner is rendering a full-screen view.
onAdClosed()The user returns to the app after clicking on a banner.
onAdLeftApplication()The banner caused the user to leave the app.

For more information and to see an example, the implementation is detailed in our guide. Currently, your implementation includes onAdLoaded, onAdFailedToLoad, onAdExpanded, onAdCollapsed, and onAdDismissed. You need to make sure all of the AdMob callbacks are included, and that they're named properly.

There is also a problem with the way you're instantiating your custom banner in NewGameActivity.

        // Initialize AdMob AdView

        AdView admobAdView = (AdView) findViewById(R.id.newgameactivity_adview_admob);


        // Unsure if this is needed

        AmazonBannerAd amazonBannerAd = new AmazonBannerAd();


        // Sets up AdMob Banner Ad - Should be holding mediated ads - status unknown

        AdRequest.Builder builder = new AdRequest.Builder();

        builder.addTestDevice(getString(R.string.admob_testdeviceid));

        builder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);

        if (mPrefs.getBoolean(PROFILE_CREATED, false)) {

            String gender = mPrefs.getString(GENDER, null);

            if (gender != null && gender.matches("male")) {

                builder.setGender(AdRequest.GENDER_MALE);

            } else if (gender != null && gender.matches("female")) {

                builder.setGender(AdRequest.GENDER_FEMALE);

            }

            String birthday = mPrefs.getString(BIRTHDAY, null);

            if (birthday != null) {

                DateFormat df = new SimpleDateFormat("MM/dd/yyyy", Locale.US);

                try {

                    Date date = df.parse(birthday);

                    builder.setBirthday(date);

                } catch (Exception e) {

                    e.printStackTrace();

                }

            }

        }

        AdRequest adRequest = builder.build();

        admobAdView.loadAd(adRequest);


You initialize your AmazonBannerAd object:

        // Unsure if this is needed

        AmazonBannerAd amazonBannerAd = new AmazonBannerAd();


But then you never use it, instead you create an ad request and load it into admobAdView, which will never return an ad from Amazon. You need to load your request in the custom AmazonBannerAd view that you created.

Regards,
Chris Feldman
Mobile Ads SDK Team

Benjamin Becker

unread,
Dec 19, 2016, 3:30:03 PM12/19/16
to google-adm...@googlegroups.com
I think that is where I am getting lost. The interface I am implementing in the AmazonBannerAdListener is the Amazon AdListener interface. Is that correct? From there, I have to use each of the methods you listed above within the overridden methods from Amazon's AdListener?

As for the AmazonBannerAd object, how do I add that into the Admob Adview? Just do "admobAdview.loadAd(amazonBannerAd)"? Would that not just load amazon ads instead of admob's mediated ads?

I apologize. I'm very new to programming and self-taught so some of this is over my head. Thank you for your patience.

--

---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/lSSE5HP7gKo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Feldman (Mobile Ads SDK Team)

unread,
Dec 19, 2016, 5:13:46 PM12/19/16
to Google Mobile Ads SDK Developers
Hi,

The interface I am implementing in the AmazonBannerAdListener is the Amazon AdListener interface. Is that correct? From there, I have to use each of the methods you listed above within the overridden methods from Amazon's AdListener?

This is exactly right. You need to make sure each of those callbacks is called within the overridden methods from the Amazon AdListener. If I was unclear in my last message, you're missing the callbacks for onAdOpened and onAdLeftApplication. 

It would also be helpful if you could ensure that your mediation settings allow for only Custom Event ads to serve. You can do this by setting your eCPM value for Admob to 0.1. That will make it much easier to debug. Since Admob is not currently returning any Custom Events, it's impossible to test whether the connection to the Amazon SDK has been done correctly.

Regards,
Chris Feldman
Mobile Ads SDK Team

On Monday, December 19, 2016 at 3:30:03 PM UTC-5, Benjamin Becker wrote:
I think that is where I am getting lost. The interface I am implementing in the AmazonBannerAdListener is the Amazon AdListener interface. Is that correct? From there, I have to use each of the methods you listed above within the overridden methods from Amazon's AdListener?

As for the AmazonBannerAd object, how do I add that into the Admob Adview? Just do "admobAdview.loadAd(amazonBannerAd)"? Would that not just load amazon ads instead of admob's mediated ads?

I apologize. I'm very new to programming and self-taught so some of this is over my head. Thank you for your patience.

Benjamin Becker

unread,
Dec 19, 2016, 5:34:54 PM12/19/16
to google-adm...@googlegroups.com
Okay, I think I have the Listener set up. Code attached.

As for the Admob settings, I have it set for Amazon eCPM higher than Admob (after taking off optimization). This is the setting I had when I first had it set up just to make sure they were working and I was still getting 0 impressions.

I'm lost as far as what to do with AmazonBannerAd object after it is initialized. Do I call the requestBannerAd method? Or something else?

Thanks for hanging in there with me.

To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.

To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Feldman (Mobile Ads SDK Team)

unread,
Dec 20, 2016, 10:47:44 AM12/20/16
to Google Mobile Ads SDK Developers
Hi Benjamin,

No problem! Thank you for your interest in our SDK. I'll hang in here until we get this working.

For your AmazonBannerAd object, I may have mislead you in my earlier message. You do want to use an AdView like you were doing originally. You can see this in action in our mediation example:

        // Sample custom event banner.
        AdView mCustomEventAdView = (AdView) findViewById(R.id.customevent_adview);
        mCustomEventAdView.loadAd(new AdRequest.Builder().build());

The customevent_adview is created with an ad unit ID that is registered with the name of the the CustomEvent class (for this sample it's com.google.ads.mediation.sample.customevent.SampleCustomEvent). You can view the code for that class in the sample here. It may be a bit confusing because the sample uses that classes for a bunch of different ad types. The SDK populates the AdView based on your custom class instead of the normal AdMob implementation.

I've created a sample app for you that fetches Amazon ads through AdMob mediation. I will send you the sample privately because it includes your ad unit ID and class names. Let me know if you have any questions about the implementation!

Regards,
Chris Feldman
Mobile Ads SDK Team

On Monday, December 19, 2016 at 5:34:54 PM UTC-5, Benjamin Becker wrote:
Okay, I think I have the Listener set up. Code attached.

As for the Admob settings, I have it set for Amazon eCPM higher than Admob (after taking off optimization). This is the setting I had when I first had it set up just to make sure they were working and I was still getting 0 impressions.

I'm lost as far as what to do with AmazonBannerAd object after it is initialized. Do I call the requestBannerAd method? Or something else?

Thanks for hanging in there with me.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andre Arsenault

unread,
Sep 14, 2020, 7:15:11 AM9/14/20
to Google Mobile Ads SDK Developers
Hello! I know it's almost 4 years later but I have very similar questions. Namely:

- Once I have created the instance of the Amazon banner ad (now: com.amazon.device.ads.AdLayout), does it need to be added to the view as a child of the AdMob banner view or should it be added to the main view independently? The samples are rather vague on this important step.

- Would it be possible to get a copy of the sample app sent to the original poster? (Ad ids removed of course).

Thank you for any guidance you can provide.


On Tuesday, 20 December 2016 at 16:47:44 UTC+1 Chris Feldman (Mobile Ads SDK Team) wrote:
Hi Benjamin,

No problem! Thank you for your interest in our SDK. I'll hang in here until we get this working.

For your AmazonBannerAd object, I may have mislead you in my earlier message. You do want to use an AdView like you were doing originally. You can see this in action in our mediation example:

        // Sample custom event banner.
        AdView mCustomEventAdView = (AdView) findViewById(R.id.customevent_adview);
        mCustomEventAdView.loadAd(new AdRequest.Builder().build());

The customevent_adview is created with an ad unit ID that is registered with the name of the the CustomEvent class (for this sample it's com.google.ads.mediation.sample.customevent.SampleCustomEvent). You can view the code for that class in the sample here. It may be a bit confusing because the sample uses that classes for a bunch of different ad types. The SDK populates the AdView based on your custom class instead of the normal AdMob implementation.

I've created a sample app for you that fetches Amazon ads through AdMob mediation. I will send you the sample privately because it includes your ad unit ID and class names. Let me know if you have any questions about the implementation!

Regards,
Chris Feldman
Mobile Ads SDK Team

On Monday, December 19, 2016 at 5:34:54 PM UTC-5, Benjamin Becker wrote:
Okay, I think I have the Listener set up. Code attached.

As for the Admob settings, I have it set for Amazon eCPM higher than Admob (after taking off optimization). This is the setting I had when I first had it set up just to make sure they were working and I was still getting 0 impressions.

I'm lost as far as what to do with AmazonBannerAd object after it is initialized. Do I call the requestBannerAd method? Or something else?

Thanks for hanging in there with me.
To post to this group, send email to google-adm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--

---
You received this message because you are subscribed to a topic in the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-admob-ads-sdk/lSSE5HP7gKo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-adm...@googlegroups.com.

Mobile Ads SDK Forum Advisor Prod

unread,
Sep 14, 2020, 9:11:02 AM9/14/20
to an...@talisman.games, google-adm...@googlegroups.com
Hi Andre,

Thank you for bringing this question to our attention. As you have state this is a 4 year old post that you have pointed to and many things have changed since then. At this time we do not have the code that was used for the original post so are unable to share that with you.

What I would suggest are the following.
  • Make sure you are updated with the current SDK version.
  • While we do not support Amazon Meditation I would suggest that you check Amazons documents .
  • Also look at our mediation section to get a better idea of how you can do this.
Regards,
Google Logo
William Pescherine
Mobile Ads SDK Team
 

 

ref:_00D1U1174p._5004Q24b5nK:ref

Andre Arsenault

unread,
Sep 14, 2020, 9:33:39 AM9/14/20
to Google Mobile Ads SDK Developers
Hi William,

Yes I'm on the latest AdMob and Amazon SDKs and have gone through the documentation and sample code.

The Amazon document you linked provides sample code that circumvents AdMob mediation (tries to load from Amazon and if there is no fill then it request an ad from AdMob). I would prefer to use AdMob as my primary and mediate Amazon through Custom Events, as detailed in this original thread.

I have been using your mediation documentation to guide my efforts thus far and it has been very helpful. However there is no guidance on how the new banner view from the Custom Event should be hooked up to the app's view hierarchy.

- Does the Custom Event's banner view need to be added to the view as a child of the AdMob banner view or should it be added to the main view independently?
- Does the AdMob SDK automatically hide the AdMob banner if the Custom Event loads and invokes CustomEventBannerListener.onAdLoaded()?

I'm rather confused about the interaction of views when using Custom Events in general, and the documentation and sample code does not clarify this point.

Thanks.

Mobile Ads SDK Forum Advisor Prod

unread,
Sep 14, 2020, 12:20:32 PM9/14/20
to an...@talisman.games, google-adm...@googlegroups.com
Hi Andre,

Thank you for the response back and letting me know the additional thoughts. I have been looking over the previous staements regarding the original case.Based on that and having looked over the CustomEvent documentation here is what I can suggest at this moment.
  • I believe that you should be able to directly add to the adView and do not need to add it as a child, It would appear to be connecting right to the main adView.
  • It would appear that you need to make sure that all the Amazon SDK callbacks are being invoked or otherwise this could cause an issue. 
  • Again it would appear to invoke the CustomEventBannerListener.onAdLoaded() and if it returns NO_FILL then would default to the AdMob servers. Still if no ad served, then it should hide the bannerView
Reply all
Reply to author
Forward
0 new messages