Ad Mob - Ads Not Showing

Below is the code I have in my Build Setttings, main.lua and levelComplete.lua.    level complete is where my game goes when a player either ends the level or completes the level.  On that screen they can press one of three buttons:  Replay Level, Play Next Level or End Game.

I had the code set up like below and for a while the ads appeared but I had a loop and ads kept showing every time I pressed a button.  So I tried putting some code at the end of the phase of pressing the buttons but I couldn’t get the ads to show up.  The screen locked up.

So, I went back and set it up like below to see the ads again and now nothing.  No ads.

I’m not sure what I’m doing wrong and would appreciate any guidance.

Thanks,

Lori

BUILD SETTINGS

settings =

{


–ORIENTATION TABLE


orientation =

   {

       default = “portrait”,

       supported = { “portrait”}

   },


–PLUGINS TABLE


plugins =

  {

  -----------------------------------------------------------------------------

  --CORONA

  ----------------------------------------------------------------------------- 

         [“CoronaProvider.gameNetwork.apple”] =

                {

                    publisherId = “com.coronalabs”,

                    supportedPlatforms = { iphone=true, [“iphone-sim”]=true },

                },

           

    -----------------------------------------------------------------------------

    --ADS MOB

    -----------------------------------------------------------------------------

      [“plugin.google.play.services”] = { publisherId = “com.coronalabs” }, 

   },

   android = 

   {

      usesPermissions = 

      {

         “android.permission.INTERNET”,

         “android.permission.ACCESS_NETWORK_STATE”,

      },

MAIN.LUA


–Assign Various Ad ID’s


local interstitialAppID = “ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXX”   – for IOS interstitial–

if (system.getInfo(“platformName”) == “Android”) then

  interstitialAppID = “ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXXXXXX” --for Android int

end

local adProvider = “admob”

local ads = require (“ads”) --Require the Ads Plugin 

local testMode = true

local function adListener( event )

  for k,v in pairs( event ) do

     print("adListener ", k, v ) – so you see everything you get

  end

end

local function adListener(event)

– The ‘event’ table includes:

   – event.name: string value of “adsRequest”

   – event.response: message from the ad provider about the status of this request

   – event.phase: string value of “loaded”, “shown”, or “refresh”

   – event.type: string value of “banner” or “interstitial”

   – event.isError: boolean true or false

   local msg = event.response

   – Quick debug message regarding the response from the library

   print( "Message from the ads library: ", msg )

        if ( event.isError ) then

          – attempt to fetch another ad

       elseif ( event.phase == “loaded” ) then

          – an ad was preloaded

       elseif ( event.phase == “shown” ) then

          – the ad was viewed and closed

       end

 end

  

     if ( ads.isLoaded(“interstitial”) ) then

           ads.show(“interstitial”)

     end

appID = interstitialAppID

ads.init (adProvider, appID, adListener)

ads:setCurrentProvider(“admob”)

ads.load(“admob”, { appId = interstitialAppID, testMode = testMode } )

LEVEL COMPLETE SCREEN

local ads = require (“ads”) --Require the Ads Plugin

local testMode = true

------------------------------------------------------------------------ 

–SCENE SHOW

------------------------------------------------------------------------ 

 function scene:show( event )

local sceneGroup = self.view

local phase = event.phase

if phase == “will” then

– Called when the scene is still off screen and is about to move on screen

  elseif phase == “did” then

  


–AD MOB


ads.load(“interstitial”, { appId=interstitialAppID } )

ads.show(“interstitial”, { appId=interstitialAppID } )

------------------------------------------------------------------------ 

–SCENE HIDE

------------------------------------------------------------------------ 

function scene:hide( event )

local sceneGroup = self.view

local phase = event.phase

     if event.phase == “will” then

            ads.hide( “interstitial” )

  

      elseif phase == “did” then

  – Called when the scene is now off screen

       composer.removeScene(“levelComplete”)

       end 

end

There are a couple of things I see.

First you have to adListener() functions. It’s only going to use the last one defined.

Secondly I would start with just calling ad.show() and skip ad.load(). The purpose of ad.load() is to let you preload the ad before you show it. It doesn’t make sense to call ad.load() then immediately call ad.show() because there is a good chance the ad won’t be loaded that fast.

Then watch your console.log and look for the print statements from your listener function.

Rob

I put:  local testMode = true   in my main.lua  (See Above)

I looked at my adMob account and it shows $0.63.    Am I set up properly to test?   I didn’t think it would generate any revenue if I am in the test mode.

What change do I need to make so it is test?

Thanks,

Lori

You’re not setting testMode here:

ads.load(“interstitial”, { appId=interstitialAppID } )

ads.show(“interstitial”, { appId=interstitialAppID } )

In levelcomplete.

Rob

1)  Do I need to leave :   local testMode = true on Level Complete?

2) To confirm, I setting as follows makes it in test mode?      

        ads.load(“admob”, { appId = interstitialAppID, testMode = testMode } )

