Got Admob working for Android :)

Just want to mention that this code no longer works. showWebPopup doesn’t return anything, so you you are actually trying to insert a nil value with this line:
[lua]display.getCurrentStage():insert(adSpace, false)[/lua]

You get “app is corrupted” when trying to run on device. [import]uid: 52103 topic_id: 8021 reply_id: 53374[/import]

Here is a modified version, compatible with recent releases of Corona and made as a module - name it whatever you want, but don’t name it “ads.lua” since this is now reserved by Corona for InMobi and future ad providers. For example, “admob.lua” will do.

I also added the option to show the ad on top of the screen.

However, it looks like the timer workaround for jumping ads in original code doesn’t work anymore. When createAd() is call the ad will display normally, then it will quickly shift 2px to the left, then 1px to the right and again 1px to the right, returning to it’s normal position. This happens quickly in 2 sec or so and is a minor thing, but if somebody knows how to get rid of this jumping behavior please share a solution here.

[lua]module(…, package.seeall)

local dummy
local isAndroid = “Android” == system.getInfo(“platformName”)

local CW = display.contentWidth
local CH = display.contentHeight
local SOX = display.screenOriginX
local SOY = display.screenOriginY

local function round(n)
return math.floor(n + 0.5)
end

local function showAd_Android(event)
– Is the url a remote call?
if string.find(event.url, “android_ad.html”, 1, false) then
return true
else
system.openURL( string.gsub(event.url, “Corona:”, “”) )
– Refresh ad
removeAd()
createAd()
return true
end
end

