Monetize your app with Ads
- You have to publish a first version of your app to be able to use AdMob.
- You need to have a Google AdMob account : https://admob.google.com/home/. This may sound strange but it's the way it is. Either way, your app won't launch as you need a an published app to create your app on AdMob.
Configure the Ad mob provider
To facilitate the use of AdMob, we created a provider for you.
But before you can use it, you need to configure it.
- You have to uncomment the related lines in the
lib/core/ads/ads_provider.dart
file. - Update the production environment
androidInterstitialAdUnitId
andiosInterstitialAdUnitId
with the ids you got from AdMob. (Don't change the development environment ids as they are already configured to use test ads.)
👌 A CLI command will be added to do this automatically in the future.
Show an Ad
Once you've created your app on AdMob, and installed the plugin, you can show an ad like this:
As you don't want to show an ad every time the user opens the app, you can use the showIfElapsedTime
method to show an ad only if a certain amount of time has passed since the last time an ad was shown.
We prepared a provider for you to do that. You can use it like this:
// you must have a reference to the Riverpod Ref object
ref
.read(googleAdsProvider.notifier)
.showIfElapsedTime(secondsSinceLastAds: 60);
Either way, you can show an ad directly like this:
// you must have a reference to the Riverpod Ref object
ref
.read(googleAdsProvider.notifier)
.show();
Best practices
I'am not an expert in AdMob but I've been using it for a while now and I've learned a few things.
- Don't use test ads in production. You can use test ads during development but don't forget to remove them before publishing your app. (That's why I've )
- Prefer using Interstitial ads instead of Banner ads. Banner ads are not very profitable and they are not very user friendly.
- Prefer using the method with a timer to not show too much ads. You don't want to annoy your users.
- You can add some tags to your ads to be able to track them in the AdMob console. It's very useful to know which ads are the most profitable.
Additional information
Here's the officiel documentation for the AdMob plugin for Flutter.