> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shipmobilefast.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AdMob Integration

> Implement Google AdMob in your Expo app

<Frame>
  <img src="https://mintcdn.com/shipmobilefast-51a499dc/4ztR-scAO2Zjz6Y6/images/features/admob.png?fit=max&auto=format&n=4ztR-scAO2Zjz6Y6&q=85&s=5dca8f18f1a42fb02467983e1dc48ce5" alt="AdMob Home" className="w-full h-full rounded-lg" width="700" height="320" data-path="images/features/admob.png" />
</Frame>

## How to integrate AdMob in our React Native Expo App?

1. Firstly, you need to make sure to have an AdMob account. If you don't have one, you can create it [here](https://apps.admob.com/v2/home).

2. Start the setup by following the steps below.

### Setup

<Steps>
  <Step>
    First, you need to install the `react-native-google-mobile-ads` package.

    ```bash theme={null}
    npm install react-native-google-mobile-ads
    ```
  </Step>

  <Step>
    Go to the [admob.google.com](https://admob.google.com/v2/home) and create your account.

    <Frame>
      <img src="https://mintcdn.com/shipmobilefast-51a499dc/0OITnrSFpxUQjTf4/images/setup/admob/admob0.png?fit=max&auto=format&n=0OITnrSFpxUQjTf4&q=85&s=72f1afde58b4e7f2277fc81ade2f39a1" alt="AdMob Home" className="w-full h-auto max-w-lg rounded-lg" width="570" height="720" data-path="images/setup/admob/admob0.png" />
    </Frame>
  </Step>

  <Step>
    You need to create the same app for iOS and Android.

    <Frame>
      <img src="https://mintcdn.com/shipmobilefast-51a499dc/0OITnrSFpxUQjTf4/images/setup/admob/admob1.png?fit=max&auto=format&n=0OITnrSFpxUQjTf4&q=85&s=7dbc696886d502970078ff35d5a71ee3" alt="AdMob App ID" className="w-full h-auto max-w-lg rounded-lg" width="1026" height="480" data-path="images/setup/admob/admob1.png" />
    </Frame>
  </Step>

  <Step>
    Then pick a name for your app:

    <Frame>
      <img src="https://mintcdn.com/shipmobilefast-51a499dc/0OITnrSFpxUQjTf4/images/setup/admob/admob2.png?fit=max&auto=format&n=0OITnrSFpxUQjTf4&q=85&s=72a76445b4a4df2af7e1d55ad33772e4" alt="AdMob App Name" className="w-full h-auto max-w-lg rounded-lg" width="611" height="353" data-path="images/setup/admob/admob2.png" />
    </Frame>
  </Step>

  <Step>
    Now you need to create an ad unit for each type of ad.

    <Frame>
      <img src="https://mintcdn.com/shipmobilefast-51a499dc/0OITnrSFpxUQjTf4/images/setup/admob/admob3.png?fit=max&auto=format&n=0OITnrSFpxUQjTf4&q=85&s=55b943632b80494147b45a57e0d03d8d" alt="AdMob Ad Unit" className="w-full h-auto max-w-lg rounded-lg" width="947" height="490" data-path="images/setup/admob/admob3.png" />
    </Frame>
  </Step>

  <Step>
    You can choose a 4 category:

    <Warning>
      `Banner`, `Interstitial`, `Rewarded` and `App Open`.
    </Warning>

    <Frame>
      <img src="https://mintcdn.com/shipmobilefast-51a499dc/0OITnrSFpxUQjTf4/images/setup/admob/admob4.png?fit=max&auto=format&n=0OITnrSFpxUQjTf4&q=85&s=1508f306f74378d3a2c3f84c7a02a968" alt="AdMob App Category" className="w-full h-auto max-w-lg rounded-lg" width="932" height="955" data-path="images/setup/admob/admob4.png" />
    </Frame>
  </Step>

  <Step>
    Now you need to get your app ID for each platform.

    <Frame>
      <img src="https://mintcdn.com/shipmobilefast-51a499dc/0OITnrSFpxUQjTf4/images/setup/admob/admob5.png?fit=max&auto=format&n=0OITnrSFpxUQjTf4&q=85&s=5d1380587290f6bbb2facb3c83d7c4bc" alt="AdMob App ID" className="w-full h-auto max-w-lg rounded-lg" width="1066" height="773" data-path="images/setup/admob/admob5.png" />
    </Frame>
  </Step>

  <Step>
    <Check>
      Ad Unit Successfully Created.
    </Check>

    <Frame>
      <img src="https://mintcdn.com/shipmobilefast-51a499dc/0OITnrSFpxUQjTf4/images/setup/admob/admob6.png?fit=max&auto=format&n=0OITnrSFpxUQjTf4&q=85&s=3420a5858979c12e7467a1208c07841e" alt="AdMob Ad Unit ID" className="w-full h-auto max-w-lg rounded-lg" width="714" height="589" data-path="images/setup/admob/admob6.png" />
    </Frame>
  </Step>

  <Step>
    Now, listen carefully to the following steps.

    <Warning>
      Open `app.json` file and add the following code down below:
    </Warning>

    ```json theme={null}
    plugins: [
        ...
            [
            "react-native-google-mobile-ads",
            {
              "androidAppId": "ca-app-pub-<your-android-app-id>",
              "iosAppId": "ca-app-pub-<your-ios-app-id>"
            }
          ],
        ...
    ]
    ```
  </Step>

  <Step>
    <Warning>
      Go to `services/admob/admobConfig.ts` file and change the values with your own.
    </Warning>

    <Warning>
      If you are using the Gluestack branch go to the `services/admob/admobInitialize.ts` file and change the values to your own.
    </Warning>

    <Warning>
      Go to `services/admob/admobService.ts` file and uncomment the code.
    </Warning>
  </Step>

  <Step>
    Now , go to `app/_layout.tsx` file and add the following code down below:

    ```tsx app/_layout.tsx {1,2,5,9,16,19} theme={null}
    import { initializeAdmobService } from '@/services/admob';
    import { useAdmob } from '@/hooks/useAdmob';

    function App(){
        const { admobState, initializeAdmobService } = useAdmob();
        useEffect(() => {
            ...
            // Ad this line: 👇
            initializeAdmobService();
            ...
            getUserTrackingPermission();
            ...
        }, []);
        // Find this useEffect and change this line: 👇
        useEffect(() => {
            if (loaded && initialized && admobState.admobReady.isLoaded) {
                SplashScreen.hideAsync();
            }
    }, [loaded, initialized, admobState.admobReady.isLoaded]); 
    ```
  </Step>

  <Step>
    <Info>
      Now you can use Ads in where you want in your app. For example:
    </Info>

    ```tsx app/screens/profile.tsx {1,3,5} theme={null}
    import { BannerAd } from 'react-native-google-mobile-ads';
    // If you want to use other Ad types, use this import: 👇
    import { useAdmob } from '@/hooks/useAdmob';
    // If you want to use Banner AD, use this import: 👇
    import { admobConfig } from '@/services/admob/admobConfig';

    const ProfileScreen = () => {
        const { showInterstitial, showRewarded, showAppOpen } = useAdmob();
        useEffect(() => {
            // Show Interstitial Ad
            showInterstitial();
            // or  
            showRewarded();
            // or
            showAppOpen();
        }, []);
        return (
            <>
                <BannerAd
                    unitId={admobConfig.bannerAdUnitId}
                    size={BannerAdSize.ANCHORED_ADAPTIVE_BANNER}
                />
                <ProfileComponent .../>
            </>
        );
    };
    ```
  </Step>

  <Step>
    <Info>
      Don't forget to build your app again.
    </Info>

    <Warning>
      `npx expo prebuild` or `eas build --profile development --platform <platform>`
    </Warning>
  </Step>
</Steps>