local function showAd_Apple(event)
– Is the url a remote call?
if string.find(event.url, “http://”, 1, false) == 1 then
– Is it a call to the admob server?
if string.find(event.url, “c.admob.com”, 1, false) ~= nil then
– an actual click on an ad, so open in Safari
system.openURL(event.url)
– Refresh ad
removeAd()
createAd()
end
else
return true
end
end

function createAd(showOnTop)
native.cancelWebPopup()

local adfile = “apple_ad.html”
local sizeX = 320
local sizeY = 48
local posX = (CW - sizeX) / 2
– round the Y position to remove the 1px gap
– between the bottom of the ad the bottom of the screen
local posY = showOnTop and SOY or round(CH - SOY - sizeY)

if isAndroid then
adfile = “android_ad.html”
native.showWebPopup(posX, posY, sizeX, sizeY, adfile,
{
baseUrl = system.ResourceDirectory,
hasBackground = false,
urlRequest = showAd_Android
}
)

elseif system.getInfo(“environment”) == “simulator” then
dummy = display.newRect(posX, posY, sizeX, sizeY)
display.getCurrentStage():insert(dummy, false)
else
native.showWebPopup(posX, posY, sizeX, sizeY, adfile,
{
baseUrl = system.ResourceDirectory,
hasBackground = false,
urlRequest = showAd_Apple
}
)
end
end

function removeAd()
native.cancelWebPopup()
if dummy then
dummy:removeSelf()
dummy = nil
end
end[/lua] [import]uid: 52103 topic_id: 8021 reply_id: 53535[/import]

hI guys,

really i don’t like to spoil your fun with adding admob in web views.
Just let you know that my contact on admob/adsense confirmed ‘they’ don’t allow that!

:what i got from google/admob
>>we don’t allow ads to be implemented in the web view, and shown through an app.
>>That applies to AdMob and AdSense.
>>We don’t have a solution for developers using web views in apps right now.

I mention that to keep you out of trouble. As from experience (look in forums) they cancelled several developers admob/adsense accounts in the past and the devs lost a lot of money

In that case it may be better to focus on Inmobi (official in Corona) or as ‘alickgardiner’ mentioned it looks MobFox is fine with implementing ads in that way (i can’t confirm).

Take care and best luck!

Chris
[import]uid: 4795 topic_id: 8021 reply_id: 53537[/import]

Hey guys.

Sorry been away for a few weeks with work. Here’s some replies to various posts. Let me know if I missed anyone…
eusebi: The banner does only have 320x48 pixels, BUT webkit will ‘zoom’ it up on larger screens. Normally the maximum zoom is 1.5, but in some instances it can be higher.

The code handles resizing the webview automatically, but it may be some themeing difference on your device which causes different behaviour.

Check the two SizeX and SizeY lines, and instead of +1 try +2

The only issue with making this value too large is that the ad jumps more on first load.

With regards to your second problem - as far as I know its not possible to preload the webview, since it only loads when you display it. The Webview is always on top too, so you cant even burry it behind an image and preload it there.

What you could try is to open the webpopup OFF screen before the end of the level and move it ON screen when you hit the end of the level.

Be careful with this tho, as opening web popups off screen for impressions wont make admob too happy. But if you open it 3 or 4 seconds before i’m sure thats fine.

One last thing, I personally found that ads in game worked a lot better than on menu screens and level pages between levels.

cullenjwebb: The position of where the webpopup is, is in the webpopup call:

(display.contentWidth - sizeX)/2, display.contentHeight - display.screenOriginY - sizeY, sizeX, sizeY

Here, x is (display.contentWidth - sizeX)/2, or the display width minus the webpopup size, divided by two. Or in other words centred X on the screen
Here, y is (display.contentHeight - display.screenOriginY - sizeY, or the height of the screen + the letterbox area (to find the bottom of the screen) minus the webpopup height.

The -display.screenOriginY is a bit misleading, but OriginY gives you the size of the top letterbox, which will be negative, while the bottom one should be positive. Thats why you - instead of +.

If you want it in the top left you would probably use:

x = -display.OriginX + SizeX/2
y = display.OriginY + sizeY/2

guruk: I’ve been using it without problems since March. Also when it comes to mobile devices, this is actually what this code is for.

EDIT: I just saw chris’s post, and I’m a bit baffled by that. The admob page itself suggests its for web apps :confused: Perhaps they don’t want to oficially say you can do that so they can revoke your account if you do something silly with it.

vitally: oops :slight_smile: You only ever need that insert for the simulator to insert the Rect to the top. I guess it just happen to work before because showWebPopup returned a non nil value. I’ve edited my first post to move that line inside the ‘simulator’ if block.

With regards to the ad jumping around - This is the admob script itself trying to centre the add in the structure or frame its in. Since the script itself is a giant anonymous function there’s no way to override that function without duplicating it locally. I decided against duplicating their function locally as they could at any stage change the embedded url or some other parameter they use. I only override the click event so we can catch it in corona. The original code only implements the timer to allow you to delay showing the webpopup. I use it in my game so I left it in there. You could of course do the same by using performWithDelay yourself.
[import]uid: 8872 topic_id: 8021 reply_id: 53539[/import]

@kam187
as mentioned i just wrote to keep you out of trouble.
I am several years in that business and some things work nice for ‘a while’ till they stop it, than the users scream out they they came stolen money (sometimes they loose several thousand dollars)

WEB Mobile Ads are for WebPages that are most seen on mobiles. But and thats the point, the page 'where the ads are included" needs relevant content, wherein they can search for keywords and make the ads relevant for the users and profitable for the advertiser.

I agree that it would be the best way as you do, because we could change ads and ad networks without uploading the app again :slight_smile:

Take care, my interest is you are on the safe side, thats it. Would be cool Carlos or anyone else could get an official “OK” for that. I will jump on the train immediately :slight_smile:

greets
chris
[import]uid: 4795 topic_id: 8021 reply_id: 53544[/import]

@kam187 I think I’m missing something. The timer just calls showWebPopup with delay and centering of the ad happens after showWebPopup was called. Unless you can showWebPopup and make it visible after a delay when the ad is already centered.
Could you explain how this works? [import]uid: 52103 topic_id: 8021 reply_id: 53548[/import]

From my understanding embedding a page inside your app that loads the admob .js either for a web app or otherwise is what this script is for. I _thought_ hosting the web page and loading it remotely was a no-no.

It seems its all grey :stuck_out_tongue:

Having said that i’ve been using it since march, and a number of other engine like appcelerator to name one, have been doing this forever :confused: [import]uid: 8872 topic_id: 8021 reply_id: 53549[/import]

I’m not able to make it working on 2.3, it only blink 1 second when i call the function and nothing else. [import]uid: 70625 topic_id: 8021 reply_id: 54549[/import]

Has anyone else noticed admob fill rates have dropped ALOT, especially on android. I’m seeing something like 17 to 20% :confused:

Even on iOS its only 50%.
[import]uid: 8872 topic_id: 8021 reply_id: 54908[/import]

Since Sep, 5 that Fill Rate on 2 of my app’s are near 5%.
No answers from Admob.

Anyone has any idea why? [import]uid: 13114 topic_id: 8021 reply_id: 54914[/import]

It has been less than 20% fill rate for me all this while. InMobi is also the same for me (less than 20%). And for me, InMobi takes days (I wonder why) to approve an app for their ads, whilst AdMob does not require approval. Ansca really need to support AdMob if we are going to see better fill rates and better monetization. We really need AdMob SDK integration. [import]uid: 64189 topic_id: 8021 reply_id: 55000[/import]

Totally missed your post there vitalyx for some reason.

The only thing I think you could do it display the webpopup out of the screen, and then bring it into view (change x,y) once its loaded and centered. You can use some JS (look at the admob help page) to check when/if the ad is loaded. Maybe you can send a callback somehow to corona to let it know its ready. [import]uid: 8872 topic_id: 8021 reply_id: 55557[/import]

Thanks for your reply, kam187. Man, these ads are frustrating.
AdMob is not officially supported and InMobi also has it’s share of deal breaking issues. So I decided to go the old way once again. It has always worked well for me. [import]uid: 52103 topic_id: 8021 reply_id: 55773[/import]

I’m using this code to display ads and it seems to be working pretty well. The only thing that’s odd is I’m getting a huge amount of Requests according to AdMob. Just in the last 2 hours I have 2500+ requests and I am the only one with the app installed, and I only ask for a request in between levels.

Any ideas why my request count is so high? [import]uid: 84258 topic_id: 8021 reply_id: 56071[/import]

what do you guys think of this announcement? http://techcrunch.com/2011/09/03/admob-to-stop-serving-ads-to-mobile-web-google-pushes-developers-to-use-adsense/

Does it put a stop on the hack? [import]uid: 8745 topic_id: 8021 reply_id: 56113[/import]

I’m having trouble with this. I think i am pretty close tho. First of all, the ads wont show up. I can only see flickering for about 1 sec. when i start my app. Second, the fillrate is about 30%. Please help. [import]uid: 84344 topic_id: 8021 reply_id: 56276[/import]

Vitalyx are your admob ads working right now? [import]uid: 70625 topic_id: 8021 reply_id: 56837[/import]

@shark.androidlab I decided not to go with ads, but haven’t seen any sales during the past 3 days. So I’ll be releasing ad supported version soon, going with InMobi first.
Android was a big surprise. My sales of stock market app for webOS are doing waaaaay better two years after I released it and that’s on a niche and *dead* platform. Ridiculous! [import]uid: 52103 topic_id: 8021 reply_id: 57636[/import]

Has anyone tried clicking on their own ads to check if they work?
I just did and here is what I see:

Redirect doesn’t work, apparently. Any idea why this can be? [import]uid: 52103 topic_id: 8021 reply_id: 58208[/import]

I have stopped using this AdMob hack. For the first time, my AdMob payout for last month was delayed. After writing in to remind them, only, did they make payment after a week. Each app was fetching thousands of requests each day although the number of new installs is less than a 100 for each app. Also the fill rate was less than 20%. I figured probably the extremely high requests triggered some alarm bells with the AdMob team. So be careful guys.

Official AdMob integration into Corona is still nowhere in sight. Sad. [import]uid: 64189 topic_id: 8021 reply_id: 58290[/import]