This guide shows how to debug ad serving using in-app preview and the
Delivery Inspector.

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

The [Delivery
Inspector](https://support.google.com/admanager/answer/7449957)
gives information on which ads were delivered. When unexpected ads deliver,
use the Delivery Inspector to find out why.

## Prerequisites

- Version 7.13.1 or higher of Google Mobile Ads SDK
- Access to a Google Ad Manager account
- Complete [Get Started](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/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 function
below in your app, and trigger it based on a user action:

### Swift

```swift
@IBAction func openDebugOptions(sender: AnyObject) {
  // TODO: Replace YOUR_AD_UNIT_ID with your own ad unit ID.
  let debugOptionsViewController = DebugOptionsViewController(adUnitID: "YOUR_AD_UNIT_ID")
  self.present(debugOptionsViewController, animated: true, completion: nil)
}
```

### Objective-C

```objective-c
- (IBAction)openDebugOptions:(id)sender {
  // TODO: Replace YOUR_AD_UNIT_ID with your own ad unit ID.
  GADDebugOptionsViewController *debugOptionsViewController =
      [GADDebugOptionsViewController debugOptionsViewControllerWithAdUnitID:@"YOUR_AD_UNIT_ID"];
  [self presentViewController:debugOptionsViewController animated:YES completion:nil];
}
```

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

> [!NOTE]
> **Note:** Another way to open the menu is to do a swipe gesture on the creative, but it doesn't work for all ad formats such as native ads, and you must be careful to not click the ad when attempting to swipe. Calling the method above is much more robust.

## Get notified when the debug menu closes

When opening the debug options menu programmatically, you may choose
to implement `GADDebugOptionsViewControllerDelegate` to be notified
when the view controller is dismissed. To do this, make your class
conform to the delegate:

### Swift

```swift
import GoogleMobileAds
 
class ViewController: UIViewController, GADDebugOptionsViewControllerDelegate {
}
```

### Objective-C

```objective-c
@import GoogleMobileAds;
 
@interface ViewController : UIViewController <GADDebugOptionsViewControllerDelegate> {
}
 
@end
```

Set the delegate on your `GADDebugOptionsViewController`:

### Swift

```swift
@IBAction func openDebugOptions(sender: AnyObject) {
  let debugOptionsViewController = GADDebugOptionsViewController(adUnitID: "YOUR_AD_UNIT_ID")
  debugOptionsViewController.delegate = self
  self.present(debugOptionsViewController, animated: true, completion: nil)
}
```

### Objective-C

```objective-c
- (IBAction)openDebugOptions:(id)sender {
  GADDebugOptionsViewController *debugOptionsViewController =
      [GADDebugOptionsViewController debugOptionsViewControllerWithAdUnitID:@"YOUR_AD_UNIT_ID"];
  debugOptionsViewController.delegate = self;
  [self presentViewController:debugOptionsViewController animated:YES completion:nil];
}
```

Finally, implement the delegate:

### Swift

```swift
func debugOptionsViewControllerDidDismiss(controller: GADDebugOptionsViewController) {
  print("Debug options view controller dismissed.")
}
```

### Objective-C

```objective-c
- (void)debugOptionsViewControllerDidDismiss:(GADDebugOptionsViewController *)controller {
  NSLog(@"Debug options view controller dismissed.");
}
```

## Link your device

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

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

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

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

> [!NOTE]
> **Note:** `SFSafariViewController` is opened on iOS 9 and above, while `Safari` is opened on iOS 8 and below.

You have successfully linked your device! At this point, you can
see your device linked in the [Ad Manager front-end](https://www.google.com/dfp).
You can also [allow others to access your
devices](https://support.google.com/admanager/answer/7160685#access).

## 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 to see the creative.

After pushing a creative from the front-end, trigger the debug
options menu on your device again, and select **Creative Preview**
again. This step lets the SDK check Ad Manager again 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 wish to preview to see your creative!

## Delivery Inspector

Follow the [Begin app troubleshooting](https://support.google.com/admanager/answer/7180401)
steps to troubleshoot your app. If you complete the steps successfully, the
request will show up in the Ad Manager frontend and you can view more info about the ad
that served.

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