Flutter 应用中的多个横幅广告问题

问题描述 投票:0回答:1

我在我的应用程序上使用 Flutter 并使用横幅广告,但我刚刚意识到我做了这样的广告集成(我正在使用 Google Admob),

所以我的问题是“我为每个横幅广告使用相同的bannerAdUnitId,这是正常的做法还是我需要为应用程序中的每个横幅广告使用不同的bannerUnitId?

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();
    }
  }
}

我为每个横幅广告使用相同的bannerAdUnitId,它工作没有问题,但它让我感觉很奇怪,我觉得这是错误的,而且钱比它必须的低太多了,我认为这可能不是最好的解决方案使用像那个

android ios flutter admob banner-ads
1个回答
0
投票

在不同屏幕上使用相同的banner ID完全没有问题。如果您愿意,您可以创建另一个横幅并在不同的屏幕上加载不同的横幅 ID。拥有多个横幅可以为您提供更好的分析选择。但是,如果您在同一屏幕上多次使用同一横幅,则可能会出现错误。

© www.soinside.com 2019 - 2024. All rights reserved.