Placing Button directly above Banner Ad

Hi guys,

I would like to place an ad directly at the bottom of the screen and a button to get to the next level higher on top of the ad.

I tried to get the Ad height like this to get the dimensions of the banner:

adHeight = 0 local function adListener( event ) local msg = event.response -- Quick debug message regarding the response from the library print( "Message from the ads library: ", msg ) if ( event.isError ) then print( "Error, no ad received", msg ) else print( "Ah ha! Got one!" ) adHeight = ads.height() end end ads.init( adProvider, appID, adListener ) ads.show( "banner", { x=0, y=display.contentHeight, appId=bannerAppID } )

But unfortunately even when the ad is shown the adHeight is still 0. 

Much appreciated for any suggestion!

fj

Hi @fj,

What ad provider are you using?

Brent

Thanks Brent,

I am using AdMob.

fj

Hi @fj,

OK, I suggest that you detect the event.phase of “shown” before trying to get the ad height, because there’s no way to get the height until after the ad is actulally shown. What you’re currently doing is detecting only if there is not an error (as the “else” condition following check of event.isError) and then you try to get the height. This isn’t necessarily “wrong” but you should take it one small step further:

[lua]

    else

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

            print( “Ah ha! Got one!” )

            adHeight = ads.height()

        end

    end

[/lua]

Brent

Thanks again, Brent, but unfortunately this does not work. It looks like, ads.height() does not give anything back even when event.pase == “shown”.

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 print( "Error, no ad received", msg ) else print( "Ah ha! Got one!" ) end if ( event.phase == "shown" ) then adHeight = ads.height() levelText.text = ads.height() end end

It does display levelText.text = 0

Cheers,

fj

I’ve emailed you a test app to try.  Please report back if you’re getting ads.height() with it and see how your app and the sample differ.

Thanks

Rob

Thanks Rob - I did some testing. Your App works due to the config.lua width and height values. It looks like this affects the ads.height() output and if config.lua does not supply those values it returns 0 on the ads.height().

As I dont have any images and have kept everything dynamic to the actual display height and width, I would like to understand what I can do to still get the ad-height.

Thanks!
fj

Try adaptable scaling.

application = {
    content = {
        scale = “adaptive”,

    }

}

Hi Rob,

same problem, ads.height() = 0.

fj

I don’t know if this is a bug or a design limitation. From a user perspective it’s clearly frustrating. There is an existing bug report for this. Given that AdMob is a huge project for us to undertake and we have to approach it in methodical way, I’m not sure how soon this will be addressed.

In the mean time you can either go to a config.lua that has a width/height or guess at what the height will be. Generally speaking on a 320 point wide config.lua, banners should be in the 50 point high range (or perhaps a bit shorter). You might be able to take display.contentWidth / 320 * 50 to perhaps get the approx height of the ad. Or you can look at the standard ad sizes and figure out where the top is. Consider these two links:

https://support.google.com/admob/answer/3098666?hl=en

https://firebase.google.com/docs/admob/android/banner

Rob

Works for me, it is not quite aligned, but definitely a good solution for the time being!

Thanks!

fj

Hi @fj,

What ad provider are you using?

Brent

Thanks Brent,

I am using AdMob.

fj

Hi @fj,

OK, I suggest that you detect the event.phase of “shown” before trying to get the ad height, because there’s no way to get the height until after the ad is actulally shown. What you’re currently doing is detecting only if there is not an error (as the “else” condition following check of event.isError) and then you try to get the height. This isn’t necessarily “wrong” but you should take it one small step further:

[lua]

    else

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

            print( “Ah ha! Got one!” )

            adHeight = ads.height()

        end

    end

[/lua]

Brent

Thanks again, Brent, but unfortunately this does not work. It looks like, ads.height() does not give anything back even when event.pase == “shown”.

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 print( "Error, no ad received", msg ) else print( "Ah ha! Got one!" ) end if ( event.phase == "shown" ) then adHeight = ads.height() levelText.text = ads.height() end end

It does display levelText.text = 0

Cheers,

fj

I’ve emailed you a test app to try.  Please report back if you’re getting ads.height() with it and see how your app and the sample differ.

Thanks

Rob

Thanks Rob - I did some testing. Your App works due to the config.lua width and height values. It looks like this affects the ads.height() output and if config.lua does not supply those values it returns 0 on the ads.height().

As I dont have any images and have kept everything dynamic to the actual display height and width, I would like to understand what I can do to still get the ad-height.

Thanks!
fj

Try adaptable scaling.

application = {
    content = {
        scale = “adaptive”,

    }

}

Hi Rob,

same problem, ads.height() = 0.

fj

I don’t know if this is a bug or a design limitation. From a user perspective it’s clearly frustrating. There is an existing bug report for this. Given that AdMob is a huge project for us to undertake and we have to approach it in methodical way, I’m not sure how soon this will be addressed.

In the mean time you can either go to a config.lua that has a width/height or guess at what the height will be. Generally speaking on a 320 point wide config.lua, banners should be in the 50 point high range (or perhaps a bit shorter). You might be able to take display.contentWidth / 320 * 50 to perhaps get the approx height of the ad. Or you can look at the standard ad sizes and figure out where the top is. Consider these two links:

https://support.google.com/admob/answer/3098666?hl=en

https://firebase.google.com/docs/admob/android/banner

Rob