This guide explains how to implement more control over clickthrough in your IMA SDK
implementation. "Clickthrough" refers to the process of a user clicking on an ad and getting to
the landing page for that ad. The examples in this guide demonstrates how to configure where that
landing page opens and how to listen for events related to users visiting that page.

## Prerequisites


An iOS application with the IMA SDK implemented.

## Configuring clickthrough

### Changing the link opener

The IMA SDK offers two options for opening ad landing pages---via an in-app browser, or via Safari. By default, the SDK opens pages using Safari. To update the SDK to use an in-app browser, you need to use `IMAAdsRenderingSettings`:

### Swift

```swift
func createAdsRenderingSettings() {
  self.adsRenderingSettings = IMAAdsRenderingSettings();
  self.adsRenderingSettings.linkOpenerDelegate = self;
  self.adsRenderingSettings.linkOpenerPresentingController = self;
}
```

### Objective-C

```objective-c
- (void)createAdsRenderingSettings {
  self.adsRenderingSettings = [[IMAAdsRenderingSettings alloc] init];
  self.adsRenderingSettings.linkOpenerDelegate = self;
  self.adsRenderingSettings.linkOpenerPresentingController = self;
}
```
Once you've configured the `IMAAdsRenderingSettings` instance, you can pass it to the `IMAAdsManager` initialization method:

### Swift

```swift
self.adsManager.initialize(withAdsRenderingSettings: adsRenderingSettings);
```

### Objective-C

```objective-c
[self.adsManager initializeWithAdsRenderingSettings:adsRenderingSettings];
```

### Listening for clickthrough-related events

The IMA SDK provides the `IMALinkOpenerDelegate` to communicate when the user is about to see or has just closed a clickthrough page. To use this delegate, add it to your delegate list in the header, and implement its methods. In the header:

### Swift

```swift
class ViewController: UIViewController, IMALinkOpenerDelegate {
```

### Objective-C

```objective-c
@interface ViewController : UIViewController<IMALinkOpenerDelegate>
```
And in the implementation:

### Swift

```swift
func linkOpenerWillOpen(externalBrowser: NSObject) {
  print("External browser will open.")
}

func linkOpenerWillOpen(inAppLink: NSObject) {
  print("In-app browser will open.")
}

func linkOpenerDidOpen(inAppLink: NSObject) {
  print("In-app browser did open.")
}

func linkOpenerWillClose(inAppLink: NSObject) {
  print("In-app browser will close.")
}

func linkOpenerDidClose(inAppLink: NSObject) {
  print("In-app browser did close.")
}
```

### Objective-C

```objective-c
- (void)linkOpenerWillOpenExternalBrowser:(NSObject *)linkOpener {
  NSLog(@"External browser will open.");
}

- (void)linkOpenerWillOpenInAppBrowser:(NSObject *)linkOpener {
  NSLog(@"In-app browser will open.");
}

- (void)linkOpenerDidOpenInAppBrowser:(NSObject *)linkOpener {
  NSLog(@"In-app browser did open.");
}

- (void)linkOpenerWillCloseInAppBrowser:(NSObject *)linkOpener {
  NSLog(@"In-app browser will close.");
}

- (void)linkOpenerDidCloseInAppBrowser:(NSObject *)linkOpener {
  NSLog(@"In-app browser did close.");
}
```