AdMob using both banner and interstitial ads - HELP!

My app currently displays banner ads. I want to change this to show an interstitial ad when the app first starts, then after that ad is gone and a user clicks a button to start, the banner ads will appear (as they currently do).

With the code below the interstitial ad appears but never the banner ad. All of this is through one provider - AdMob. Build is most recent build.

Here’s what’s going on:

appID = interstitialAppID;
ads.init( adProvider, appID, adListener ); — init is first called with the interstitialAppID

– check if online, if so then

ads.show( “interstitial”, { appID=interstitialAppID } ); — this DOES show the interstitial ad

– once closed, the user clicks a button to start and the following is executed:

ads.hide(); – tried without this line too

ads.show( “banner”, { x=0, y=0, appID=bannerAppID } ); – NO banner is ever displayed :frowning:

Any dual-ad experts here?

Hello @lessmsios,

Did you carefully follow through the recent tutorial on AdMob V2?

http://coronalabs.com/blog/2014/07/15/tutorial-implementing-admob-v2/

Best regards,

Brent

Thanks for your quick reply Brent.

I’ve read through it several times. It looks like it should be simple as this excerpt from that post:

ads.show( “banner”, { x=0, y=0, appID=bannerAppID } )
ads.show( “interstitial”, { appID=interstitialAppID } )

But this is essentially what I’m doing in the code I previously posted. One part I’m not positive about is this example a few lines previous:

local ads = require( “ads” )
local bannerAppID = “ca-app-pub-nnnnnnnnnnn/nnnnnnnnn” --for your iOS banner
local interstitialAppID = “ca-app-pub-nnnnnnnnnnn/nnnnnnnn” --for your iOS interstitial
if ( system.getInfo( “platformName” ) == “Android” ) then
     bannerAppID = “ca-app-pub-nnnnnnnnnnn/nnnnnnnnn” --for your Android banner
     interstitalAppID = “ca-app-pub-nnnnnnnnnnn/nnnnnnnnn” --for your Android interstitial
end

local adProvider = “admob”
local function adListener( event )
–(more on this later)
end

ads.init( adProvider, appID, adListener )

The “ads.init” is initialized with “appID” which has not be initialized. I made an assumption that was one of the “banner” or “interstitial” appID strings.

Any thoughts?

I would suggest flushing our your adListener function and put in some print statements to see if you have an error and what the response from the server is.   You can look for this output in your device’s console log.  It will tell you what’s going on.

Rob

Hey lessmsios, did you figure it out? I have the same problem. I read that when you do “ads.init” you can put whichever appID with no problem, just as long as you ask for the correct ads in the “ads.show” part. But it isn’t working for me.

Nope. The tutorial http://coronalabs.com/blog/2014/07/15/tutorial-implementing-admob-v2/ mentions using both but there is no working code example that proves it does. :frowning:

Hello @lessmsios,

Did you carefully follow through the recent tutorial on AdMob V2?

http://coronalabs.com/blog/2014/07/15/tutorial-implementing-admob-v2/

Best regards,

Brent

Thanks for your quick reply Brent.

I’ve read through it several times. It looks like it should be simple as this excerpt from that post:

ads.show( “banner”, { x=0, y=0, appID=bannerAppID } )
ads.show( “interstitial”, { appID=interstitialAppID } )

But this is essentially what I’m doing in the code I previously posted. One part I’m not positive about is this example a few lines previous:

local ads = require( “ads” )
local bannerAppID = “ca-app-pub-nnnnnnnnnnn/nnnnnnnnn” --for your iOS banner
local interstitialAppID = “ca-app-pub-nnnnnnnnnnn/nnnnnnnn” --for your iOS interstitial
if ( system.getInfo( “platformName” ) == “Android” ) then
     bannerAppID = “ca-app-pub-nnnnnnnnnnn/nnnnnnnnn” --for your Android banner
     interstitalAppID = “ca-app-pub-nnnnnnnnnnn/nnnnnnnnn” --for your Android interstitial
end

local adProvider = “admob”
local function adListener( event )
–(more on this later)
end

ads.init( adProvider, appID, adListener )

The “ads.init” is initialized with “appID” which has not be initialized. I made an assumption that was one of the “banner” or “interstitial” appID strings.

Any thoughts?

