### Install Dependencies Source: https://github.com/invertase/react-native-google-mobile-ads/blob/main/CONTRIBUTING.md Install the necessary project dependencies using Yarn. ```bash yarn ``` -------------------------------- ### Install react-native-google-mobile-ads (Bare React Native) Source: https://github.com/invertase/react-native-google-mobile-ads/blob/main/docs/index.mdx Install the admob module for bare React Native projects using npm. ```bash # Install the admob module npm install react-native-google-mobile-ads ``` -------------------------------- ### Install react-native-google-mobile-ads (Expo) Source: https://github.com/invertase/react-native-google-mobile-ads/blob/main/docs/index.mdx Install the admob module and config plugin for Expo projects using npx. ```bash # Install the admob module and config plugin npx expo install react-native-google-mobile-ads ``` -------------------------------- ### Example Server-Side Verification Callback Source: https://github.com/invertase/react-native-google-mobile-ads/blob/main/docs/displaying-ads.mdx This is an example of how AdMob might call your server with the `userId` and `customData` parameters included in the ad request. Developers must verify these incoming requests. ```http [14/Aug/2020 12:51:43] "GET /views/admob-ssv/?ad_network=...&ad_unit=...&custom_data=my-custom-data&reward_amount=1&reward_item=test_reward_item×tamp=1597377102267&transaction_id=148cc85...&user_id=9999&signature=MEUCIQCQSi3cQ2PlxlEAkpN...&key_id=3335... HTTP/1.1" 200 0 ``` -------------------------------- ### Set User Consent in JavaScript Source: https://github.com/invertase/react-native-google-mobile-ads/blob/main/docs/mediation.mdx After installing the module and rebuilding your client, you can call native methods from JavaScript. This example shows how to set user consent. ```javascript import { setHasUserConsent } from 'google-mobile-ads-mediation-applovin' // Call your custom native method. setHasUserConsent(true) ``` -------------------------------- ### Add Third-Party Pod Dependency Source: https://github.com/invertase/react-native-google-mobile-ads/blob/main/docs/mediation.mdx To integrate a mediation network, add its specific pod dependency to your Podfile. Ensure you run `pod install` afterwards. ```ruby s.dependency 'GoogleMobileAdsMediationAppLovin' ``` -------------------------------- ### Install Expo Build Properties Plugin Source: https://github.com/invertase/react-native-google-mobile-ads/blob/main/docs/mediation.mdx Install the `expo-build-properties` plugin using npm or yarn if you haven't already. This plugin is necessary for managing native dependencies within Expo projects. ```bash npx expo install expo-build-properties ``` -------------------------------- ### Rebuild Project (Expo without EAS) Source: https://github.com/invertase/react-native-google-mobile-ads/blob/main/docs/index.mdx Commands to rebuild your project's native code and install the new build on your device if you are using Expo without EAS. ```bash # For iOS npx expo prebuild npx expo run:ios # For Android npx expo prebuild npx expo run:android ``` -------------------------------- ### Load and Display Interstitial Ads with Event Listeners Source: https://github.com/invertase/react-native-google-mobile-ads/blob/main/docs/displaying-ads.mdx Load an interstitial ad and manage its lifecycle using event listeners for LOADED, OPENED, and CLOSED events. This example shows how to conditionally render a button to show the ad once it's loaded. ```jsx import React, { useEffect, useState } from 'react'; import { Button, Platform, StatusBar } from 'react-native'; import { InterstitialAd, AdEventType, TestIds } from 'react-native-google-mobile-ads'; const adUnitId = __DEV__ ? TestIds.INTERSTITIAL : 'ca-app-pub-xxxxxxxxxxxxx/yyyyyyyyyyyyyy'; const interstitial = InterstitialAd.createForAdRequest(adUnitId, { keywords: ['fashion', 'clothing'], }); function App() { const [loaded, setLoaded] = useState(false); useEffect(() => { const unsubscribeLoaded = interstitial.addAdEventListener(AdEventType.LOADED, () => { setLoaded(true); }); const unsubscribeOpened = interstitial.addAdEventListener(AdEventType.OPENED, () => { if (Platform.OS === 'ios') { // Prevent the close button from being unreachable by hiding the status bar on iOS StatusBar.setHidden(true); } }); const unsubscribeClosed = interstitial.addAdEventListener(AdEventType.CLOSED, () => { if (Platform.OS === 'ios') { StatusBar.setHidden(false); } }); // Start loading the interstitial straight away interstitial.load(); // Unsubscribe from events on unmount return () => { unsubscribeLoaded(); unsubscribeOpened(); unsubscribeClosed(); }; }, []); // No advert ready to show yet if (!loaded) { return null; } return (