Admob doesn’t work

Hello,
I made a game and I want to publish it. I implemented admob ads(interstitials) and found that add appears only on my test device. And if I use my test device there is only one interstitial add shown. Another one ad is shown after app restart. What could be wrong?

Sorry for my English it is not my mother tongue.

Did you pre-load the ads first, then check whether ad has pre-loaded ?

See https://docs.coronalabs.com/plugin/admob/load.html

Yes, this is my implementation.

if ( phase == "will" ) then
	-- Code here runs when the scene is on screen (but is about to go off screen)
	timer.cancel(timerCloud)
-- AdMob listener function
local function adListener( event )

    if ( event.phase == "init" ) then  -- Successful initialization
        -- Load an AdMob interstitial ad
        admob.load( "interstitial", { adUnitId="********", childSafe=true } )
    end
end
-- Initialize the AdMob plugin
admob.init( adListener, { appId="************" } )
--admob end
if ( admob.isLoaded( "interstitial" ) ) then
    admob.show( "interstitial" )
end
elseif ( phase == "did" ) then
	-- Code here runs immediately after the scene goes entirely off screen
-- Sometime later, show the interstitial ad
	composer.removeScene("menu")
	--audio.stop( 1 )
end

end

Looks like your code only preloads the ad once. You need to do it everytime the ad closes. See https://docs.coronalabs.com/plugin/admob/event/adsRequest/phase.html

Add this code into your ‘adListener(event)’

	if ( event.phase == "closed" ) then  
		-- Preload the ad again
		admob.load( "interstitial", { adUnitId="********", childSafe=true } )
	end
1 Like

Thank you very much for your help :slight_smile: and is it true, that ads will be shown for “no test devices” after app publish?

The admob test mode will work after publishing (live to android store) if you set it to test mode, as stated in https://docs.coronalabs.com/plugin/admob/init.html

this means all users downloading your app will see ‘test ads’ and no revenue will come to you. Make sure testMode = false when publishing your app.

admob.init( adListener, { testMode  = true, appId="YOUR_ADMOB_APP_ID" } )

I set test device trough advertising ID (on admob web page in settings section). In my game there is testMode = false because this is set to false as default. If I try my game on “no test device” 0 ads appear and if I set Frequency capping for apps or for ad units only one ad appear in my test device.(without frequency ads works normal in “test device”)

If you are trying to show ‘live’ ads on your test device, most likely there are no available ads to be shown.

I see this no-available-ads on my test-android phone also, as I don’t use this phone for anything else other than testing. I guess admob can’t figure out what my device has been used for and don’t know what ads to show.

Try using the app on a device that you usually use (browsing, playing games, etc).

I tried app on other devices and result is the same 0 ads appear. I don’t know why. I filled all information on admob page(half year ago). And I received mail that my account is verified.

Hi, I tried x-implementations and result is the same. Only thing which is not filled on admob page is link to google play (because my game is not published). My test ads works fine. I have two scenes. One with score and play button. This scene includes this.

> -- hide()
> function scene:hide( event )
> 
> 	local sceneGroup = self.view
> 	local phase = event.phase
> 
> 	if ( phase == "will" ) then
> 		-- Code here runs when the scene is on screen (but is about to go off screen)
> 		timer.cancel(timerCloud)
>     if ( admob.isLoaded( "interstitial" ) ) then
>         admob.show( "interstitial" )
>     end
> 	elseif ( phase == "did" ) then
> 		-- Code here runs immediately after the scene goes entirely off screen
> 		composer.removeScene("menu")
> 	end
> end

Second scene is with game and this scene includes this code.

> -- hide()
> function scene:hide( event )
> 
> 	local sceneGroup = self.view
> 	local phase = event.phase
> 
> 	if ( phase == "will" ) then
> 		-- Code here runs when the scene is on screen (but is about to go off screen)
>     timer.cancel(catchMeController)
>     timer.cancel(theLineTimer)
> 
> 	elseif ( phase == "did" ) then
> 		-- Code here runs immediately after the scene goes entirely off screen
>     switch=true
>     isItOkToLip=false
>     Runtime:removeEventListener("collision",onCollision)
>     physics.stop()
>     composer.removeScene("game")
>     composer.removeScene("setting")
>     -- AdMob listener function
>     local function adListener( event )
>       if (not admob.isLoaded( "interstitial" ) ) then
>         if ( event.phase == "init" ) then  -- Successful initialization
>             -- Load an AdMob interstitial ad
>             admob.load( "interstitial", { adUnitId="ca-app-pub-...", childSafe=true } )
>         elseif ( event.phase == "closed" ) then
>       		-- Preload the ad again
>       		admob.load( "interstitial", { adUnitId="ca-app-pub-...", childSafe=true } )
>         elseif ( event.phase == "failed" ) then
>       		-- Preload the ad again
>       		admob.load( "interstitial", { adUnitId="ca-app-pub-...", childSafe=true } )
>       	end
>       end
>     end
>     -- Initialize the AdMob plugin
>     admob.init( adListener, { appId="..." } )
>     --admob end
> 	end
> end

