Appodeal ad not showing

Is your app really at a point you need to add in Ads? I would consider this one of the last things you want to add in because you will be seeing them as you develop your app. You seem to have multiple apps in production so it’s really hard to judge where you are with them.

Now that said, you do have a problem in main.lua.  You try to tell the .init() function about your listener function when it doesn’t exist yet. Remember Lua is a one pass compiler and you have to define/write things before you can address them. This is that pesky “scope” issue.

local appodeal = require( "plugin.appodeal" ) local json = require( "json" ) local composer = require( "composer" ) local function adListener( event ) print( json.prettify( event ) ) if ( event.phase == "init" ) then -- Successful initialization -- Show a banner ad composer.setVariable( "adsReady", true ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) end end appodeal.init( adListener, { appKey="09e6c681ff134a85e448de94d693efa0fbbe231bca7d0e40", testMode=true} ) composer.gotoScene("start")

Notice how I changed the order of the adListener function and the .init(). I also added in a print statement to dump the results of the event table to the console log so you can see what errors you’re getting.  

Your code jumps immediately to “start.lua”. There is a good chance that appodeal.init() isn’t finished yet and you won’t be able to show an ad until it completes. Do you really want a full screen ad to be the very first thing your users see? Or are you just trying to build a test case?  

I also moved requiring Composer to the top. You should really try and group all your requires at the top of your code. By doing this I can use composer.setVariable() to define a variable that will let your other scenes know when initialization is complete.

Your start scene really needs to do some work before you start trying to load and show ads.

Lets make these changes and see what messages are printing to your console.log.

Rob

I did everything I was suppose to in the start scene :

-- requires local appodeal = require( "plugin.appodeal" ) local composer = require( "composer" ) local scene = composer.newScene() -- background function scene:create(event) local screenGroup = self.view background = display.newImageRect("start.jpg",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) end local options = { effect = "fade", time = 400, } function start( event ) if event.phase == "began" then composer.gotoScene("game", options) end end function scene:show(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("show started") elseif ( phase == "did" ) then print("show showing objects") appodeal.show("interstitial") --\<-------- move this to scene:show()'s "did" phase background:addEventListener("touch", start) end end function scene:hide(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("hide started") composer.removeScene( "start" ) elseif ( phase == "did" ) then print("hide removing objects") appodeal.show("interstitial") --\<-------- move this to scene:show()'s "did" phase background:removeEventListener("touch", start) end end function scene:destroy(event) end scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) scene:addEventListener("destroy", scene) return scene

when i run the app on my phone , I only get the loading sign and that’s it.

I just saw the ad take up about 3 quarters of the screen and only show for about 3 seconds .

Brandon, when people respond to your posts are you just copy/pasting the code or are you reading all the text?

I ask because I asked a couple of questions that didn’t get answered. Also there is a line of code in start.lua that you were asked to “move” but it looks like you copied the line and didn’t remove the line from where it doesn’t belong.

Finally, I had you put in code that would output messages to the device’s console log. Do you know how to read that information? You can’t trouble shoot these problems until you learn how to do that.

Are you on a Mac or Windows? 

Rob

Yes I have two apps that are finished and ready to launch that’s why I want to add in the ads now . When I’m going live , all I have to do is take of testMode = true to show the real ads and not test ones ?

Correct

Thanks .

FYI. Most errors are reported in the device log when you run your app. It’s recommended to check the device log as it usually contains helpful information which can identify problems when things go wrong.

Here are some items to check:

First of all make sure the package id of your app (Example: com.company.appname) in your Appodeal dashboard is exactly the same as what you’re using in your Corona app.

There are also a few things wrong with the code you posted above.

  1. You have 2 functions called adListener. You should only have one.
  2. You’re trying to call appodeal.init() twice. It should only be called once within the lifetime of the app, preferably in main.lua.
  3. There is no yAlign option for interstitials.
  4. While developing your app you should use testMode=true. Live ads will most likely fail when registering new apps (see explanation below). You set test mode when calling init: 
    appodeal.init( adListener, { appKey=“YOUR_KEY”, testMode=true } )

