As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!

40,926

Views

Beginner

Level

12

Comments

Ads for Android

by Jon (Updated on 2016-10-08)


Contents

  • Introduction
  • Set Up an AdMob Account
  • Initialize Admob in Stencyl
  • Displaying Banner Ads
  • Displaying Interstitial ads
  • Ads Events
  • Other Ad Networks
  • FAQ

Introduction

Although Android supports many ad networks, we've chosen to support AdMob, which is owned and operated by Google itself. Through 3rd-party extensions, Stencyl supports a number of other ad networks.

This guide is for Stencyl build 9279 and higher

Set Up an AdMob Account

Before you can test ads, in your game, you must set up an account with AdMob.

  1. Sign up for an account on AdMob's site.
  2. Provide the details they ask for (Tax Information, Personal Details, etc.)
  3. Monetise a new app for your game. admob_Monetise
  4. Add your app manually or if its already in the store search for it and select your platform.
  5. Add App and take note of the App ID. You'll enter this into the Initialize Block in Stencyl.
  6. Select ad format and name ad unit. Stencyl is only supporting Banner and Interstitial ads at the moment.
  7. Save it and take note of th Ad unit ID (Also called Publisher Key on Stencyl Monetization page). You'll enter this into the Monetization page in Stencyl.
  8. Skip Firebase Firebase Analytics, this is not support by Stencyl.
  9. And your Finished

Initialize Admob in Stencyl

Now that you've set up an account with AdMob, you can test out ads in your game.

Enable Admob

  1. Open your game in Stencyl. Under Settings > Mobile > Monetization.
  2. Enable Admob ads

Enable Test Ads.

Before you publish your game to the store, you want to know if the ads are working. Google does not allow you to click on live ads when testing your game so you have to set Admob in Testmode.

  1. Open your game in Stencyl. Under Settings > Mobile > Monetization.
  2. Enable Test ads

Note: Don't forget to disable Test Ads when your are ready to Publish your game, or else the test ads will show up.

Enter in the AppId.

  1. Take note of your Admob AppId as mentioned above in step 4.
  2. Open your game in Stencyl. In palette under Game > Mobile you can find the Admob blocks.
    admob_initialize
  3. Fill in the AppId in the block, if your are using Banner Ads you can set here if you want it show at the top or at the bottom of your game.

Note: Use this block only once a session as early as possible(Like in a loading scene)

Displaying Banner Ads

Enter in the Ad unit ID

  1. Take note of your AdMob Banner Ad unit ID as mentioned above in step 6. Als called Publisher key on Stencyl Monetization page

  2. Open your game in Stencyl. Under Settings > Mobile > Monetization.

  3. Enter the Ad unit ID in AdMob Banner Android key

Displaying the Banner Ad

To display an ad, you must tell the ad to show. This is done using the show/hide ad block (under Game > Mobile). If you've read our iOS Ads guide, you'll notice that this is the same block.

ad-show-hide

Note: All the blocks that apply to iOS Ads also apply to Android Ads.

Controlling Ad Position

Ad Position is set in the Initialize block using the dropdown. You can choose between Top or Bottom positioning. If you want to change the position on runtime use the

ad-position

Displaying Interstitial (Fullscreen) Ads

Enter in the Ad unit ID

  1. Take note of your AdMob Interstitial Ad unit ID as mentioned above in step 6. Als called Publisher key on Stencyl Monetization page

  2. Open your game in Stencyl. Under Settings > Mobile > Monetization.

  3. Enter the Ad unit ID in AdMob Interstitial Android key

Displaying Interstitial Ads

Before you can show the Interstitial ad, you have to load them first. (Its take a couple of seconds to load an ad). You have to load the ad every after it's showed up.

For example:

  1. Load the ad when player click the start play button
    ad-interstitial-load

  2. Show the ad when player ends his game, like when he is game over.
    ad-interstitial-show

Ads Events

Sometimes, it's useful to know when an ad has been clicked on or dismissed, so that you can provide a smooth transition between viewing the ad and resuming the game. Stencyl provides the following events for ads.

These events can be found under the Mobile > Ads item under the Add Event dropdown.

Banner Ads Events

Event Description
An banner ad is showing The banner ad is showing on screen
An banner ad is closed User closes the banner ad
The banner ad area loads Called each time a banner ad loads
The banner ad area fails to load Called when no banner ads can be loaded
An banner ad is clicked User clicks on the banner ad

Tip: We recommend pausing the game when an ad is clicked on and resuming it when the ad is dismissed. If you don't do this, the game will continue to run while the ad is overlayed over everything else. ad-events

Interstitial Ads Events

Event Description
An fullscreen ad is showing The Interstitial ad is showing on screen
An fullscreen ad is closed User closes the Interstitial ad
The fullscreen ad area loads Called each time a Interstitial ad loads
The fullscreen ad area fails to load Called when no Interstitial ads can be loaded
An fullscreen ad is clicked User clicks on the Interstitial ad

Tip: We recommend pausing the game when an ad is clicked on and resuming it when the ad is dismissed. If you don't do this, the game will continue to run while the ad is overlayed over everything else.

ad-events-interstitial-clicked

ad-events-interstitial-closed

Other Ad Networks

Officially, Stencyl only supports AdMob on Android. Through free, user-created extensions, other ad networks besides AdMob are supported. These include...

Check out our Extensions Market and Extensions Forum for more details.

FAQ

What version of the AdMob SDK is used?

As of late 2016, we're using v9.4 of Google play Services Library (SDK)

Tips

Avoid covering up the screen

When ads are displayed, they will cover up a small part of the screen. You should avoid displaying crucial game elements under an ad, such as HUD elements.

The height of mobile ad block (under Game > Mobile) provides the height, so you can lay your game out accordingly.

Print Article Edit Article How to Edit an Article
Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

12 Comments

Unknown User
1
0 2 years, 1 week ago
VanityBlood
The images on the page are not working, and I am unable to see where to put fill the AppId into the block as you describe? Would this be in the photo?
0 2 years, 9 months ago
henryyy
Has someone tried using Admob together with GlobalHop? As they say on their web page, it can work with any other SDK together.
0 5 years, 6 months ago
glvrn
Suggest that this article be updated to reflect new UI and options.
0 8 years, 5 months ago
Jon
Updated the article to reflect the current state of things.
0 9 years, 1 month ago
luciasp
When i activate the ads and then i test the game on an android device, the adds don't show
2 9 years, 11 months ago
zohaibhisam
For your reference, builds based on the current SDK being used in admob (6.0) will no longer be supported from august 1st. Trying to raise a red flag in advance, support appreciated.
https://developers.google.com/mobil e-ads-sdk/docs/rel-notes

1 10 years, 4 months ago
zohaibhisam
just an FYI, google has stated that it will stop supporting the legacy SDK based builds by august. the new admob IDS are working fine at the moment, but in august the legacy SDK based builds will no longer be acceptable at play (which will mean that if stencyls default admob plugin is based on the legacy SDK, our builds would not be acceptable). Kindly update if necessary, thanks, and if possible please confirm on thread (august is only 20 days away).

z

1 10 years, 4 months ago
zohaibhisam
just migrated to the new admob (legacy admob shuts down aug 31st anyways). the publisher id format has changed. can we use the new format ID just like the old one? e.g. my games old legacy ID (the one that works) is a1531820524bce2
, but the new ID assigned by admob is ca-app-pub-6365002354052646/8477029 218. should i put this in without worrying?

1 10 years, 5 months ago
atreyuatnz
Do I need to add both Show\Hide block or just show? I have followed the above
1 10 years, 6 months ago

Sign In to Comment