I would suggest flushing our your adListener function and put in some print statements to see if you have an error and what the response from the server is.   You can look for this output in your device’s console log.  It will tell you what’s going on.

Rob

Found the problem,…  {appId = “xxxx”} (small “d”), not  {appID = “xxxx”} (capital “D”)  :slight_smile:

Heres my code for showing different type of admob ads. It works for me, I don’t have them run in the same scene though, so like banner on the start menu for example and pop up occurs in the game after game over for example. But:

local AdMob = require("ads") local adMobId = "ca-app-pub-my#" local adMobIdInter = "ca-app-pub-diff#" local adMobListener = function(event) print("ADMOB AD - Event: " .. event.response) end AdMob.init( "admob", adMobId, adMobListener ) --Than where I need to show it: AdMob.show( "banner", {x=0, y=position}) AdMob.show( "interstitial", {appId=adMobIdInter} )

Can someone please help me fix my code to were my banner ads show up

My Build.setting code; 

settings = { plugins = { ["CoronaProvider.ads.admob"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true } }, ["plugin.google.play.services"] = { publisherId = "com.coronalabs", supportedPlatforms = { android=true }, }, ["CoronaProvider.gameNetwork.google"] = { --required! publisherId = "com.coronalabs", supportedPlatforms = { android=true } }, ["facebook"] = { publisherId = "com.coronalabs", supportedPlatforms = { iphone=true}, }, }, orientation = { default = "portrait", supported = { "portrait", } }, android = { usesPermissions = { "android.permission.INTERNET", "android.permission.ACCESS\_NETWORK\_STATE", }, }, iphone = { plist = { UIAppFonts = { "QuentinCaps.ttf", }, UIViewControllerBasedStatusBarAppearance = false, UIStatusBarHidden = true, CFBundleIconFile = "Icon.png", CFBundleIconFiles = { "Icon.png", "Icon@2x.png", "Icon-60.png", "Icon-60@2x.png", "Icon-72.png", "Icon-72@2x.png", "Icon-76.png", "Icon-76@2x.png", "Icon-Small.png", "Icon-Small@2x.png", "Icon-Small-50.png", "Icon-Small-50@2x.png", }, UIApplicationExitsOnSuspend = false, -- must be false for single sign-on to work FacebookAppID = "329435700566704", -- replace XXXXXXXXX with your facebook appId CFBundleURLTypes = { { CFBundleURLSchemes = { "fb329435700566704", -- replace XXXXXXXXX with your facebook appId, make sure that you leave fb in front of "app910588198" } } } } }, }

my main.lua 

