question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ads placed in ListView is getting impression before they appear on the screen in Flutter 3

See original GitHub issue

Hi, I originally posted this here https://github.com/googleads/googleads-mobile-flutter/issues/269#issuecomment-1059741368, before the new Android PlatformView implementation was merged with the stable channel, but this issue is now in Flutter 3 stable channel.

With the new Android PlatformView implementation, banner placed in ListView is getting impression before it appears on the screen. This conflicts with Admob policy. (https://support.google.com/admob/answer/3269069?hl=en) In the previous version, getting impression only when the first pixel of banner is seen on the screen.

This is a critical issue, apps using this plugin with Flutter 3 can be banned by Admob, because technically you are creating fake impressions with this implementation.

Steps to Reproduce

To reproduce, try this example code with Flutter 3, plugin version doesn’t matter.

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView.builder(
        itemCount: 15,
        itemBuilder: (context, index) {
          if (index != 0 && index % 5 == 0) {
            return const _BannerAd();
          }

          return Container(
            height: 200,
            color: Color((Random().nextDouble() * 0xFFFFFF).toInt())
                .withOpacity(1),
          );
        },
      ),
    );
  }
}

class _BannerAd extends StatefulWidget {
  const _BannerAd({Key? key}) : super(key: key);

  @override
  _BannerAdState createState() => _BannerAdState();
}

class _BannerAdState extends State<_BannerAd>
    with AutomaticKeepAliveClientMixin {
  @override
  bool get wantKeepAlive => true;

  late BannerAd myBanner;

  @override
  void initState() {
    super.initState();
    myBanner = BannerAd(
      adUnitId: BannerAd.testAdUnitId,
      size: AdSize.banner,
      request: const AdRequest(),
      listener: BannerAdListener(
        onAdLoaded: (ad) => print('Ad loaded.'),
        onAdFailedToLoad: (ad, error) {
          ad.dispose();
          print('Ad failed to load .');
        },
        onAdOpened: (ad) => print('Ad opened.'),
        onAdClosed: (ad) => print('Ad closed.'),
        onAdImpression: (ad) => print('Ad impression.'),
      ),
    )..load();
  }

  @override
  void dispose() {
    myBanner.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);

    return Container(
      width: myBanner.size.width.toDouble(),
      height: myBanner.size.height.toDouble(),
      margin: const EdgeInsets.all(20),
      alignment: Alignment.center,
      child: AdWidget(ad: myBanner),
    );
  }
}

Expected results: Ads placed in the ListView should get impression when they appear on the screen.

Actual results: All ads in ListView are simultaneously get impression when the ListView is built.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:21

github_iconTop GitHub Comments

6reactions
marcellocamaracommented, Aug 15, 2022

I think because of this bug I got suspension for the last 7 months (I’ve migrated to facebook audience network)

Unfortunatelly, google admob, do not have a support to contact to resolve it (yes, I’m trying to reach contact for 7 months)

Error when try to contact on https://support.google.com/admob/gethelp:

Captura de Tela 2022-08-15 às 10 03 43

Google forum thread that I’ve created, and have many others peoples complaining: https://groups.google.com/g/google-admob-ads-sdk/c/NCshQ7Fh46w/m/MI2p3ULMBwAJ

1reaction
jjliu15commented, Oct 31, 2022

@bparrishMines I did some more testing and have confirmed that https://github.com/bparrishMines/flutter/tree/current_engine_main fixes the issue. You can also verify by checking out https://github.com/jjliu15/googleads-mobile-flutter-1/tree/impression_bug and running the example app.

After removing the visibility workaround and using flutter:stable the current behavior is:

  • The test BannerAd uses a loaded impression definition, so it should not be used for testing this issue
  • If you slowly scroll the AdManagerBannerAd and NativeAd into view, you’ll see that their impressions are fired about half a screen before they are actually visible

After removing the visibility workaround and using https://github.com/bparrishMines/flutter/tree/current_engine_main, the impressions occur when the ad views are scrolled into view.

Read more comments on GitHub >

github_iconTop Results From Across the Web

showing admob banner ads randomly in listview builder
Comments • 3 ; How do I show interstitial ads in flutter - Interstitial google admob ads. Proto Coders Point · 4.1K views...
Read more >
Implement Banner Ad between Listview items in a flutter.
flutter #flutterTutorial # listview #listviewseparated #bannerAds #AdmobAds#interstitialAds Show Ads between listview items in a flutter.
Read more >
Flutter :- This AdWidget is already in the Widget tree. How to ...
If you placed this AdWidget in a list, make sure you create a new instance in the builder function with a unique ad...
Read more >
Flutter AdMob Monetization – Banner and Interstitial Ads
Before the user can see the ad, it needs to be created and then loaded. First, let's import the Google Mobile Ads for...
Read more >
Rewarded ads | Android - Google Developers
// Called when a click is recorded for an ad. ... // Called when ad is dismissed. // Set the ad reference to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found