AdMob with Banner loaded and preload Interstitial At The Same Time

Hi guys,

With the new adMob paid-plugin, there are some changes to the API calls.

In the old API, I just show a banner ad on page (without preload), and at the same time, I preload a ‘interstitial’ ad so it is ready for the user to view (when the user goes to another page).

In the new docs, it has this important note :

Before attempting to show an ad, you must first load one via admob.load() and confirm it's ready to be shown. See the example below for basic usage details.

Is it necessary to preload a banner ad ?

Any issues if I don’t check whether the ad is already preloaded and just call admob.show() ?

What is the best way to show a banner ad on page, and preload a interstitial ad in the background ?

Would it be better for me to create 2 variables and initialise/preload/show/hide them all separately ? 1 for banner, 1 for interstitial (like below)

local ads\_banner = require( "plugin.admob" ) local ads\_interstitial = require( "plugin.admob" ) 

Old reference : https://forums.coronalabs.com/topic/37839-admob-integrate-both-banner-and-interstitual-issue

The plugin should only be required once. Trying to require it more than once will have no effect.

One way to accomplish what you want is to try the following

local admob = require( "plugin.admob" ) -- AdMob listener function local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization admob.load( "interstitial", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) admob.load( "banner", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) elseif ( event.phase == "loaded" ) then if ( event.type == "banner" ) then admob.show( "banner" ) end end end -- Initialize the AdMob plugin admob.init( adListener, { appId="YOUR\_ADMOB\_APP\_ID" } )

A banner only needs to be loaded once. Once it’s loaded you can use admob.hide() and show(“banner”) without loading a new one.

However a new Interstitial must be loaded after it has been shown. This is best accomplished by loading a new interstitial when the interstitial’s “closed” phase triggers.

Thanks for the info.

Wouldn’t I need to call the ‘admob.init()’ again, as the appId differs ? Banner & interstitial has different appId.

local admob = require( "plugin.admob" ) -- AdMob listener function local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization admob.load( "interstitial", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) admob.init( adListener, { appId="YOUR\_ADMOB\_APP\_ID\_INTERSTITIAL" } ) admob.load( "banner", { adUnitId="YOUR\_ADMOB\_APP\_ID\_INTERSTITIAL" } ) elseif ( event.phase == "loaded" ) then if ( event.type == "banner" ) then admob.show( "banner" ) end end end -- Initialize the AdMob plugin admob.init( adListener, { appId="YOUR\_ADMOB\_APP\_ID" } )

I think you’re confusing AppID with AdUnitId. They are not the same thing.

admob.init() is only called once with the AppID found on the AdMob dashboard.

Hmmm, that’s interesting.

I haven’t added any new apps to my AdMob portal for over a year.

I initialise like this for live apps:

admob.init(AdMobListener, {appId = adMobID, testMode = false})  

where adMobID is the interstitial ad unit ID. I cannot recall an App ID existing in the dash at the time.

To load I use:

admob.load(“interstitial”, {adUnitId = adMobID})

admob.load(“banner”, {adUnitId = adMobBannerID})

using each individual unique ad unit ID. At no point have I ever used an App ID - though I can see that one is present for each of my apps!

I wonder if other Corona devs do not use the App ID?

My apps correctly display banners and non-rewarded video.

In the old adMob v2 (the free version), it only needs the ‘AdUnitId’.

I never used my AppID, but only AdUnitId in all my admob init/load/show.  Now the the new Admob paid plugin, it seems to need extra info.

@yosu

Just as I thought! When I recently migrated from the old free AdMob plugin to the new paid AdMob plugin, I missed the App ID concept entirely.

Looking at my AdMob dash my IDs have this format (as I’m sure everyone else’s do):

App ID   ca-app-pub-numbers~numbers1

Interstitial ad unit: ** ca-app-pub-numbers/numbers2**

Banner ad unit: ** ca-app-pub-numbers/numbers3**

@Ingemar - is the  App ID new(ish) to the AdMob portal, or new to Corona’s admob init function?

I admit I am a little worried that I do not use the App ID in any of my apps to init AdMob. Still, all banners and interstitials are showing. Odd?!

The AdMob AppID has been around for a long time ( I think all the way back from 2014 ) and has been the official way to initialize the AdMob SDK ever since.

However previous SDK versions were initialized by using AdUnitIDs, and AdMob have kept that way to initialize their SDK for backward compatibility.

You don’t need to worry too much about it as the SDK will initialize properly anyway, however it’s recommended to update your apps to the official way of initializing with AppID as AdMob may some day decide to remove the legacy way of doing things.

First rate answer as always from you Ingemar.

Much appreciated. :slight_smile:

Hoglet.

Just want to share. There are several phases in the listener, and after some testing, i found that putting the pre-load call in the ‘displayed’ is also needed to ensure it is preloaded everytime.

Important note : Will need a short timer, or else the app will hang (manage to test only on Android device).

Something like this :

