React Native Admob Google Mobile Ads not working?

Viewed 107

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-3940256099942544/1033173712';

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>
  );
}
0 Answers
Related