When the user click an ad...

Is it possible to the app know when the user click an (Admob) ad?

local ads = require “ads”

local function adListener( event )
   if event.isError then
      – Failed to receive an ad.
   end
end

ads.init( “admob”, “myAppId”, adListener )
ads.show( “banner”, { x=0, y=0 } )

When an ad is received from server the adListener function is called.

And is it called even when the user click the ad or not?

If yes, what I need to write in the function (what is the condition)?

I’m just testing and I want that the app presents a text containing the number of times the user clicked an ad.

If it’s not the function adListener that is called, it is another function or no function is called at all?

Thanks

If it has no such listener then you can always draw rectangle over it and make it receive touch

I tried that invisible rectangle (with isHitTestable = true) in the same place and size of the ad, but it does not work.

If I click the ad, the listener of the rectangle where I have the code to update a text, is not called.

So I think it only works if there are a native listener for when the ad is clicked…

You must be doing something wrong if touch doesn’t work

local function clicked()
    numberclicks = numberclicks + 1

    textclicks.text = "clicks = " … numberclicks
    return true
end

rectad = display.newRect( 0, 0, adwidth, adheight )
rectad.isVisible=false
rectad.isHitTestable = true
rectad:addEventListener(“tap”, clicked)


So?

What is wrong?

The ad go to front by itself anf if I click there, the other objects below are not reached and so, their listener is never called…

Hi @galiksoft,

Try removing the “return true” from your “clicked()” function and see if you get a response.

Brent

Have you tried calling rectad:toFront after you instantiate the ad (so your rectangle/touch object is on top of the real ad) … and as Brent said, don’t return true from your listener (otherwise the ad never gets called … and I assume you’ll get no revenue)

I gave up!

I did what you said and it did not work. Never. Simply because the ad is allways in front of any other app object.

If it has no such listener then you can always draw rectangle over it and make it receive touch

I tried that invisible rectangle (with isHitTestable = true) in the same place and size of the ad, but it does not work.

If I click the ad, the listener of the rectangle where I have the code to update a text, is not called.

So I think it only works if there are a native listener for when the ad is clicked…

You must be doing something wrong if touch doesn’t work

local function clicked()
    numberclicks = numberclicks + 1

    textclicks.text = "clicks = " … numberclicks
    return true
end

rectad = display.newRect( 0, 0, adwidth, adheight )
rectad.isVisible=false
rectad.isHitTestable = true
rectad:addEventListener(“tap”, clicked)


So?

What is wrong?

The ad go to front by itself anf if I click there, the other objects below are not reached and so, their listener is never called…

Hi @galiksoft,

Try removing the “return true” from your “clicked()” function and see if you get a response.

Brent

Have you tried calling rectad:toFront after you instantiate the ad (so your rectangle/touch object is on top of the real ad) … and as Brent said, don’t return true from your listener (otherwise the ad never gets called … and I assume you’ll get no revenue)

I gave up!

I did what you said and it did not work. Never. Simply because the ad is allways in front of any other app object.