Amazon mediation adapter

589 views
Skip to first unread message

Markus Wiederkehr

unread,
Feb 10, 2014, 6:03:39 PM2/10/14
to google-adm...@googlegroups.com
I am trying to implement a CustomEventBanner adapter for Amazon banner ads.

Everything is pretty straightforward except for one thing. Sometimes they open what I think is a PopupWindow instead of an Activity when the user clicks on an ad. The problem is that the user might still be interacting with this popup when the mediation layer decides it is time to refresh the ad. So the adapter's requestBannerAd() gets called again while the popup is still visible.

They have some recommendations for this, see here: https://developer.amazon.com/public/apis/earn/mobile-ads/docs/with-other-sdks (bottom of page, Mediator SDK Integration).

Their first recommendation is to use a boolean variable to remember if a popup is currently shown. I have two problems with that. First it would have to be a static variable since a new CustomEventBanner seems to be created on every ad refresh. But what should happen if the device orientation changes? How could the adapter detect that? And second, assuming the boolean variable does what it is supposed to do, what should the adapter do if the popup is indeed visible? Call listener.onFailedToReceiveAd()? Does not work, the mediation layer would look for the next ad network. listener.onReceivedAd(View)? Does not seem to work either, popup gets destroyed. Do nothing at all? Does not seem to be appropriate either.

TLDR: Has anyone successfully implemented a CustomEventBanner for Amazon that adheres to Amazon's recommendations and is willing to share the code or ideas?

Eric Leichtenschlag

unread,
Feb 12, 2014, 12:27:31 PM2/12/14
to google-adm...@googlegroups.com
Hi Markus,

Try invoking bannerListener.onPresentScreen() when the ad is clicked and it opens up this popup window. I'll have to investigate further as to exactly what the mediation refresh logic is, but that call tells AdMob that the adapter is presenting something on top of the app, and I'm hoping AdMob respects that call and doesn't refresh from underneath you.

Btw you are right about a new instance of your CustomEventBanner class being instantiated on every call.

Thanks,
Eric

Markus Wiederkehr

unread,
Feb 13, 2014, 7:14:28 PM2/13/14
to google-adm...@googlegroups.com
Hi Eric,

My code already does that but I forgot to mention it. So that does not do the trick. See my code below.

Thanks,
Markus

---8<---8<---8<---8<---8<---8<---

public class AmazonBanner implements CustomEventBanner {
    private AdLayout mAdLayout;

