This guide shows how to debug ad serving using in-app preview and the Ad Manager
delivery tools.

[In-app preview](https://support.google.com/admanager/answer/7160685) lets you inspect
your own creatives rendered within your mobile app. This preview is especially
useful if you have creatives that interact with the app, have unique behavior,
or rely on the app for some rendering (including native creatives and MRAID).

The [Ad Manager delivery tools](https://support.google.com/admanager/answer/7449957)
give information on which ads were delivered; so when unexpected ads deliver,
use the delivery tools to find out why.

## Prerequisites

<br />

- Access to a Google Ad Manager account.
- Complete the [Get started guide](https://developers.google.com/ad-manager/mobile-ads-sdk/android/next-gen/quick-start.md.txt).

## Prepare your app

Debugging requires interaction with the SDK's debug options menu. The
recommended way to open the menu is to include the following function in your
app, and trigger it based on a user action:

### Kotlin

```kotlin
// Opens a debug menu. Call this method based on a user action.
// Pass any Ad Manager ad unit ID associated with the app that you want to debug.
MobileAds.openDebugMenu(activity, "AD_UNIT_ID")
```

### Java

```java
// Opens a debug menu. Call this method based on a user action.
// Pass any Ad Manager ad unit ID associated with the app that you want to debug.
MobileAds.openDebugMenu(activity, "AD_UNIT_ID");
```

> [!IMPORTANT]
> **Key Point:** `MobileAds.initialize()` must be called before `MobileAds.openDebugMenu()`.

Any valid ad unit from your Ad Manager account is sufficient to open the debug
options menu.

Another way to open the menu is to do a [long two-finger
press](https://support.google.com/admanager/answer/7180401) on the creative, but this
doesn't work for all ad formats, such as native ads, and you must be careful not
to click the ad when attempting to swipe. Calling the previous method is much
more robust.

## Link your device

After adding the capability to open the debug options menu, run your app and
trigger the function. The following menu opens:

![](https://developers.google.com/static/ad-manager/mobile-ads-sdk/images/android-debug-options.png)

Select **Creative Preview** to link your device. A browser opens and
automatically navigates you to a browser to sign in to Ad Manager. After signing
in, name your device to register it with your Ad Manager account. Then click
**Verify**.

![](https://developers.google.com/static/ad-manager/mobile-ads-sdk/images/android-verify-device-link.png)

At this point, you can verify that your device has been linked in the [Ad
Manager UI](https://admanager.google.com/home/). You can also [let others access your
devices](https://support.google.com/admanager/answer/7160685#make-public).

## In-app preview

Follow the steps to [push a creative to your linked
device](https://support.google.com/admanager/answer/7160685#push). Make sure that the
pushed creative is part of an active line item targeted to the ad slot where you
want the creative.

After pushing a creative from the UI, trigger the debug options menu on your
device again and select **Creative Preview** once more. This step lets the SDK
check Ad Manager to verify that the device linking was successful and to get
some information about which creative you pushed. If device linking was
previously successful, the debug menu closes immediately. If it was
unsuccessful, you're prompted to link your account again.

Finally, load an ad for the slot you want to preview to see your creative.

## Delivery tools

Follow the steps in [Inspect delivery in Ad
Manager](https://support.google.com/admanager/answer/7180401#inspect-in-ui) to
troubleshoot your ad delivery. If you've completed the steps successfully, the
request shows up in the Ad Manager UI and you can view more info about the ad
that served.

![](https://developers.google.com/static/ad-manager/mobile-ads-sdk/images/troubleshoot.png)