googleads / googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Apache License 2.0
344 stars 285 forks source link

googleads-mobile-flutter SDK causes Invalid Traffic in iOS #1155

Closed kitet closed 3 months ago

kitet commented 3 months ago

I have implemented the banner ads and interstitial ads in my new app. Followed the documentation I have combined rxdart in implementation.

Banner implementation : final _anchoredAdaptiveAd = BehaviorSubject<BannerAd?>();

Future<void> _load() async {
    if (_anchoredAdaptiveAd.valueOrNull == null) {
      final AnchoredAdaptiveBannerAdSize? size =
          await AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
              MediaQuery.of(context).size.width.truncate() - 20);

      if (size == null) {
        return;
      }
      BannerAd(
        adUnitId: Platform.isAndroid
            ? 'ca-app-pub-3940256099942544/6300978111'
            : 'ca-app-pub-3940256099942544/2934735716',
        size: size,
        request: const AdRequest(),
        listener: BannerAdListener(
          onAdLoaded: (Ad ad) {
            _anchoredAdaptiveAd.add(ad as BannerAd);
          },
          onAdFailedToLoad: (Ad ad, LoadAdError error) {
            ad.dispose();
          },
        ),
      ).load();
    }
  }

Function to show banner

Widget _showBanner() {
    return StreamBuilder(
      stream: _anchoredAdaptiveAd,
      builder: (c, s) {
        if (s.hasData) {
          final banner = s.data!;
          return SizedBox(
            width: banner.size.width.toDouble(),
            height: banner.size.height.toDouble(),
            child: AdWidget(ad: banner),
          );
        } else {
          return const SizedBox.shrink();
        }
      },
    );
  }

Interstitial Ad implementation:

_loadInterstitialAd() {
    if (intad.valueOrNull == null && ispremium == null) {
      InterstitialAd.load(
        adUnitId: Platform.isAndroid
            ? 'ca-app-pub-3940256099942544/1033173712'
            : 'ca-app-pub-3940256099942544/4411468910',
        request: const AdRequest(),
        adLoadCallback: InterstitialAdLoadCallback(
          onAdLoaded: (ad) {
            ad.fullScreenContentCallback = FullScreenContentCallback(
              onAdDismissedFullScreenContent: (ad) {
                ad.dispose();
                intad.add(null);
                _loadInterstitialAd();
              },
              onAdFailedToShowFullScreenContent: (ad, error) {
                ad.dispose();
                intad.add(null);
                _loadInterstitialAd();
              },
            );
            intad.add(ad);
          },
          onAdFailedToLoad: (error) {},
        ),
      );
    }
  }

  void showIntad() {
    if (intad.valueOrNull != null) {
      intad.value!.show();
    }
  }

I have read this issue but I see no solution.

Could the documentation be wrong on how these ads should be implemented?

malandr2 commented 3 months ago

Hi @kitet, if you're having policy issues, that should be directed towards the AdMob Developers forum for it to be properly triaged, as this is something the Flutter plugin does not control.

Closing this out. Thanks!

kitet commented 3 months ago

It is a policy issue caused by this sdk. I do not understand the blatant closure.

malandr2 commented 3 months ago

Policy issues are best resolved in the AdMob Developers forum