Closed vacating closed 3 months ago
Hi @vacating, users who select "DO NOT CONSENT" are eligible to receive Limited ads. This is the expected behavior
Hello @malandr2 thanks for the response.
i followed the link that you referred to Limited ads, and i turned off the Programmatic limited ads in my admobe account.
i run my code and i denied the consent i chose " do not consent " the banner ad is still showing,
i am using test banner id ID for banner ad And in the AndroidManifest.xml am using my real admobe account ID for the andriod.
these are the logs i get after i dont consent to ads but the ads still showing
_D/UserMessagingPlatform( 8653): Writing to storage: [IABTCF_CmpSdkID] 300 D/UserMessagingPlatform( 8653): Writing to storage: [IABTCF_CmpSdkVersion] 2 D/UserMessagingPlatform( 8653): Writing to storage: [IABTCF_PolicyVersion] 5 D/UserMessagingPlatform( 8653): Writing to storage: [IABTCF_gdprApplies] 1 D/UserMessagingPlatform( 8653): Writing to storage: [IABTCF_PurposeOneTreatment] 0 D/UserMessagingPlatform( 8653): Writing to storage: [IABTCF_UseNonStandardStacks] 0 D/UserMessagingPlatform( 8653): Writing to storage: [IABTCFVendorConsents] 0
and an error
W/Ads (12681): Not retrying to fetch app settings
can you please guide where the issue would be what other aspect of the admobe i should check or in code.
Hi @vacating, users are still eligible to receive ads when they click "DO NOT CONSENT". See our Frequently asked questions and specifically, How can I check if a user consented?
You can also check the Privacy Signals
section after integrating Ad Inspector, the samples have it included.
hay @malandr2 hello,
could u please see this code , its just 2 file code: the issue is when i withdraw my consent while the banner ad is active it wont disappear unless i go out of the page and come back then its disappear.
**` import 'dart:async';
import 'package:google_mobile_ads/google_mobile_ads.dart';
typedef OnConsentGatheringCompleteListener = void Function(FormError? error);
/// The Google Mobile Ads SDK provides the User Messaging Platform (Google's IAB
/// Certified consent management platform) as one solution to capture consent for
/// users in GDPR impacted countries. This is an example and you can choose
/// another consent management platform to capture consent.
class ConsentManager {
/// Helper variable to determine if the app can request ads.
Future
/// Helper variable to determine if the privacy options form is required.
Future
/// Helper method to call the Mobile Ads SDK to request consent information /// and load/show a consent form if necessary. void gatherConsent( OnConsentGatheringCompleteListener onConsentGatheringCompleteListener) { // For testing purposes, you can force a DebugGeography of Eea or NotEea. ConsentDebugSettings debugSettings = ConsentDebugSettings( // debugGeography: DebugGeography.debugGeographyEea, ); ConsentRequestParameters params = ConsentRequestParameters(consentDebugSettings: debugSettings);
// Requesting an update to consent information should be called on every app launch.
ConsentInformation.instance.requestConsentInfoUpdate(params, () async {
ConsentForm.loadAndShowConsentFormIfRequired((loadAndShowError) {
// Consent has been gathered.
onConsentGatheringCompleteListener(loadAndShowError);
});
}, (FormError formError) {
onConsentGatheringCompleteListener(formError);
});
}
/// Helper method to call the Mobile Ads SDK method to show the privacy options form. void showPrivacyOptionsForm( OnConsentFormDismissedListener onConsentFormDismissedListener) { ConsentForm.showPrivacyOptionsForm(onConsentFormDismissedListener); } }`**
TEST PAGE FILE:
**`import 'package:flutter/material.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; import 'package:grow_todo/consent/consent_manager.dart';
class TestPage extends StatefulWidget { @override _TestPageState createState() => _TestPageState(); }
class _TestPageState extends State
@override void initState() { super.initState(); _initializeAds(); }
void _initializeAds() { ConsentManager().gatherConsent((error) { if (error == null) { _loadBannerAd(); } else { print('Consent error: ${error.message}'); } }); }
void _loadBannerAd() { _bannerAd = BannerAd( adUnitId: 'ca-app-pub-3940256099942544/6300978111', request: AdRequest(), size: AdSize.banner, listener: BannerAdListener( onAdLoaded: (ad) { setState(() { _isBannerAdReady = true; }); // Register ad for potential disposal ConsentManager.registerAd(ad); }, onAdFailedToLoad: (ad, error) { print('Ad failed to load: ${error.message}'); _isBannerAdReady = false; ad.dispose(); }, ), )..load(); }
void _showConsentMessage() { ConsentManager().showPrivacyOptionsForm((FormError? error) { if (error != null) { print('Privacy options form error: ${error.message}'); } else { print('Privacy options form dismissed.'); _initializeAds(); } }); }
@override void dispose() { _bannerAd?.dispose(); super.dispose(); }
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('Test Page')), body: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ if (_isBannerAdReady) Container( height: _bannerAd?.size.height.toDouble(), width: _bannerAd?.size.width.toDouble(), child: AdWidget(ad: _bannerAd!), ), Spacer(), Padding( padding: const EdgeInsets.all(16.0), child: ElevatedButton( onPressed: _showConsentMessage, child: Text('Load Consent Message'), ), ), ], ), ); } } `** if you could say how to remove the current running ads in widget tree after the new ads are stopped , it would be billions of thanks to you
@malandr2 the issue was that i had to dispose the ads in lifecycle diposead() if it fails
thank you for all ur help and assessment god bless , and i give u the "budge of billion thanks" in what u helped.
cheers have good one.
Plugin Version
google_mobile_ads: ^5.1.0
[REQUIRED] Step 2: Describe the problem
I'm encountering an issue with GDPR consent handling using the google_mobile_ads package version ^5.1.0 in my Flutter app. Despite following the official guide and using the example provided, the consent status is not being stored correctly, causing ads to not load or load as expected : @malandr2
Steps to Reproduce
Documentation and Example Used:
Official Guide Example Code:
`import 'dart:async'; import 'package:google_mobile_ads/google_mobile_ads.dart';
typedef OnConsentGatheringCompleteListener = void Function(FormError? error);
class ConsentManager { Future canRequestAds() async {
return await ConsentInformation.instance.canRequestAds();
}
Future isPrivacyOptionsRequired() async {
return await ConsentInformation.instance
.getPrivacyOptionsRequirementStatus() ==
PrivacyOptionsRequirementStatus.required;
}
void resetConsent() { ConsentInformation.instance.reset(); }
void gatherConsent( OnConsentGatheringCompleteListener onConsentGatheringCompleteListener) { ConsentDebugSettings debugSettings = ConsentDebugSettings( debugGeography: DebugGeography.debugGeographyEea, // Force to EU for testing ); ConsentRequestParameters params = ConsentRequestParameters(consentDebugSettings: debugSettings);
}
void showPrivacyOptionsForm( OnConsentFormDismissedListener onConsentFormDismissedListener) { ConsentForm.showPrivacyOptionsForm(onConsentFormDismissedListener); } } `
`import 'dart:io'; import 'package:flutter/material.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; import 'package:grow_todo/consent/ConsentManager.dart'; import 'app_bar_item.dart';
class BannerExample extends StatefulWidget { const BannerExample({super.key});
@override BannerExampleState createState() => BannerExampleState(); }
class BannerExampleState extends State {
final _consentManager = ConsentManager();
var _isMobileAdsInitializeCalled = false;
var _isPrivacyOptionsRequired = false;
BannerAd? _bannerAd;
bool _isLoaded = false;
Orientation? _currentOrientation;
final String _adUnitId = Platform.isAndroid ? 'ca-app-pub-3940256099942544/9214589741' : 'ca-app-pub-3940256099942544/2435281174';
@override void initState() { super.initState();
}
@override Widget build(BuildContext context) { return MaterialApp( title: 'Banner Example', home: Scaffold( appBar: AppBar( title: const Text('Banner Example'), actions: _appBarActions()), body: OrientationBuilder( builder: (context, orientation) { if (_currentOrientation != orientation) { _isLoaded = false; _loadAd(); _currentOrientation = orientation; } return Stack( children: [ if (_bannerAd != null && _isLoaded) Align( alignment: Alignment.bottomCenter, child: SafeArea( child: SizedBox( width: _bannerAd!.size.width.toDouble(), height: _bannerAd!.size.height.toDouble(), child: AdWidget(ad: _bannerAd!), ), ), ) ], ); }, ))); }
List _appBarActions() {
var array = [AppBarItem(AppBarItem.adInpsectorText, 0)];
}
void _loadAd() async { var canRequestAds = await _consentManager.canRequestAds(); if (!canRequestAds) { return; }
}
void _getIsPrivacyOptionsRequired() async { if (await _consentManager.isPrivacyOptionsRequired()) { setState(() { _isPrivacyOptionsRequired = true; }); } }
void _initializeMobileAdsSDK() async { if (_isMobileAdsInitializeCalled) { return; }
}
@override void dispose() { _bannerAd?.dispose(); super.dispose(); } } `
Expected results: The consent status should be stored correctly, allowing ads to be loaded and displayed based on the user's consent. altho i dont consent it laod and show the banner ad:
ps: no error on flutter analyze
Actual results:
it shows the ads altho user didnt consent