I added event.phase == “failed” because with this ads works when frequency capping is on. (1 ad per minute)

Will live ads works after publishing?
Thanks for every advice

I have a problem with admob too, and I’m trying to find out the exact cause. Is the platform you tested ios? Is it Android?

It is android. I read discussion which claim that live ads will work after app publishing. Is your app published? And is it ios or android?

In the Android, it worked well before publishing.

admob may take some time to activate.
However, the basic function does not change after publishing.

My ad and account was created half year ago. I really don’t know what is wrong. Is my implementation correct?

Hey, It seems like a common problem:
When you create a new app in the Admob site and new ad units - Admob won’t serve you real ads (for that- specific app) until it decides you can start receiving ads.
“And when is that??” you might be asking.
Well - it most likely to happen few days after you publish your app to Google Play and start receiving real ad request from various devices.

But don’t worry - Admob let you know that you did everything you needed to do and the only problem is that it has no ads to give you - yet (In short: it’s not you, it’s them).
How Admob let you know? by sending you an error. this error is error code 3, which means that the ad request was successful, but no ad was returned due to lack of ad inventory.
as I said, “lack of ad inventory” in your situation happens because this is a new app, but it can be returned for other reasons.

So, to make sure this is the reason why you not see any ads in your app, you can print out the error you receive from the Admob server:
In your admob function listener, you can print the received data from the admob server:

local function adListener( event )
    native.showAlert( "Data from admob:", event.data, { "Close" })
    [...] The rest of your listener
end
admob.init( adListener, { appId="..." } )

Using the native.showAlert line, you show a pop up to the screen with the event.data. this event.data will contains the error code and the error message from admob.

Now, you can run this app on your phone and check if you get an error code 3 from the Admob server - if you do, you can upload your app to Google Play without any fear, you will start receiving ads soon! :slight_smile:

Please let me know if it helped,
Good luck!

More details about request events

Hello,
you really helped me to understand how it works. Thanks for that. Yesterday I tried internal test in google play store and now live ads work well. I tried your Alert and its showing error 1 and sometimes error 3. Function is in my code called only once but 1-6 alerts are shown. Why?

And again big thank. I appreciate your answer :slight_smile: .

Good.
It may take to serve a real ads.

In my case, Android doesn’t need many times.

You defined your function once but it doesn’t get called once because it’s not a regular function like you think… it’s a listener - meaning: it waits for events from the Admob server and when some event arrive - then your function get called. it can be once, but it can be 100. When you init your admob plugin then you will get an event, maybe two - I’m not sure, and then when you request an ad you trigger an event and also when you receive data from the admob Server for the request…

Anyway, if you receive error code 3 it ok, I’ll recommend you to publish your app to Google play even if you get error code 1 for once in a while because error code 1 means that the request wasn’t good but there is many reasons for that (packet lost, connection lost[happens in bad WIFIs] and more… ) there is a nice response I wrote in another question here that I’ll suggest you to read

Also you and @kaeguree - (It might be related to the other question):
There is something in the Admob site called “Match Rate” which determinate how often you get a real ad when you request one (when the match rate is 100% then every time your app asks for an ad it gets one and match rate 0% is the opposite).
it look like that (This is my 71% and its not so good hahaha)
image
So don’t be worry about not getting ads every time … this is how it works :slight_smile:

You both can read about how match rate works, why it’s low, and how to increase it:

  1. Common: https://support.google.com/admob/answer/9655701?hl=en
  2. Admob dashboard: https://support.google.com/admob/answer/7356428?ctx=tltp#admob-network
1 Like

Thank you. You made my day again. You look like skilled developer. I have last question. Is it better to use ChildSafe=true and set in google play console that my target audience contains kids under 13?
admob.load( "interstitial", { adUnitId="ca-app-pub-***", childSafe=true } )

Or is it better to use normal ads and set target audience in google play console to 13+?
admob.load( "interstitial", { adUnitId="ca-app-pub-***} )

It really depends on your app nature and to who it’s aimed for…
childSafe=true can cause a lower match rate, so if your app is general and not children specific, I would not use the childSafe flag…

Happy that I could help, good luck!

1 Like