Some general thoughts:

Before your app goes live it’s recommended that you contact Appodeal and tell them about your app so they can “flip the switch” on the mediated ad networks and make sure your app gets proper ads quickly. It’s not entirely necessary to contact them, however if you don’t it will take some time before their mediation system learns about your app so that it can start serving relevant live ads.

Appodeal is a mediation platform which works by letting all participating ad networks compete against each other in real time where the highest bidder wins the impression. For this system to be effective you need more than 10 thousand impressions per day. If you have less than that you might not see any real benefits from using Appodeal mediation as opposed to a standalone ad network plugin.

So it should look like this ? 

main.lua(not all my code) :

local appodeal = require( "plugin.appodeal" ) appodeal.init( adListener, { appKey="appkey", testMode=true} )

All other scenes I want to show an appodeal ad on :

local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization -- Show a banner ad appodeal.show( "interstitial", { yAlign="top" } ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) end end

No, adListener should be in main.lua too (remove appodeal,show() from the listener).

When you want to show an ad you simply call appodeal.show(“interstitial”) in your scene.

Main.lua :

local appodeal = require( "plugin.appodeal" ) appodeal.init( adListener, { appKey="c6e5e59f5c0a2860b5c2c9183dc9af5f", testMode=true} ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization -- Show a banner ad appodeal.show( "interstitial", { yAlign="top" } ) elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) end end local composer = require( "composer" ) composer.gotoScene("start")

start.lua :

-- requires local appodeal = require( "plugin.appodeal" ) local composer = require( "composer" ) local scene = composer.newScene() -- background appodeal.show("interstitial") function scene:create(event) local screenGroup = self.view background = display.newImageRect("start.jpg",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) end ..... .....

Like that ?

Ingemar asked you remove the appodeal.show() call in this block of code:
 

local appodeal = require( "plugin.appodeal" ) appodeal.init( adListener, { appKey="c6e5e59f5c0a2860b5c2c9183dc9af5f", testMode=true} ) local function adListener( event ) if ( event.phase == "init" ) then -- Successful initialization -- Show a banner ad appodeal.show( "interstitial", { yAlign="top" } ) --\<------ take this line out.... elseif ( event.phase == "failed" ) then -- The ad failed to load print( event.type ) print( event.isError ) print( event.response ) end end local composer = require( "composer" ) composer.gotoScene("start")

Then in this block of code:

local appodeal = require( "plugin.appodeal" ) local composer = require( "composer" ) local scene = composer.newScene() -- background appodeal.show("interstitial") --\<-------- move this to scene:show()'s "did" phase function scene:create(event) local screenGroup = self.view background = display.newImageRect("start.jpg",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) end

For Composer scene files, if you put appodeal.show() where you are, the next time the scene loads, it may not run. It’s best to do this in scene:show()'s “did” phase.

Rob

Thanks for the help guys .

Would it make sense if I put 

appodeal.hide( “interstitial” )

In the game.lua file so the ad doesn’t show during the game ?

Or should I leave it alone ?

That depends on your code. If you show the interstitial ad, it covers the whole screen and the user has to tap to close it. They would not be able to get to the game scene without being able to interact with buttons behind the ad… unless you have a timer or something that automatically goes to the game level. If you do that, you would need to call the hide() call. But in most cases, you won’t need to hide an interstitial ad. It’s mostly for banner ads.

Rob

Thanks

Please keep in mind, as per the documentation, you cannot call hide() on interstitials and rewarded videos.
https://docs.coronalabs.com/plugin/appodeal/index.html

You should only call show() when it’s safe to show an ad.
Preferably you should also call isLoaded() to check if an ad is available.

The ads don’t show on my phone . Do I have to take test mode off ?