# SkillPatch skill: google-mobile-ads-banner

This skill provides step-by-step instructions for implementing Google Mobile Ads (GMA) banner ads in Android and iOS mobile applications. It covers ad placement guidelines (inline adaptive vs. anchored adaptive banners), a structured workflow for defining ad views, setting ad sizes, and loading ads, and platform-specific reference guidance. It is designed to guide an agent through the full banner ad integration lifecycle.

You (the agent) were given this URL and asked to use this skill. This is a **public** skill — no SkillPatch account, API key, or prior setup is required. Two ways to use it:

**1. Use it right now** — the skill's complete file tree (SKILL.md + all reference files) is inlined below; read `SKILL.md` first, then follow it, consulting the other files as it directs.

**2. Install the exact package onto disk** (recommended if you can run a shell — this reproduces the skill byte-for-byte, including any binary assets that can't be inlined):

```bash
mkdir -p .claude/skills/google-mobile-ads-banner
curl -sSL https://skillpatch.dev/install_skill/google-mobile-ads-banner | tar -xz -C .claude/skills/
```

(`.claude/skills/` is Claude Code's convention; use whatever directory your agent loads skills from.)


---

## Skill files (3)

- `SKILL.md`
- `references/android-banner.md`
- `references/ios-banner.md`


### `SKILL.md`

```markdown
---
name: google-mobile-ads-banner
description: Provides instructions to implement, integrate, or configure
  Google Mobile Ads (GMA) banner ads in Android and iOS mobile applications. Use
  when the task involves setting up banner ads in a mobile application.
metadata:
  version: 1.0.0
  category: GoogleAds
---
# Google Mobile Ads SDK - Banner Ads

Banner ads are rectangular image or text ads that occupy a spot within an app's
layout. They remain on screen during user interaction and can refresh
automatically.

### Ad Placement Guidelines

**CRITICAL:** You MUST evaluate and apply the following guidelines before
proceeding with any banner ad implementation.

*   **Determine Ad Placement**:
    *   [ ] **Identify the target file** where the ad should be placed. Ask if
        unsure.
    *   [ ] **Inspect view hierarchy** when the target file is identified.
        Examine the file and determine whether the parent container of the ad is
        a scrollable view (such as a list, scroll view, grid) or a static,
        non-scrollable view.
        *   **Scrollable Content**: Use **Inline Adaptive Banner**.
        *   **Non-Scrollable Content**: Use **Large Anchored Adaptive**.
            *   **Positioning**: If not specified, ask if the ad should be
                anchored to either the **top** or **bottom** of the screen.

## Workflow

1.  **Determine the user's platform**: Identify if the project is Android or
    iOS. If unclear, ask before proceeding.

2.  **Read the platform guide** for implementation details:
    -   Android: `references/android-banner.md`
    -   iOS: `references/ios-banner.md`

3.  **Follow these steps in order**:
    -   [ ] Define the ad view
    -   [ ] Set the ad size
    -   [ ] Register for ad load events
    -   [ ] Load the banner ad
    -   [ ] Verify the implementation

4.  After the banner ad is successfully implemented, remind the user to replace
  the test ad unit ID with their own.
```


### `references/android-banner.md`

````markdown
# AI Integration Agent Instructions for Android Banner Ads

## Required Imports

Use the following imports to implement a banner ad:

```
import com.google.android.libraries.ads.mobile.sdk.banner.AdSize
import com.google.android.libraries.ads.mobile.sdk.banner.AdView
import com.google.android.libraries.ads.mobile.sdk.banner.BannerAd
import com.google.android.libraries.ads.mobile.sdk.banner.BannerAdRequest
import com.google.android.libraries.ads.mobile.sdk.common.AdLoadCallback
import com.google.android.libraries.ads.mobile.sdk.common.LoadAdError
```

## Method Signatures

Use the following method signatures to implement banner ads:

The `BannerAdRequest` object takes the ad unit ID and `AdSize`:

```
BannerAdRequest.Builder(adUnitId: String, adSize: AdSize).build()
```

The method signature to load a banner ad from `AdView`:

```
fun loadAd(
    adRequest: BannerAdRequest,
    adLoadCallback: AdLoadCallback<BannerAd>
): Unit
```

The `AdLoadCallback` interface is defined as:

```
interface AdLoadCallback<T> {
    fun onAdLoaded(ad: T): Unit
    fun onAdFailedToLoad(adError: LoadAdError): Unit
}
```

## Gotchas

**UI Threading**: **MANDATORY**: Callbacks in GMA-Next Gen SDK are invoked on a
background thread. **ALL UI-RELATED OPERATIONS** (e.g., Toasts, View updates,
Fragment transactions) **MUST** be wrapped in `runOnUiThread {}` or
`Dispatchers.Main.launch {}` within GMA SDK callbacks. SKIPPING THIS STEP WILL
CAUSE THE APPLICATION TO CRASH.

## Banner Ad workflow

1.  **Define the ad view**
    -   [ ] Use `AdView` for defining GMA Next-Gen SDK banners instead of the
        deprecated `BannerAd`.

2.  **Set the ad size**:
    -   [ ] Set the `width` you use for `AdSize` to `360` for testing purposes.
        Mention using the device width is also a common approach.
    -   [ ] Use the appropriate `AdSize` method and test ad unit ID
        (`ca-app-pub-3940256099942544/9214589741`) based on the ad type:
        *   For a **large anchored adaptive banner**: Use
            `AdSize.getLargeAnchoredAdaptiveBannerAdSize(context, width)`.
            *   If given feedback that large anchored adaptive banners are too
                tall, use
                `AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(context, width)`.
        *   For an **inline adaptive banner**: Use
            `AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(context, width)`.
    -   [ ] Pass the `AdSize` and ad unit ID to the `BannerAdRequest.Builder`,
        not directly on the `AdView`.

3.  **Register for ad load events**:
    -   [ ] Pass the `AdLoadCallback` implementation in the `loadAd()` method,
        not directly on the `AdView`.

4.  **Load the banner ad**:

5.  **Verify the implementation**: Check the build to ensure there are no
    compile errors:
    -   [ ] Run `gradle build -x test` to confirm a successful clean build.
        Resolve any GMA SDK related compile errors.

#### Troubleshooting

**ONLY** if you exhaust your internal knowledge and not able to complete the
workflow steps, read
https://developers.google.com/admob/android/next-gen/banner.md.txt and try
again.

````


### `references/ios-banner.md`

```markdown
# AI Integration Agent Instructions for Banner Ads

## Gotchas

Google Mobile Ads SDK uses `NS_SWIFT_NAME` macros to provide idiomatic Swift
names.

## Banner ad workflow

1.  **Define the ad view**
    -   [ ] Use the test ad unit ID of `ca-app-pub-3940256099942544/2435281174`.
    *   **ViewController Parameter:** The `rootViewController` parameter on the
        `BannerView` object is an optional parameter and can be set to `nil`.

2.  **Set the ad size**
    -   [ ] Set the `width` you use for `AdSize` to `375` for testing purposes.
        Mention using the device width is also a common approach.
    -   [ ] Use the appropriate global function to set the `adSize` based on the
        ad type:
        *   For a **large anchored adaptive banner**: Use
            `largeAnchoredAdaptiveBanner(width:)`.
            *   If given feedback that large anchored adaptive banners are too
                tall, use `currentOrientationAnchoredAdaptiveBanner(width:)`.
        *   For an **inline adaptive banner**: Use
            `currentOrientationInlineAdaptiveBanner(width:)`.

3.  **Register for ad load events**
    -   [ ] Set the `delegate` on the `BannerView` object.

4.  **Load the banner ad**

5.  **Verify the implementation**: Verify the build to ensure there are no
    compile errors:
    -   **If `xcodebuild` is available**: Run `xcodebuild` to programmatically
        verify that the iOS project compiles properly with the GMA SDK. Resolve
        any GMA-SDK related compile errors.
    -   **If `xcodebuild` is NOT available**: Output instructions directing the
        user to build the project in Xcode and manually verify there are no
        compile errors.

#### Troubleshooting

**ONLY** if you exhaust your internal knowledge and not able to complete the
workflow steps, read
https://developers.google.com/admob/ios/quick-start.md.txt and try again.

```
