2

I copied the exact code from documentation and tried to check in my application but it's not working, here I just removed the button because I don't need the button.

Ads should appear automatically after users visit the page. Now when I run the app the ads do not appear.

What should I need to do? Where should I placed the- interstitial.show(); inside the code

import React, { useEffect, useState } from 'react';
import { Button } from 'react-native';
import { InterstitialAd, AdEventType, TestIds } from 'react-native-google-mobile-ads';

const adUnitId = __DEV__ ? TestIds.INTERSTITIAL : 'ca-app-pub-xxxxxxxxxxxxxxxx/yyyyyyyyyy';

const interstitial = InterstitialAd.createForAdRequest(adUnitId, {
  requestNonPersonalizedAdsOnly: true,
  keywords: ['fashion', 'clothing'],
});

function App() {
  const [loaded, setLoaded] = useState(false);

  useEffect(() => {
    const unsubscribe = interstitial.addAdEventListener(AdEventType.LOADED, () => {
      setLoaded(true);
    });

    // Start loading the interstitial straight away
    interstitial.load();

    // Unsubscribe from events on unmount
    return unsubscribe;
  }, []);

 
  if (!loaded) {
    return null;
  }

  return (
    
    <View>
<Text>Hello World</Text>
</View>
  );
}
Community
  • 1
  • 1
  • Same here. I have implement ads but only on debugging mode ads can show, on production mode, on playstore, and tested real devices not working. Only banner ads work. Rewarded ads, interstitial ads, etc. Not working in production, any updates? – Tofa Maulana Irvan Oct 19 '22 at 14:28
  • Hi Tofa, Please check the below link it may solve your problem, I got the same problem but when I used version 8.1.2 then it's worked fine for me. Thanks to @mike-hardy https://stackoverflow.com/questions/74010695/admob-react-native-google-mobile-ads-not-working-on-real-device-rewarded-ads-wo – Rahul Aadam Oct 20 '22 at 15:32
  • Not a solution but worth mentioning that I was having the exact same issue with it testing fine but not working in production. This is hard to debug. I eventually realized that the `__DEV__ ? TestIds.INTERSTITIAL` was why it worked in testing but in production my actual ID was for the wrong ad unit. – Cory Feb 24 '23 at 18:42
  • did anyone solve it? I am facing the same error my ad works fine last week but now ad not show in production but on the test ID it works fine – Ibad Ur Rehman Jun 08 '23 at 16:10

0 Answers0