-
Notifications
You must be signed in to change notification settings - Fork 293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[App Open Ad] AdError code 3, message the ad can not be shown when app is not in foreground
in production
#906
Comments
Hi @peterweb2005 Please provide the entire error stack trace as well. Thank you! |
this only means that if I mismatched event for fullscreen ads, eg AppLifecycleState event for App Open Ads,, but not AppStateEventNotifier.appStateStream events and moreover, AppStateEventNotifier.appStateStream still inaccurate for App Open Ads, which I opened another issue Edited Edited also |
Hi @peterweb2005 |
just your sample, app open ad, thanks |
Can you share the steps to reproduce the issue? I check this with app_open_example but the ad can display well: DemoRecord_2023-08-23-17-34-33.mp4 |
yes but if you had a published app, and use the sample code for app open ads, and crash log the show error, onAdFailedToShowFullScreenContent: (ad, error) { the crashlytics would tell for example, |
Thanks for your response. It looks like This could be related to your implementation, please see googleads/googleads-mobile-android-examples#145 and please confirm you also didn't trigger ad to show from background. Btw, can you share places where you are showing ad in your app? |
yes, please, as i mentioned many times,
@override
void initState() {
super.initState();
AppOpenAdManager appOpenAdManager = AppOpenAdManager()..loadAd();
_appLifecycleReactor =
AppLifecycleReactor(appOpenAdManager: appOpenAdManager);
_appLifecycleReactor.listenToAppStateChanges();
}
void listenToAppStateChanges() {
AppStateEventNotifier.startListening();
AppStateEventNotifier.appStateStream
.forEach((state) => _onAppStateChanged(state));
}
void _onAppStateChanged(AppState appState) {
print('New AppState state: $appState');
if (appState == AppState.foreground) {
appOpenAdManager.showAdIfAvailable();
}
} |
Thanks for your response. Looks like it's only reproducible in production, I will label the issue for the investigation. I will mark this issue as App Open Ad issue. For the interstitial ad, I'm not sure how your implementation looks like, please file a new issue for it. Thank you! |
AdError code 3, message the ad can not be shown when app is not in foreground
in production
all I can tell is that it is not only in production, |
summary,
|
I ran into exactly the same issue (or bug). If I sleep for 80ms before calling showAdIfAvailable, it always works. I found around 20ms is the threshold on my phone (SM-G937U1). Here is my "workaround": public void onStart(@nonnull LifecycleOwner owner) { |
@wujieliulan I currently trying visibility detector, which the plugin depends, there has a important updateIntevral variable |
May I ask how you detect visibility? |
EDIT |
Hello, I would like to get a more detailed explanation on how to reproduce this problem since my attempts to get the same error message were unsuccessful. If I understand correctly, this happens even in the app_open_example project on both production and debug versions. Also, I understand that it happens sometimes but what I don't understand is the exact steps you follow to get the error. What I did:
My result was that, when it detected going to background and then foreground, it always showed the open ad with no error message at all. |
it is hardly to reproduce the error when just 1 user, or developer don't forget, add the line to report error inside onAdFailedToShowFullScreenContent, if error code is 3 Thanks EDIT |
Thanks @peterweb2005 . I found out that locking and unlocking the phone while the app is in the foreground is the most reliable way to reproduce this error message. I also found that the issue comes from the native Android format (don't know about iOS) and have triaged to look into the problem. |
Actually Google had a new release on last week, they seemed to fix it, it doesn't happen to me, which is good, I don't need the work around anymore. The new version is com.google.android.gms:play-services-ads:22.4.0 |
@wujieliulan Thanks for that. @peterweb2005 can you confirm that upgrading the Android SDK to |
how? EDIT |
@peterweb2005 For the sake of experiment, if the api of the Android GMA SDK is set to In doing so, are you still able to reproduce the issue? |
EDIT publishing after comfired the versions 22.4.0 |
Got it, thanks. |
seems still happen, but dont know if the rate lower |
isnt it obvious? when showing interstitial, after wait on resumed, no error code 3 why when showing app opened ad, after on foreground, but not wait on resumed? |
is it ok?? check both app state AppLifecycleState.resumed & AppStateEventNotifier's AppState.foreground static const interval = Duration(milliseconds: 50);
static const maxInterval = Duration(milliseconds: 250);
StreamSubscription<int>? appResumedSubscription;
pause() {
log.finer('pause()');
appResumedSubscription?.cancel();
appResumedSubscription = null;
}
resume({required AdAppState adAppState}) async {
log.finer('resume()');
log.finest('userAccepted: ', userAccepted);
if (userAccepted) {
log.finest('adAppState: ', adAppState);
switch (adAppState) {
case AdAppState.app:
// page ad..
case AdAppState.admob:
// if page ad end
if (ref.read(adProvider.notifier).pageAdEnded == true) {
log.finest('isAppResumed: ', isAppResumed);
if (isAppResumed) {
appOpenAdHandler.resume();
} else {
appResumedSubscription ??= RxUtil.interval(
initialDelay: interval,
period: interval,
).listen(
(int i) {
log.finer('onData()');
//log.finest('i: ', i);
final time = interval * (i + 1);
log.finest('time: ', time);
if (isAppResumed || time >= maxInterval) {
//
if (foreground) {
log.finest('call resume, time: ', time);
debugShow('call resume, time: $time');
appOpenAdHandler.resume();
}
appResumedSubscription?.cancel();
appResumedSubscription = null;
}
},
onError: (e) {
throw e;
},
//cancelOnError: true,
);
}
}
default:
}
}
}
|
WARNINGthe above approach is good, much lower error rate, it is just admob foreground event (which happen earlier) wait for flutter resumed event, |
Following up on this, the issue was fixed in #843, which updated Closing the issue. |
…ue as googleads/googleads-mobile-flutter#906. PiperOrigin-RevId: 575274160
…ue as googleads/googleads-mobile-flutter#906. PiperOrigin-RevId: 576531757
nothing changed |
@malandr2 stat update, error rating updated from 5.8% to 9.5% |
See #1029 (comment) for any insight, the fix applied there may be applicable for others. |
NO that 2 flags, thanks EDIT Rewarded Ad, App Open Ad, Interstitial Ad, diff cases |
Error continues: #1196 |
I have solved this issue by putting some delay between when the app comes to the foreground and call showAppOpen function |
await canRequestAds, i thought it legal (update) not solved, just halved |
AppLifecycleState
https://api.flutter.dev/flutter/dart-ui/AppLifecycleState.html
AppStateEventNotifier
https://pub.dev/documentation/google_mobile_ads/latest/google_mobile_ads/AppStateEventNotifier-class.html
otherwise may throw AdError code 3, message the ad can not be shown when app is not in foreground
but AppStateEventNotifier events are very not active (rare) compared with AppLifecycleState events?
thanks
updated
provide message for the ad error code 3
Interstitial
Interstitials that show when your app is in the background are a violation of AdMob policies and may lead to blocked ad serving. To learn more, visit https://googlemobileadssdk.page.link/admob-interstitial-policies
App Open
The ad can not be shown when app is not in foreground.
The text was updated successfully, but these errors were encountered: