AdRequest the right way

161 views
Skip to first unread message

Matheus Araujo

unread,
Jul 21, 2016, 1:08:52 PM7/21/16
to Google Mobile Ads SDK Developers
I change the demo script and it works for me:

 using GoogleMobileAds.Api;
    void Start(){
        RequestInterstitial();
    }

    private void RequestInterstitial()
    {
        #if UNITY_EDITOR
            string adUnitId = "unused";
         #elif UNITY_ANDROID
            string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxx";
         #elif (UNITY_5 && UNITY_IOS) || UNITY_IPHONE
            string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
        #else
            string adUnitId = "unexpected_platform";
        #endif

        // Create an interstitial.
        interstitial = new InterstitialAd(adUnitId);

        // Load an interstitial ad.
        interstitial.LoadAd(createAdRequest());
    }

    private AdRequest createAdRequest()
    {
        return new AdRequest.Builder()
                .AddTestDevice(AdRequest.TestDeviceSimulator)
                .AddTestDevice("0123456789ABCDEF0123456789ABCDEF")
                .AddKeyword("game")
                .SetGender(Gender.Male)
                .SetBirthday(new DateTime(1985, 1, 1))
                .TagForChildDirectedTreatment(false)
                .AddExtra("color_bg", "9B30FF")
                .Build();
    }

   public void endGame(){
        if (interstitial.IsLoaded())
        {
            interstitial.Show();
        }
    }

Now I want to remove the test device to use that on real work, all I need to make is to change the method  createAdRequest() like this:

    private AdRequest createAdRequest()
    {
        return new AdRequest.Builder().Build();
    }

That will work? There is some arguments that I need to put on the AdRequest? If I need to change something can someone give me a example?

Thank's

Vu Chau (Mobile Ads SDK Team)

unread,
Jul 21, 2016, 5:17:32 PM7/21/16
to Google Mobile Ads SDK Developers
Hi there,

Removing the AddTestDevice from your AdRequest Builder will stop serving test ads to your app.  However, doing that does not necessarily guarantee you will see live ads.  To get live ads, first you will create an ad unit ID on admob.com.  Then, plug it in correspondingly in your RequestInterstitial logic:
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID //if serving to an Android implementation
string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxx";
#elif (UNITY_5 && UNITY_IOS) || UNITY_IPHONE //if serving to an iOS implementation
string adUnitId = "INSERT_IOS_INTERSTITIAL_AD_UNIT_ID_HERE";
#else
string adUnitId = "unexpected_platform";
#endif
Vu Chau
Mobile Ads SDK Team

Matheus Araujo

unread,
Jul 21, 2016, 8:07:39 PM7/21/16
to Google Mobile Ads SDK Developers
I alredy created an ad unit ID and put it on rigth place. I need to do something else?

Vu Chau (Mobile Ads SDK Team)

unread,
Jul 21, 2016, 9:17:48 PM7/21/16
to Google Mobile Ads SDK Developers
Hi Matheus

That should be all you need to do to serve live ads.

Are you running into any issues?  Do you have logs (console, Charles), ad unit ID, et al. if so?

Vu Chau
Mobile Ads SDK Team

Matheus Araujo

unread,
Jul 21, 2016, 9:24:05 PM7/21/16
to Google Mobile Ads SDK Developers
No, I just wanted to know if everything was right. Thanks :D 
Reply all
Reply to author
Forward
0 new messages