AdMob Integration Examples Needed

I’m finding it surprisingly difficult to integrate ads with AdMob. I have my game basically complete, but I’ve been stuck on incorporating ads, as the documentation seems extremely spotty and I can’t find a single example that works when repurposed into my app.

The AdMob section of the Corona database was slightly helpful, but lacked the bigger picture explanation that I needed to actually load an ad. I got a couple test ads to show, but not consistently.

Additionally, I couldn’t find any examples that worked around, or even mentioned, the scenes template. Does anyone have a clear example/ explanation for loading a banner or interstitial ad into my program?

Hi. There is on one-size fits all way to handle ads.

Tell folks how you’d like them to work in your game and you might get some advice.

Tell folks what interfaces your game has, how then are connected and where + when you want ads to show up.

I’m not sure how the AdMob docs aren’t complete. They include all the details you need to init(), load(), show(), etc. https://docs.coronalabs.com/plugin/admob/index.html

I think, maybe you’re hoping for some kind of framework example or maybe some best known methods?

With regards to composer (you referred to ‘scene template’), how is your code put together. Did you put all your game code right in the scene files or did you keep it organized in separate module files and simply call the needed module function from scenes. It is far easier to add ads and other features later if you maintain clean and small scene files.

1 Like

Based on the docs here. Important thing is that you need to pre-load the banner, interstitial, reward ads. You can further customize your ad selections in your own google-AdMob settings page.

Brief steps :

  1. Make sure you add in the correct ad-ids
  2. Call admob.init()
  3. Call admob.load() to preload the ad.
  4. Check if ad is pre-loaded using admob.isLoaded()
  5. If ad has been pre-loaded, then admob.show()

Below are the undocumented ‘event.phase’ for the adListener in ‘admob.init()’

  1. init (this is return when admob.init is called)
  2. loaded (pre-loaded ad has been loaded. You can now display ad)
  3. refreshed (this is when ad is shown and refreshed on page)
  4. hidden (ad is hidden)
  5. closed (when interstitial ad is closed by user)
  6. reward (when user finish watching a reward video. NOTE : reward-ads has bugs where close-button will not be shown at the end of the video)
  7. displayed (when ad is displayed)
1 Like

@yosu,

Great help, but let me point out one detail you had wrong. I’m not chastising here, but I want you and others to know how to find this in the future.

You said the phases were undocumented. Fortunately, they are documented, but it is a little tricky to find them.

  1. Go here: https://docs.coronalabs.com/plugin/admob/index.html
  2. On left side of screen, under ‘Events’, click adsRequest (goes here: https://docs.coronalabs.com/plugin/admob/event/adsRequest/index.html)
  3. Then, click ‘event.phase’ under the Properties section (goes here: https://docs.coronalabs.com/plugin/admob/event/adsRequest/phase.html)

Almost all features with specific events have their event docs locatable in a similar fashion.

Thanks. i guess i missed that doc link out.

I was working with those docs for most of yesterday, and I even found a few older forum posts that made me realize fairly early that I had been placing my ad code in composer incorrectly, so I worked on fixing that.

I’m planning on starting with a banner ad that stays in place throughout the app’s duration. I’m also planning on adding an interstitial at the start of a specific scene, but I was having so much trouble with the banner loading consistently that I haven’t even worked on that much yet.

I placed almost exactly the example from this (minus the admob.hide) in my main.lua, and it worked perfectly the first time I launched the app. https://docs.coronalabs.com/plugin/admob/hide.html

The banner loaded quickly while I was on the app’s home screen, stayed while I was in-game, and lasted into the high scores page, as intended.

However, as soon as I exited and restarted the app, it never appeared again. I was having similar issues before with my previous implementations where I could get the ads to load but only sporadically (with the interstitial as well).

I have almost no experience working with modules, which is definitely limiting me and especially complicates adding in the interstitial. My game code is fairly small, as the game is relatively simple, but not compartmentalized like that at all.

I’m not positive, but I think the bulk of my issue stems from the fact that I’m not sure when to pre-load my ads and when/ how to implement a continuous check to see if said ads are loaded so that I can show them.

My game is based around the default composer template, with a home scene, game scene, and high scores scene, if that helps. The scenes are transitioned between each other through buttons, except for the game scene, which transitions into the high scores page upon a player’s loss after a brief delay so that they may view their score. I was hoping that that delay period would be a good time to pre-load an interstitial, but I’m not sure how I’d implement that when I need it in a different scene.

Thank you for your time and help.

I also have my AdMob dashboard set up, and I wasn’t getting results with my own ads in test mode, so I’ve been using the test ad unit codes as recommended.

Thank you, at what point should I pre-load though? I was having a lot of trouble with loading ads early enough to actually be shown.

UPDATE:

I opened up the current build of my app today and strangely, the banner is working completely fine. Last night I made a few changes where the app reloaded/ attempted to show a banner each scene, in addition to the function and init in the main, and it didn’t seem to make any difference. Since then, however, I’ve made zero changes to the code, and now it works, so maybe it was just a slight service error last night?

Which version of Solar2D and Admob are you using? is your app already being monetized? already in the store?

I’m using whatever the last update for Corona was, and the version of AdMob that shows up for free in the Corona plugin store.

No, my app is not already being monetized, this is my first attempt.

It’s not in the store yet, I’m looking to configure the ads first, finish up my icons, and release some time within the next few days.

Part of the issue may have been with the fact that I made my AdMob account quite recently (?)