Posts tagged with admob

I am trying to add google native ads in my flutter app using this library

https://pub.dev/packages/google_mobile_ads

i am getting this error:

\[log\] NativeAd failed to load: LoadAdError(code: 0, domain: com.google.android.gms.ads, message: Internal error., responseInfo: ResponseInfo(responseId: _-SvZbabD5e-3LUP4oaxkAs, mediationAdapterClassName: , adapterResponses: \[AdapterResponseInfo(adapterClassName: com.google.ads.mediation.admob.AdMobAdapter, latencyMillis: 83, description: { "Adapter": "com.google.ads.mediation.admob.AdMobAdapter", "Latency": 83, "Ad Source Name": "Reservation campaign", "Ad Source ID": "7068401028668408324", "Ad Source Instance Name": "\[DevRel\] \[DO NOT EDIT\] Native Ads Campaign", "Ad Source Instance ID": "3518433842871043", "Credentials": { "pubid": "ca-app-pub-3940256099942544/2247696110/cak=no_cache&cadc=c3&caqid=_-SvZfiWDr-FmsMPtMWtgAM", "campaign_id": "12584073087" }, "Ad Error": { "Code": 0, "Message": "Internal error.", "Domain": "com.google.android.gms.ads", "Cause": "null" } }, adUnitMapping: {pubid: ca-app-pub-3940256099942544/2247696110/cak=no_cache&cadc=c3&caqid=\_-SvZfiWDr-FmsMPtMWtgAM, campaign_id: 12584073087}, adError: AdError(code: 0, domain: com.google.android.gms.ads, message: Internal error.), adSourceName: Reservation campaign, adSourceId: 7068401028668408324, adSourceInstanceName: \[DevRel\] \[DO NOT EDIT\] Native Ads Campaign, adSourceInstanceId: 3518433842871043)\], loadedAdapterResponseInfo: null), responseExtras: {mediation_group_name: Campaign}) 

Minimal Code to Reproduce

Native Controller:

import 'package:get/get.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; class NativeAdController extends GetxController{   NativeAd? ad;   final adLoaded = false.obs; } 

Ad Helper:

import 'dart:developer'; import 'package:flutter/foundation.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; import '../controllers/controller_native_ads.dart'; class AdHelper{   static Future<void> initAds() async {     await MobileAds.instance.initialize();   }   void loadInterstitialAd({required VoidCallback onComplete}) {     InterstitialAd.load(       adUnitId: 'ca-app-pub-3940256099942544/1033173712',       request: const AdRequest(),       adLoadCallback: InterstitialAdLoadCallback(         // Called when an ad is successfully received.         onAdLoaded: (ad) {           ad.fullScreenContentCallback = FullScreenContentCallback(             onAdDismissedFullScreenContent: (ad) {               onComplete();             },             onAdFailedToShowFullScreenContent: (ad, error) {               log(error.toString());             },             onAdShowedFullScreenContent: (ad) {               log("Full Screen");             },           );           log('This is the $ad loaded.');         },         // Called when an ad request failed.         onAdFailedToLoad: (LoadAdError error) {           log('InterstitialAd failed to load: $error');         },       ),     );   }   static NativeAd loadNativeAd({required NativeAdController nativeAdController}) {     return NativeAd(       adUnitId: 'ca-app-pub-3940256099942544/2247696110',       listener: NativeAdListener(         onAdLoaded: (ad) {           log('$NativeAd loaded.');           nativeAdController.adLoaded.value = true;         },         onAdFailedToLoad: (ad, error) {           log('$NativeAd failed to load: $error');           ad.dispose();         },       ),       request: const AdRequest(),       // Styling       nativeTemplateStyle: NativeTemplateStyle(         templateType: TemplateType.small,       ),     )..load();   } } 

Test Screen:

import 'package:flutter/material.dart'; import '../controllers/controller_native_ads.dart'; class TestScreen extends StatelessWidget{   TestScreen({super.key});   final adController = Get.put(NativeAdController());   @override   Widget build(BuildContext context) {     adController.ad = AdHelper.loadNativeAd(nativeAdController: adController);     return Scaffold(       bottomNavigationBar: adController.ad != null && adController.adLoaded.isTrue           ? SafeArea(               child: SizedBox(                 height: 80,                 child: AdWidget(ad: adController.ad!),               ),             )           : null,     );   } } 

I am using test id provided by official google docs flutter-quick-start

Can anyone explain me why this error occurs?

I am just now getting this message but on my dashboard, everything is active and in my code, I have the correct adunits with a banner ad. I have downloads and they are growing but now I am seeing that ads are not showing up. How do I get this corrected outside of contacting the help desk?

I validated my code with the correct id's.

I am using Admob (react-native-admob-native-ads) package with my react-native(android) app. I have a problem with NativeAd, onAdImpression callback on NatveAd is not called even after the ad is loaded and display on screen. But when i open my app from app-tray onAdImpression called correctly.

Here is my code for NativeAd

<NativeAd ref={nativeAdViewRef} adUnitID={NATIVE_AD_ID} onAdLoaded={()=>console.log('Ad Loaded successfully')} onAdImpression={()=>console.log 'impression count'}/>

Here Ad Loaded successfully printed in concole but impression count not until i open my app from app-tray

As shown in the image admob banner ad is cut off or stretched.

If I use AdSize.banner widget does not take the entire width but shows the ad correctly. If I use full-banner the ad is stretched.

How do I get the banner to fit the full width of the screen and show the content correctly (without cut off or streached)?

class _AdBannerState extends State<AdBanner>{   BannerAd? _inlineAdaptiveAd;   bool _isLoaded = false;   AdSize? _finalSize;   @override   void didChangeDependencies() {     super.didChangeDependencies();     _loadAd();   }   void _loadAd() async {     await _inlineAdaptiveAd?.dispose();     setState(() {       _inlineAdaptiveAd = null;       _isLoaded = false;     });     // Get an inline adaptive size for the current orientation.     AdSize size = AdSize.fullBanner;     _inlineAdaptiveAd = BannerAd(       adUnitId: AdHelper.bannerAdUnitId,       size: size,       request: const AdRequest(),       listener: BannerAdListener(         onAdLoaded: (Ad ad) async {           debugPrint('Inline adaptive banner loaded: ${ad.responseInfo}');           // After the ad is loaded, get the platform ad size and use it to           // update the height of the container. This is necessary because the           // height can change after the ad is loaded.           BannerAd bannerAd = (ad as BannerAd);           _finalSize = await bannerAd.getPlatformAdSize();           // if (size == null) {           //   debugPrint(           //       'Error: getPlatformAdSize() returned null for $bannerAd');           //   return;           // }           setState(() {             _inlineAdaptiveAd = bannerAd;             _isLoaded = true;           });         },         onAdFailedToLoad: (Ad ad, LoadAdError error) {           debugPrint('Inline adaptive banner failedToLoad: $error');           ad.dispose();         },       ),     );     await _inlineAdaptiveAd!.load();   }   @override   Widget build(BuildContext context) {     return (_inlineAdaptiveAd != null && _isLoaded && _finalSize != null)         ? Expanded(             child: SizedBox(                 width: _finalSize!.width.toDouble(),                 height: _finalSize!.height.toDouble(),                 child: AdWidget(                   ad: _inlineAdaptiveAd!,                 )))         : const SizedBox(             width: 0,             height: 0,           );   }   @override   void dispose() {     _inlineAdaptiveAd?.dispose();     super.dispose();   } }