local composer = require( "composer" ) display.setStatusBar(display.HiddenStatusBar) \_G.prefLib = require "prefLib" \_G.adsLib = require "adsLib" \_G.networksLib = require "networksLib"; local activeNetworksProviders = { ["Android"] = {"google", "CgkIhNyInMgZEAIQAQ"}, ["iPhone OS"] = {"gamecenter", "CgkIhNyInMgZEAIQAQ"} --replace "gamecenter" with "none" if you don't use any leaderboard! }; --networksLib.init(activeNetworksProviders); -- For in game Ad's use this table and call local activeAdsProviders = { ["Android"] = {"chartboost","admob","revmob"}, ["iPhone OS"] = {"chartboost","admob","revmob"}, }; adsLib.init(activeAdsProviders); ---===================sound related tasks \_G.musicChannel = 1; audio.reserveChannels(1); --and let's immediately set the volume to the values saved throughout plays local m = prefLib.getSaveValue("musicVolume") or .3 prefLib.setSaveValue("musicVolume",m,true) audio.setVolume(m, {channel = \_G.musicChannel}); for i = 2, audio.totalChannels do local s = \_G.prefLib.getSaveValue("sfxVolume") or .5 prefLib.setSaveValue("sfxVolume",s,true) audio.setVolume(s, {channel = i}); end --also, we're going to use this sound everywhere, so I'll load it here as a global variable once \_G.splashSFX = audio.loadStream("sounds/splash.mp3"); \_G.clickSFX = audio.loadSound("sounds/click.wav"); \_G.fireSFX = audio.loadSound("sounds/spring.wav"); \_G.jumpSFX = audio.loadSound("sounds/jump.wav"); \_G.rocketSFX = audio.loadSound("sounds/rocket.wav"); \_G.fallSFX = audio.loadSound("sounds/fall.wav"); \_G.coinSFX = audio.loadSound("sounds/coin.mp3"); \_G.gunShot = audio.loadSound("sounds/gunshot.mp3"); audio.play(splashSFX, {channel = audio.findFreeChannel()}); -- Later... local img = display.newImageRect("assets/Splash Screen1.jpg",640,1136) img.x = display.contentWidth/2 img.y = display.contentHeight/2 local function move() display.remove(img);img = nil composer.gotoScene( "homescene","fade",1500 ) end timer.performWithDelay(4000,move,1)

Please help me fix this ASAP. Thanks

@LsVtechTurbo95, please do not ask your question more than once a day.  This is called “Bumping” and we only permit bumping once per day.  It takes time for the community to come on and read your post.  You are also only allowed to post the same question in one forum thread. 

We want you to get help, but if you keep posting this over and over, we will be forced to remove your excessive posts. 

Thank you!

Here is the code I used for the the tutorial to test it.

-------------------------------------------------------------------------------- -- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license -- Copyright (C) 2013 Corona Labs Inc. All Rights Reserved. -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- Setup -------------------------------------------------------------------------------- -- Hide the status bar display.setStatusBar( display.HiddenStatusBar ) -- Load Corona 'ads' library local ads = require( "ads" ) -------------------------------------------------------------------------------- -- Setup ad provider -------------------------------------------------------------------------------- -- The name of the ad provider. local provider = "admob" -- Your Android application ID local bannerAppID = "ca-app-pub-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/\*\*\*\*\*\*\*\*\*\*" local interstitialAppID = "ca-app-pub-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/\*\*\*\*\*\*\*\*\*" if system.getInfo("platformName") == "iPhone OS" then     -- Your iOS application IDs     intersititalAppID = "ca-app-pub-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/\*\*\*\*\*\*\*\*\*"     bannerAppID = "ca-app-pub-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/\*\*\*\*\*\*\*\*\*" end function print\_r ( t )     local print\_r\_cache={}     local function sub\_print\_r(t,indent)         if (print\_r\_cache[tostring(t)]) then             print(indent.."\*"..tostring(t))         else             print\_r\_cache[tostring(t)]=true             if (type(t)=="table") then                 for pos,val in pairs(t) do                     if (type(val)=="table") then                         print(indent.."["..pos.."] =\> "..tostring(t).." {")                         sub\_print\_r(val,indent..string.rep(" ",string.len(pos)+8))                         print(indent..string.rep(" ",string.len(pos)+6).."}")                     elseif (type(val)=="string") then                         print(indent.."["..pos..'] =\> "'..val..'"')                     else                         print(indent.."["..pos.."] =\> "..tostring(val))                     end                 end             else                 print(indent..tostring(t))             end         end     end     if (type(t)=="table") then         print(tostring(t).." {")         sub\_print\_r(t,"  ")         print("}")     else         sub\_print\_r(t,"  ")     end     print() end -- create a background for the app local background = display.newRect( 0, 0, display.contentWidth, display.contentHeight ) background.anchorX = 0 background.anchorY = 0 background:setFillColor( 0, 0, 0.5 ) -- Create a text object to display ad status local statusText = display.newText( "", 0, 0, native.systemFontBold, 22 ) statusText:setFillColor( 255 ) statusText.x, statusText.y = display.contentWidth \* 0.5, 160 -- Set up ad listener. local function adListener( event )     -- event table includes:     --         event.provider     --        event.isError (e.g. true/false )     print\_r(event)     local msg = event.response     -- just a quick debug message to check what response we got from the library     print("Message received from the ads library: ", msg)     if event.isError then         statusText:setFillColor( 1, 0, 0 )         statusText.text = "Error Loading Ad"         statusText.x = display.contentWidth \* 0.5         showAd( "banner", appID )     else         statusText:setFillColor( 0, 1, 0 )         statusText.text = "Successfully Loaded Ad"         statusText.x = display.contentWidth \* 0.5     end end -- Initialize the 'ads' library with the provider you wish to use. local appID = bannerAppID if not bannerAppID then     appID = interstitalAppID end ads.init( provider, appID, adListener ) local function showBannerAd()     ads.show("banner", { appId = bannerAppID, testMode = true }) end local function preloadInterstitialAd()     ads.load("interstital", { appId = intersititalAppID, testMode = true }) end local function showInterstitialAd()     ads.show() end local function showInterstitial()     print("checking to see if the interstital is ready")     if ads.isLoaded("interstitial") then         print("showing the interstitial")         ads.show("interstitial", { appId = interstitialAppID, testMode = true })         timer.cancel(showAdTimer)         showAdTimer = nil     end end local function changeAds()     print("changing ad types")     ads.hide()     --     -- use the ads.show() to test just showing an interstitial     -- use the ads.load() to test using ad.load()     --     --ads.show("interstitial", { appId = interstitialAppID, testMode = true } )     ads.load("interstitial", { appId = interstitialAppID, testMode = true } )     showAdTimer = timer.performWithDelay(100, showInterstitial,0) end -------------------------------------------------------------------------------- -- UI -------------------------------------------------------------------------------- -- initial variables local sysModel = system.getInfo("model") local sysEnv = system.getInfo("environment") -- Shows a specific type of ad showAd = function( adType, vendorAppID )     local adX, adY = 0, display.contentHeight - 30     statusText.text = "Showing " .. adType     ads.show( adType, { x=adX, y=adY, appId=vendorAppID, testMode = true } ) end -- if on simulator, let user know they must build for device if sysEnv == "simulator" then     local font, size = native.systemFontBold, 22     local warningText = display.newRetinaText( "Please build for device or Xcode simulator to test this sample.", 0, 0, 290, 300, font, size )     warningText:setTextColor( 1 )     warningText.x, warningText.y = display.contentWidth \* 0.5, display.contentHeight \* 0.5 else     -- start with banner ad     showAd( "banner", appID )     timer.performWithDelay(15000, changeAds, 1) end local function onSystemEvent( event )     print( "System event name and type: " .. event.name, event.type )     if event.type == "applicationResume" and isInterstitialShowing then         print("The ad closed")         showBannerAd()     end end Runtime:addEventListener( "system", onSystemEvent )

 Does my code look right and where do I add this to and is the to replace something or to add with something?

-------------------------------------------------------------------------------- -- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license -- Copyright (C) 2013 Corona Labs Inc. All Rights Reserved. -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -- Setup -------------------------------------------------------------------------------- -- Hide the status bar display.setStatusBar( display.HiddenStatusBar ) -- Load Corona 'ads' library local ads = require( "ads" ) -------------------------------------------------------------------------------- -- Setup ad provider -------------------------------------------------------------------------------- -- The name of the ad provider. local provider = "admob" -- Your Android application ID local bannerAppID = "ca-app-pub-8347067101481503/5236550917" local interstitialAppID = "ca-app-pub-8347067101481503/2335507715" if system.getInfo("platformName") == "iPhone OS" then -- Your iOS application IDs intersititalAppID = "ca-app-pub-8347067101481503/4080572917" bannerAppID = "ca-app-pub-8347067101481503/3759817713" end function print\_r ( t ) local print\_r\_cache={} local function sub\_print\_r(t,indent) if (print\_r\_cache[tostring(t)]) then print(indent.."\*"..tostring(t)) else print\_r\_cache[tostring(t)]=true if (type(t)=="table") then for pos,val in pairs(t) do if (type(val)=="table") then print(indent.."["..pos.."] =\> "..tostring(t).." {") sub\_print\_r(val,indent..string.rep(" ",string.len(pos)+8)) print(indent..string.rep(" ",string.len(pos)+6).."}") elseif (type(val)=="string") then print(indent.."["..pos..'] =\> "'..val..'"') else print(indent.."["..pos.."] =\> "..tostring(val)) end end else print(indent..tostring(t)) end end end if (type(t)=="table") then print(tostring(t).." {") sub\_print\_r(t," ") print("}") else sub\_print\_r(t," ") end print() end -- create a background for the app local background = display.newRect( 0, 0, display.contentWidth, display.contentHeight ) background.anchorX = 0 background.anchorY = 0 background:setFillColor( 0, 0, 0.5 ) -- Create a text object to display ad status local statusText = display.newText( "", 0, 0, native.systemFontBold, 22 ) statusText:setFillColor( 255 ) statusText.x, statusText.y = display.contentWidth \* 0.5, 160 -- Set up ad listener. local function adListener( event ) -- event table includes: -- event.provider -- event.isError (e.g. true/false ) print\_r(event) local msg = event.response -- just a quick debug message to check what response we got from the library print("Message received from the ads library: ", msg) if event.isError then statusText:setFillColor( 1, 0, 0 ) statusText.text = "Error Loading Ad" statusText.x = display.contentWidth \* 0.5 showAd( "banner", appID ) else statusText:setFillColor( 0, 1, 0 ) statusText.text = "Successfully Loaded Ad" statusText.x = display.contentWidth \* 0.5 end end -- Initialize the 'ads' library with the provider you wish to use. local appID = bannerAppID if not bannerAppID then appID = interstitalAppID end ads.init( provider, appID, adListener ) local function showBannerAd() ads.show("banner", { appId = bannerAppID, testMode = true }) end local function preloadInterstitialAd() ads.load("interstital", { appId = intersititalAppID, testMode = true }) end local function showInterstitialAd() ads.show() end local function showInterstitial() print("checking to see if the interstital is ready") if ads.isLoaded("interstitial") then print("showing the interstitial") ads.show("interstitial", { appId = interstitialAppID, testMode = true }) timer.cancel(showAdTimer) showAdTimer = nil end end local function changeAds() print("changing ad types") ads.hide() -- -- use the ads.show() to test just showing an interstitial -- use the ads.load() to test using ad.load() -- --ads.show("interstitial", { appId = interstitialAppID, testMode = true } ) ads.load("interstitial", { appId = interstitialAppID, testMode = true } ) showAdTimer = timer.performWithDelay(100, showInterstitial,0) end -------------------------------------------------------------------------------- -- UI -------------------------------------------------------------------------------- -- initial variables local sysModel = system.getInfo("model") local sysEnv = system.getInfo("environment") -- Shows a specific type of ad showAd = function( adType, vendorAppID ) local adX, adY = 0, display.contentHeight - 30 statusText.text = "Showing " .. adType ads.show( adType, { x=adX, y=adY, appId=vendorAppID, testMode = true } ) end -- if on simulator, let user know they must build for device if sysEnv == "simulator" then local font, size = native.systemFontBold, 22 local warningText = display.newRetinaText( "Please build for device or Xcode simulator to test this sample.", 0, 0, 290, 300, font, size ) warningText:setTextColor( 1 ) warningText.x, warningText.y = display.contentWidth \* 0.5, display.contentHeight \* 0.5 else -- start with banner ad showAd( "banner", appID ) timer.performWithDelay(15000, changeAds, 1) end local function onSystemEvent( event ) print( "System event name and type: " .. event.name, event.type ) if event.type == "applicationResume" and isInterstitialShowing then print("The ad closed") showBannerAd() end end Runtime:addEventListener( "system", onSystemEvent )

You should be able to take the code I have, put it into a main.lua.  Change your AppID’s as needed from your AdMob portal.   And as long as you have the plugin in your build.settings it should work.

This was designed to be a stand alone test app.  It’s based off of the AdMob sample app on the Corona SDK Github repository.

Rob

How do I can “Change your AppID’s as needed from your AdMob portal” ?

Still nothing. I dont know what going on. I’m starting to feel like I wasted money on my basic account when i cant even place ads on my app. Which means I willn’t make anything from it whats so ever and I already have 700+ users in 2 days since the app has been placed on android.  I still in “waiting for review” for iOS. I submit the app there tuesday. I NEED HELP WITH THIS ASAP.

change the AppID’s in this code with your own.

-- Your Android application ID local bannerAppID = "ca-app-pub-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/\*\*\*\*\*\*\*\*\*\*" local interstitialAppID = "ca-app-pub-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/\*\*\*\*\*\*\*\*\*" if system.getInfo("platformName") == "iPhone OS" then     -- Your iOS application IDs     intersititalAppID = "ca-app-pub-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/\*\*\*\*\*\*\*\*\*"     bannerAppID = "ca-app-pub-\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/\*\*\*\*\*\*\*\*\*" end

 And I’m statin

I need help I dont know were to place this stuff. Can you please place in my code and send it to me were I can just paste it. I have 8 other careers. Please understand. And this is really starting to stress me out.