question

yasirkula avatar image
yasirkula asked

Amazon Ads Unity Plugin Test Ads Fail To Load

Hello there,

I'm planning to upgrade one of my games. It already has Amazon Ads implemented and working (I have received two payments so far). Problem is that that version of the game was created two years ago and the mobile ads sdk has changed drastically since then (I am not even sure if there was an official plugin back then).

Now, when I try to create a floating banner ad or interstitial ad, AdFailedToLoadListener event is called for both of the ads (and thus, ads are not shown). Test mode is enabled, so my geo position should not be a problem. My test device is Galaxy S3. I have also tried showing ads on another S3 located in US by means of a remote test lab but ads failed to load there, too. Here is a fraction of my implementation:

mobileAds = AmazonMobileAdsImpl.Instance;
ApplicationKey key = new ApplicationKey();
key.StringValue = "REMOVED FOR SECURITY PURPOSES";
mobileAds.SetApplicationKey( key );

/*mobileAds.AddAdCollapsedListener( EventHandler );
mobileAds.AddAdDismissedListener( EventHandler );
mobileAds.AddAdLoadedListener( EventHandler );
mobileAds.AddAdExpandedListener( EventHandler );
mobileAds.AddAdFailedToLoadListener( EventHandlerFail );
mobileAds.AddAdResizedListener( EventHandlerResize );*/

ShouldEnable enable = new ShouldEnable();
enable.BooleanValue = true;
mobileAds.EnableTesting( enable );
mobileAds.EnableLogging( enable );

// Configure placement for the ad
Placement placement = new Placement();
placement.Dock = Dock.TOP;
placement.HorizontalAlign = HorizontalAlign.CENTER;
placement.AdFit = AdFit.FIT_AD_SIZE;

// This method returns an Ad object, which you must save and keep track of
current.banner = current.mobileAds.CreateFloatingBannerAd( placement );
mobileAds.CreateInterstitialAd();
mobileAds.LoadInterstitialAd();
current.mobileAds.LoadAndShowFloatingBannerAd( current.banner );

What would you recommend me to do in order to solve the issue?

Thank you very much,

Suleyman Yasir Kula

mobile adslogin with amazonsdkunity
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Levon@Amazon avatar image
Levon@Amazon answered

Hi there,

Thanks for posting! I have verified that Amazon Mobile Ads work correctly. I can't see your script's lifecycle events, but I have implemented my sample below in such a way that I setup and create the ad in Awake() and then load it in Start(), like so:

using UnityEngine;
using System.Collections;
using com.amazon.mas.cpt.ads;

public class AmazonAd : MonoBehaviour {
    Ad bannerAd;
    // Use this for initialization
    void Awake () {
        // Obtain object used to interact with the plugin
        IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
        // Use Android app key for Android apps and iOS
        // app key for iOS apps
        string appKey;
#if UNITY_ANDROID
        appKey = "Android_app_key";
#elif UNITY_IPHONE
   appKey = "iOS_app_key";
#endif
        // Construct object passed to sync operation as input
        ApplicationKey key = new ApplicationKey();
        // Set input value
        key.StringValue = appKey;
        // Call method, passing in required input structure
        // This method does not return a response
        mobileAds.SetApplicationKey(key);
        EnableTesting(false); // true for test mode; otherwise false
        EnableGeoLocation();
        CreateBannerAd();
    }

    void Start() {
        LoadAndShowBannerAd();
    }

    public void HideAd() {
        // Obtain object used to interact with the plugin
        IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
        mobileAds.CloseFloatingBannerAd(bannerAd);
    }

    void EnableTesting(bool isTestMode) {
        // Obtain object used to interact with the plugin
        IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
        // Construct object passed to sync operation as input
        ShouldEnable enable = new ShouldEnable();
        // Set input value
        enable.BooleanValue = isTestMode;
        // Call method, passing in required input structure
        // This method does not return a response
        mobileAds.EnableTesting(enable);
    }

    void EnableGeoLocation() {
        // Obtain object used to interact with the plugin
        IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
        // Construct object passed to sync operation as input
        ShouldEnable enable = new ShouldEnable();
        // Set input value
        enable.BooleanValue = true;
        // Call method, passing in required input structure
        // This method does not return a response
        mobileAds.EnableGeoLocation(enable);
    }

    void CreateBannerAd() {
        // Obtain object used to interact with the plugin
        IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
        // Construct object passed to sync operation as input
        Placement placement = new Placement();
        // Set input value
        placement.Dock = Dock.BOTTOM;
        placement.HorizontalAlign = HorizontalAlign.CENTER;
        placement.AdFit = AdFit.FIT_AD_SIZE;
        // Call method, passing in required input structure
        // This method returns an Ad object, which you must save and keep track of
        bannerAd = mobileAds.CreateFloatingBannerAd(placement);
        // Get return values
        string adType = bannerAd.AdType.ToString();
        long identifier = bannerAd.Identifier;
    }

    void LoadAndShowBannerAd() {
        // Obtain object used to interact with the plugin
        IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
        // savedAdObject is an Ad object that you received back when you called CreateFloatingBannerAd
        // Call method, passing in savedAdObject
        // This method returns a LoadingStarted object
        LoadingStarted response = mobileAds.LoadAndShowFloatingBannerAd(bannerAd);
        // Get return value
        bool loadingStarted = response.BooleanValue;
    }

}
3 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hello again,

Thank you for the detailed answer, I really appreciate that. After waiting for some time, I had already implemented another ad network; but I will try the code you provided anyways to see the results.

Best,

Suleyman Yasir Kula

0 Likes 0 ·

I've tried your code with different ShouldEnable combinations for EnableTesting and EnableGeoLocation functions. In addition, I've tested in both Portrait and Landscape modes. And lastly, I've tested it with an unsigned APK as well as a signed APK. Honestly, neither combination worked for me. My internet connection was open all the time (my GPS was not enabled, though).

I've then created an empty Unity project with only the Amazon Ads plugin imported and tested it with no luck, again. I'm sharing the project so that you can test it on your device, too:

http://www.filedropper.com/amazonadstest

Best regards,

Suleyman Yasir Kula

0 Likes 0 ·

Could you share the logcat from your app whilst running it? There may be another issue causing issues not related to the actual app code. Thanks!

0 Likes 0 ·