local admob = require( "plugin.admob" ) -- AdMob listener function local function adListener( event ) if ( event.phase == "init" ) then -- This is only called ONCE. Successful initialization admob.load( "interstitial", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) admob.load( "banner", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) elseif ( event.phase == "loaded" ) then if ( event.type == "banner" ) then admob.show( "banner" ) end elseif (event.phase == "displayed" ) then local function preloadAds() if event.type ~= 'interstitial' then admob.load( "interstitial", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) end if event.type ~= 'banner' then admob.load( "banner", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) end end local tmpTimer = timer.performWithDelay( 10, preloadAds ) end end -- Initialize the AdMob plugin admob.init( adListener, { appId="YOUR\_ADMOB\_APP\_ID" } )

The plugin should only be required once. Trying to require it more than once will have no effect.

One way to accomplish what you want is to try the following

local admob = require( "plugin.admob" ) -- AdMob listener function local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization admob.load( "interstitial", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) admob.load( "banner", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) elseif ( event.phase == "loaded" ) then if ( event.type == "banner" ) then admob.show( "banner" ) end end end -- Initialize the AdMob plugin admob.init( adListener, { appId="YOUR\_ADMOB\_APP\_ID" } )

A banner only needs to be loaded once. Once it’s loaded you can use admob.hide() and show(“banner”) without loading a new one.

However a new Interstitial must be loaded after it has been shown. This is best accomplished by loading a new interstitial when the interstitial’s “closed” phase triggers.

Thanks for the info.

Wouldn’t I need to call the ‘admob.init()’ again, as the appId differs ? Banner & interstitial has different appId.

local admob = require( "plugin.admob" ) -- AdMob listener function local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization admob.load( "interstitial", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) admob.init( adListener, { appId="YOUR\_ADMOB\_APP\_ID\_INTERSTITIAL" } ) admob.load( "banner", { adUnitId="YOUR\_ADMOB\_APP\_ID\_INTERSTITIAL" } ) elseif ( event.phase == "loaded" ) then if ( event.type == "banner" ) then admob.show( "banner" ) end end end -- Initialize the AdMob plugin admob.init( adListener, { appId="YOUR\_ADMOB\_APP\_ID" } )

I think you’re confusing AppID with AdUnitId. They are not the same thing.

admob.init() is only called once with the AppID found on the AdMob dashboard.

Hmmm, that’s interesting.

I haven’t added any new apps to my AdMob portal for over a year.

I initialise like this for live apps:

admob.init(AdMobListener, {appId = adMobID, testMode = false})  

where adMobID is the interstitial ad unit ID. I cannot recall an App ID existing in the dash at the time.

To load I use:

admob.load(“interstitial”, {adUnitId = adMobID})

admob.load(“banner”, {adUnitId = adMobBannerID})

using each individual unique ad unit ID. At no point have I ever used an App ID - though I can see that one is present for each of my apps!

I wonder if other Corona devs do not use the App ID?

My apps correctly display banners and non-rewarded video.

In the old adMob v2 (the free version), it only needs the ‘AdUnitId’.

I never used my AppID, but only AdUnitId in all my admob init/load/show.  Now the the new Admob paid plugin, it seems to need extra info.

@yosu

Just as I thought! When I recently migrated from the old free AdMob plugin to the new paid AdMob plugin, I missed the App ID concept entirely.

Looking at my AdMob dash my IDs have this format (as I’m sure everyone else’s do):

App ID   ca-app-pub-numbers~numbers1

Interstitial ad unit: ** ca-app-pub-numbers/numbers2**

Banner ad unit: ** ca-app-pub-numbers/numbers3**

@Ingemar - is the  App ID new(ish) to the AdMob portal, or new to Corona’s admob init function?

I admit I am a little worried that I do not use the App ID in any of my apps to init AdMob. Still, all banners and interstitials are showing. Odd?!

The AdMob AppID has been around for a long time ( I think all the way back from 2014 ) and has been the official way to initialize the AdMob SDK ever since.

However previous SDK versions were initialized by using AdUnitIDs, and AdMob have kept that way to initialize their SDK for backward compatibility.

You don’t need to worry too much about it as the SDK will initialize properly anyway, however it’s recommended to update your apps to the official way of initializing with AppID as AdMob may some day decide to remove the legacy way of doing things.

First rate answer as always from you Ingemar.

Much appreciated. :slight_smile:

Hoglet.

Just want to share. There are several phases in the listener, and after some testing, i found that putting the pre-load call in the ‘displayed’ is also needed to ensure it is preloaded everytime.

Important note : Will need a short timer, or else the app will hang (manage to test only on Android device).

Something like this :

local admob = require( "plugin.admob" ) -- AdMob listener function local function adListener( event ) if ( event.phase == "init" ) then -- This is only called ONCE. Successful initialization admob.load( "interstitial", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) admob.load( "banner", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) elseif ( event.phase == "loaded" ) then if ( event.type == "banner" ) then admob.show( "banner" ) end elseif (event.phase == "displayed" ) then local function preloadAds() if event.type ~= 'interstitial' then admob.load( "interstitial", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) end if event.type ~= 'banner' then admob.load( "banner", { adUnitId="YOUR\_ADMOB\_AD\_UNIT\_ID" } ) end end local tmpTimer = timer.performWithDelay( 10, preloadAds ) end end -- Initialize the AdMob plugin admob.init( adListener, { appId="YOUR\_ADMOB\_APP\_ID" } )