I was thinking the local testMode = true set it to test.

THANKS Rob

Lori

testMode = true  while testing your app, change it to false before you publish your app.

Rob

Many thanks ROB

I made the changes as I understand them.  My code is now as shown below.  Now nothing is happening.   Sorry to be a bother but I’m not able to resolve the issue at hand and would appreciate any help.  

When testing, do actual test ads appear?    If I have to test on a device, how can I check the console log messages?

Thanks  Lori

BUILDSETTINGS.LUA - SAME AS ABOVE

MAIN.LUA


–Assign Various Ad ID’s


 

local interstitialAppID = “ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXX”   – for IOS interstitial–

 

if (system.getInfo(“platformName”) == “Android”) then

  interstitialAppID = “ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXXXXXX” --for Android int

end

 

local adProvider = “admob”

 

local ads = require (“ads”) --Require the Ads Plugin 

local testMode = true

 

 

local function adListener(event)

 

– The ‘event’ table includes:

   – event.name: string value of “adsRequest”

   – event.response: message from the ad provider about the status of this request

   – event.phase: string value of “loaded”, “shown”, or “refresh”

   – event.type: string value of “banner” or “interstitial”

   – event.isError: boolean true or false

 

   local msg = event.response

   – Quick debug message regarding the response from the library

   print( "Message from the ads library: ", msg )

 

        if ( event.isError ) then

          – attempt to fetch another ad

       elseif ( event.phase == “loaded” ) then

          – an ad was preloaded

       elseif ( event.phase == “shown” ) then

          – the ad was viewed and closed

       end

 end

  

     if ( ads.isLoaded(“interstitial”) ) then

           ads.show(“interstitial”)

     end

 

appID = interstitialAppID

ads.init (adProvider, appID, adListener)

ads:setCurrentProvider(“admob”)

ads.load(“admob”, { appId = interstitialAppID, testMode = testMode } )

 

LEVEL COMPLETE SCREEN

 

local ads = require (“ads”) --Require the Ads Plugin

local testMode = true

 

------------------------------------------------------------------------ 

–SCENE SHOW

------------------------------------------------------------------------ 

 

 function scene:show( event )

local sceneGroup = self.view

local phase = event.phase

 

if phase == “will” then

– Called when the scene is still off screen and is about to move on screen

 

 

 

  elseif phase == “did” then

  


–AD MOB


ads.show(“interstitial”, { appId = interstitialAppID, testMode = testMode } )

 

------------------------------------------------------------------------ 

–SCENE HIDE

------------------------------------------------------------------------ 

function scene:hide( event )

local sceneGroup = self.view

local phase = event.phase

 

     if event.phase == “will” then

 

            ads.hide( “interstitial” )

  

      elseif phase == “did” then

  – Called when the scene is now off screen

 

       composer.removeScene(“levelComplete”)

 

       end 

end

It is now working.  I don’t think I was allowing enough load time when the level complete screen loads.  

This answer is resolved.

Fantastic

There are a couple of things I see.

