How to Monetise your Android App with Firebase Admob
We Android Developers have to make a living somehow. Sure, we can get a job somewhere or be self-employed, but none of that gets nowhere near the most beautiful form of income: PASSIVE INCOME
That’s one great thing we can do as Android Devs, and we have two (common) ways about it. Putting ads on a free app, or selling the app for a price…. or both!
Today, we’ll be doing the former: putting ads on our app. Firebase makes it all easy, because that’s just what Firebase does.
I don’t need Firebase though. Why use it?
True, you don’t need Firebase to integrate Admob, but let me tell you why.
It all lies within Firebase Analytics. Admob uses Analytics to collect information about your users like user demographics and revenue from in-app products. It then uses this information to post ads which the users might actually be interested in. Unbelievable, right?
I won’t go into too much detail about the admob sign up and registration. They’re fairly simple processes and any details couldn’t be laid out better than these little links from Google.
So how do I do it?
Start by adding this dependency.
Initialise MobileAds in your app once per launch
Your app won’t explode if you initialise MobileAds more than once per app launch, but ideally, you can extend Application and call this there.
Choose an ad format
Once imported and initialised, you can think about actually adding the ad, and there are a number of formats which you can choose from. Each has a different way to be implemented and you want to find a format that’s least disruptive to your user.
Those small rectangular ads at the bottom of the screen. They only come in very defined sizes except if you use the smart banner. Placing this smartly without covering important content wouldn’t often disrupt users. They give the least revenue-per-screen-time, but they can easily be the ones that stay on screen the longest.
These are full-screen ads that can be quickly dismissed when your user presses close. They give more revenue than banners but don’t expect them to be on screen for long. These are best used for natural pauses in your in-app flow like when games are loading.
This is a component-based ad format where you customise the elements of the ad so that it can be presented in a way that’s most unobstructive to your users. You can customise the layout, fonts, colours, and all that yourself. Of course, the actual content of the ad will be from the companies delivering the ads. This is quite advanced to set up.
These are video ads that users have the option of watching in exchange for in-app rewards. These tend to be the most rewarding of the formats in terms of revenue, and also the most annoying when completely abused… I’m sorry. I needed that off my chest.
For simplicity sake, we’ll cover the banner ad because that is the quickest and easiest to implement. If another ad format caught your fancy, I’ll link their tutorials down in the conclusion.
Implementing a Banner Ad
1. Add the AdView in your layout
This view is what will contain your banner ad. There are a couple attributes you should take note of:
|Size in dp (WxH)||Description||Availability||AdSize constant|
|320×50||Standard Banner||Phones and Tablets||
|320×100||Large Banner||Phones and Tablets||
|300×250||IAB Medium Rectangle||Phones and Tablets||
|468×60||IAB Full-Size Banner||Tablets||
|Screen width x 32|50|90||Smart Banner||Phones and Tablets||
Your banner can only be set to well-defined sizes. This table lists them all out.
The ID of that particular unit of ad. If your application featured more than one piece of ad, like say, if you had ads in different activities, they’d all require a different adUnitID. (You can get the adUnitIDs you should be using like this)
It would break the policies to run actual ads during development. While your app is still in development, you can use a test adUnitID which is this one. Just remember to switch it for your actual adUnitIDs before you publish.
2. Load the Ad
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
You’ll have to do this per ad unit. That means that if you have ads in multiple activities, you’ll have to run this chunk of code in each when they start.
And that’s it. This should get your ad ready to go!
Ad Placement Policies
There are policies you should follow when running ads in your app.
- Ads should not be placed very close to or underneath buttons or any other object such that the placement of the ad interferes with a user’s typical interaction with the app or ad.
- Ads should not be placed in a location that covers up or hides any area that users have interest in viewing during typical interaction. Ads should not be placed in areas where users will randomly click or place their fingers on the screen.
- Ads should not be placed on a ‘dead end’ screen. There must be a way to exit a screen without clicking the ad (for example, a “back” or “menu” button). Otherwise, the user should be notified that the home button will exit the application.
- Ads should not be placed in applications that are running in the background of the device or outside the app environment. It should be clear to the user which application the ad is associated with or implemented in. Examples include: ads served in widgets; ads launched before the app has opened or after the app has closed.
- Ads should not be placed in a way that prevents viewing of the app’s core content. Ads should not be placed in a way that interferes with navigation or interaction with the app’s core content and functionality. Examples include: an interstitial ad triggered every time a user clicks within the app.
- Publishers are not permitted to place ads on any non-content-based pages such as thank you, error, log in or exit screens. These are the screens that visitors may see upon launching the app, before potentially leaving the app or after performing a specific action on the screen such as a purchase or download. Ads that are the main focus on these types of screens can confuse a visitor into thinking that the ads are actual content, so do not place ads on such screens.
This content has been faithfully copied from this page.
This article is designed more as an introduction to app monetisation with Firebase. To go deeper into banner ads, you can learn how to implement Ad Events, or learn how a Smart Banner works from the official docs.
Or you can read on how to implement the other ad formats from the official docs.