I use Flutter and using banner ads on my application but I just realized I did the ad integration like that (I'm using Google Admob) ,
so my question is "I use the same bannerAdUnitId for every Banner ads, is it normal approaching or do I need to use different bannerUnitIds for each banner ads in my application ?
class AdManager {
static final AdManager _instance = AdManager._internal();
static AdManager get instance => _instance;
AdManager._internal();
BannerAd? normalModeBannerAd;
BannerAd? categoriesAd;
final bannerAdUnitId =
Platform.isAndroid ? AppSettings.androidBannerAdId : AppSettings.iosBannerAdId;
Future<void> loadCategoriesAd() async {
bool result = await TrackingPermissionHandler.instance.checkTrackingPermission();
if (result) {
if (kDebugMode) {
print('Tracking permission granted.');
}
categoriesAd = BannerAd(
adUnitId: bannerAdUnitId,
size: AdSize.banner,
request: const AdRequest(nonPersonalizedAds: false),
listener: BannerAdListener(
// Called when an ad is successfully received.
onAdLoaded: (Ad ad) {
debugPrint('$BannerAd loaded.');
},
// Called when an ad request failed.
onAdFailedToLoad: (Ad ad, LoadAdError error) {
debugPrint('$BannerAd failedToLoad: $error');
ad.dispose();
},
// Called when an ad opens an overlay that covers the screen.
onAdOpened: (Ad ad) => debugPrint('$BannerAd onAdOpened.'),
// Called when an ad removes an overlay that covers the screen.
onAdClosed: (Ad ad) => debugPrint('$BannerAd onAdClosed.'),
// Called when an ad is in the process of leaving the application.
),
);
categoriesAd?.load();
} else {
if (kDebugMode) {
print('Tracking permission is not granted.');
}
categoriesAd = BannerAd(
adUnitId: bannerAdUnitId,
size: AdSize.banner,
request: const AdRequest(nonPersonalizedAds: true),
listener: BannerAdListener(
// Called when an ad is successfully received.
onAdLoaded: (Ad ad) {
debugPrint('$BannerAd loaded.');
},
// Called when an ad request failed.
onAdFailedToLoad: (Ad ad, LoadAdError error) {
debugPrint('$BannerAd failedToLoad: $error');
ad.dispose();
},
// Called when an ad opens an overlay that covers the screen.
onAdOpened: (Ad ad) => debugPrint('$BannerAd onAdOpened.'),
// Called when an ad removes an overlay that covers the screen.
onAdClosed: (Ad ad) => debugPrint('$BannerAd onAdClosed.'),
// Called when an ad is in the process of leaving the application.
),
);
categoriesAd?.load();
}
}
Future<void> loadNormalModeBannerAd() async {
bool result = await TrackingPermissionHandler.instance.checkTrackingPermission();
if (result) {
if (kDebugMode) {
print('Tracking permission granted.');
}
// Dispose existing ad if it exists
await disposeNormalModeBannerAd();
normalModeBannerAd = BannerAd(
adUnitId: bannerAdUnitId,
size: AdSize.banner,
request: const AdRequest(nonPersonalizedAds: false),
listener: BannerAdListener(
// Called when an ad is successfully received.
onAdLoaded: (Ad ad) {
debugPrint('$BannerAd loaded.');
},
// Called when an ad request failed.
onAdFailedToLoad: (Ad ad, LoadAdError error) {
debugPrint('$BannerAd failedToLoad: $error');
ad.dispose();
},
// Called when an ad opens an overlay that covers the screen.
onAdOpened: (Ad ad) => debugPrint('$BannerAd onAdOpened.'),
// Called when an ad removes an overlay that covers the screen.
onAdClosed: (Ad ad) => debugPrint('$BannerAd onAdClosed.'),
// Called when an ad is in the process of leaving the application.
),
);
normalModeBannerAd?.load();
} else {
if (kDebugMode) {
print('Tracking permission is not granted.');
}
// Dispose existing ad if it exists
await disposeNormalModeBannerAd();
normalModeBannerAd = BannerAd(
adUnitId: bannerAdUnitId,
size: AdSize.banner,
request: const AdRequest(nonPersonalizedAds: true),
listener: BannerAdListener(
// Called when an ad is successfully received.
onAdLoaded: (Ad ad) {
debugPrint('$BannerAd loaded.');
},
// Called when an ad request failed.
onAdFailedToLoad: (Ad ad, LoadAdError error) {
debugPrint('$BannerAd failedToLoad: $error');
ad.dispose();
},
// Called when an ad opens an overlay that covers the screen.
onAdOpened: (Ad ad) => debugPrint('$BannerAd onAdOpened.'),
// Called when an ad removes an overlay that covers the screen.
onAdClosed: (Ad ad) => debugPrint('$BannerAd onAdClosed.'),
// Called when an ad is in the process of leaving the application.
),
);
normalModeBannerAd?.load();
}
}
}
I use same bannerAdUnitId for each banner ads it works no problem but it makes me feel weird,I feel like it's something wrong, also the money is too much low than it has to be , I think it may be not best solution using like that
It's not a problem at all to use the same banner ID on different screens. If you wish, you can create another banner and load different banner IDs on different screens. Having multiple banners gives you better options for analytics. However, if you use the same banner multiple times on the same screen, you may get an error.