First you have to adListener() functions. It’s only going to use the last one defined.

Secondly I would start with just calling ad.show() and skip ad.load(). The purpose of ad.load() is to let you preload the ad before you show it. It doesn’t make sense to call ad.load() then immediately call ad.show() because there is a good chance the ad won’t be loaded that fast.

Then watch your console.log and look for the print statements from your listener function.

Rob

I put:  local testMode = true   in my main.lua  (See Above)

I looked at my adMob account and it shows $0.63.    Am I set up properly to test?   I didn’t think it would generate any revenue if I am in the test mode.

What change do I need to make so it is test?

Thanks,

Lori

You’re not setting testMode here:

ads.load(“interstitial”, { appId=interstitialAppID } )

ads.show(“interstitial”, { appId=interstitialAppID } )

In levelcomplete.

Rob

1)  Do I need to leave :   local testMode = true on Level Complete?

2) To confirm, I setting as follows makes it in test mode?      

        ads.load(“admob”, { appId = interstitialAppID, testMode = testMode } )

I was thinking the local testMode = true set it to test.

THANKS Rob

Lori

testMode = true  while testing your app, change it to false before you publish your app.

Rob

Many thanks ROB

I made the changes as I understand them.  My code is now as shown below.  Now nothing is happening.   Sorry to be a bother but I’m not able to resolve the issue at hand and would appreciate any help.  

When testing, do actual test ads appear?    If I have to test on a device, how can I check the console log messages?

Thanks  Lori

BUILDSETTINGS.LUA - SAME AS ABOVE

MAIN.LUA


–Assign Various Ad ID’s


 

local interstitialAppID = “ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXX”   – for IOS interstitial–

 

if (system.getInfo(“platformName”) == “Android”) then

  interstitialAppID = “ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXXXXXX” --for Android int

end

 

local adProvider = “admob”

 

local ads = require (“ads”) --Require the Ads Plugin 

local testMode = true

 

 

local function adListener(event)

 

– The ‘event’ table includes:

   – event.name: string value of “adsRequest”

   – event.response: message from the ad provider about the status of this request

   – event.phase: string value of “loaded”, “shown”, or “refresh”

   – event.type: string value of “banner” or “interstitial”

   – event.isError: boolean true or false

 

   local msg = event.response

   – Quick debug message regarding the response from the library

   print( "Message from the ads library: ", msg )

 

        if ( event.isError ) then

          – attempt to fetch another ad

       elseif ( event.phase == “loaded” ) then

          – an ad was preloaded

       elseif ( event.phase == “shown” ) then

          – the ad was viewed and closed

       end

 end

  

     if ( ads.isLoaded(“interstitial”) ) then

           ads.show(“interstitial”)

     end

 

appID = interstitialAppID

ads.init (adProvider, appID, adListener)

ads:setCurrentProvider(“admob”)

ads.load(“admob”, { appId = interstitialAppID, testMode = testMode } )

 

LEVEL COMPLETE SCREEN

 

local ads = require (“ads”) --Require the Ads Plugin

local testMode = true

 

------------------------------------------------------------------------ 

–SCENE SHOW

------------------------------------------------------------------------ 

 

 function scene:show( event )

local sceneGroup = self.view

local phase = event.phase

 

if phase == “will” then

– Called when the scene is still off screen and is about to move on screen

 

 

 

  elseif phase == “did” then

  


–AD MOB


ads.show(“interstitial”, { appId = interstitialAppID, testMode = testMode } )

 

------------------------------------------------------------------------ 

–SCENE HIDE

------------------------------------------------------------------------ 

function scene:hide( event )

local sceneGroup = self.view

local phase = event.phase

 

     if event.phase == “will” then

 

            ads.hide( “interstitial” )

  

      elseif phase == “did” then

  – Called when the scene is now off screen

 

       composer.removeScene(“levelComplete”)

 

       end 

end

It is now working.  I don’t think I was allowing enough load time when the level complete screen loads.  

This answer is resolved.