    @Override
    public void requestBannerAd(final CustomEventBannerListener listener, Activity activity,
            String label, String serverParameter, AdSize adSize, MediationAdRequest mediationRequest,
            Object customEventExtra) {
        AdRegistration.setAppKey("01234567890123456789012345678901");

        if (BuildConfig.DEBUG) {
            AdRegistration.enableTesting(true);
            AdRegistration.enableLogging(true);
        }

        mAdLayout = new AdLayout(activity);
        mAdLayout.setLayoutParams(new LayoutParams(adSize.getWidthInPixels(activity), adSize
                .getHeightInPixels(activity)));

        mAdLayout.setListener(new AdListener() {
            public void onAdLoaded(AdLayout view, AdProperties adProperties) {
                listener.onReceivedAd(view);
            }
            public void onAdFailedToLoad(AdLayout view, AdError error) {
                listener.onFailedToReceiveAd();
            }
            public void onAdExpanded(AdLayout view) {
                listener.onPresentScreen();
            }
            public void onAdCollapsed(AdLayout view) {
                listener.onDismissScreen();
            }
        });

        mAdLayout.loadAd(new AdTargetingOptions());
    }

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

--->8--->8--->8--->8--->8--->8---

Eric Leichtenschlag

unread,
Feb 13, 2014, 9:57:16 PM2/13/14
to google-adm...@googlegroups.com
Darn, this case wasn't considered then. The only workaround I can think of would be maintaining that variable yourself, disabling refreshing on the AdMob console, and doing refreshing yourself and taking this into account. But that's a lot of extra overhead and is something the SDK should handle.

Does Amazon have a test app key that you can use to test this behavior? I'd like to be able to reproduce this locally.

Thanks,
Eric

Markus Wiederkehr

unread,
Feb 14, 2014, 2:03:32 AM2/14/14
to google-adm...@googlegroups.com
As far as I know they don't have a public test key. You have to register an app. And the package name and the key provided by the app have to match the registered key, otherwise no ads are served.

Then you have to call enableTesting like I did. They serve three or four different test ads - it is the Kindle Fire ad that causes the troubles.

Best regards,
Markus

Eric Leichtenschlag

unread,
Feb 14, 2014, 1:11:49 PM2/14/14
to google-adm...@googlegroups.com
Pardon the stupid questions but:

1. Where do you specify the package name? I couldn't see this field when creating a new app. Is that just the App SKU field? If so, can I specifiy just a package name or does it have to be some kind of url?
2. Can I get these test ads on a non-kindle device (e.g. Nexus 5)?

Thanks,
Eric
amazon.png

Markus Wiederkehr

unread,
Feb 14, 2014, 1:18:31 PM2/14/14
to google-adm...@googlegroups.com
1. IIRC you have to upload an apk at some point and they extract the package name from the manifest,
2. Yes, I am testing on a Nexus 4 myself (320x50 banner ads).

Regards,
Markus

Eric Leichtenschlag

unread,
Feb 14, 2014, 1:32:20 PM2/14/14
to google-adm...@googlegroups.com
Ok, I've uploaded an apk of a test app. We'll see if they actually let me test out ads. In the meantime, I have a bug filed to consider this case as we rethink our mediation APIs.

Thanks,
Eric

Markus Wiederkehr

unread,
Feb 14, 2014, 1:35:41 PM2/14/14
to google-adm...@googlegroups.com
Okay, actually you don't have to upload the APK,

See https://developer.amazon.com/public/apis/earn/mobile-ads/docs/quick-start (Obtaining An Application Key)

I kind of deducted the package name thingy from the note on that page that says you cannot use the same application key in another app. They probably send the package name along with the ad request and lock the application key to that package name on first request. But that is only guessing on my part.

Thanks,
Markus

Eric Leichtenschlag

unread,
Feb 14, 2014, 1:48:28 PM2/14/14
to google-adm...@googlegroups.com

Dave Isbitski, Developer Evangelist at Amazon

unread,
Feb 19, 2014, 1:05:40 PM2/19/14
to google-adm...@googlegroups.com
Eric are you still having issues?  You are correct the DISABLED_APP error message is returned by AdFailedToLoad as an INTERNAL_ERROR.  This is often due to the developer account registration process not being fully completed yet.  

I just did two recent posts on our developer blog that may help answer some questions:
Hope that helps!

Thanks,
Dave

David Isbitski Developer Evangelist, Amazon Apps and Games @thedavedev developer.amazon.com/blog

Eric Leichtenschlag

unread,
Feb 19, 2014, 1:54:55 PM2/19/14
to google-adm...@googlegroups.com
Hi Dave,

Thanks for reaching out. I'm still getting the DISABLED_APP error code. I don't see a notification that my developer account has been approved or is even still under review, so I'm not sure how to proceed. Is there some action I need to take to start the review process? My app key is 2a44d55b7d3d4680899ee88e94779843.

The post on using amazon mobile ads API with other ad networks works great if you're implementing the mediation layer yourself. But AdMob implements the mediation layer for you, and it sounds like we're triggering a refresh on one of the amazon test ads because it opened up a PopupWindow instead of an Activity. I'd like to reproduce this case to find out more information about what's going on, and so that AdMob can test that this case is accounted for in future releases. I just need to be able to get some test ads back.

Thanks,
Eric

Dave Isbitski

unread,
Feb 19, 2014, 4:22:21 PM2/19/14
to google-adm...@googlegroups.com
Got it, that makes sense.  I just sent you an email about how we can work together to reproduce and create the best experience.
Reply all
Reply to author
Forward
0 new messages