# Google Dynamic Ad Insertion (DAI) on iOS

Google Dynamic Ad Insertion (DAI) is a Server-Side Ad-Insertion solution offered by Google where THEOplayer offers playback for HLS and DASH streams.

## Prerequisites

To use Google DAI with the THEOplayer iOS SDK, the **THEOplayer GoogleIMA Integration** should be integrated. For instructions on installation, importing and adding the integration, [please refer to this guide](https://docs-preview.optiview.dolby.com/pr-863/theoplayer/how-to-guides/ios/ads/google-ima.md).

## Usage

Define a `GoogleDAITypedSource` and a `GoogleDAIVodConfiguration` to pass to theoplayer's source:

```swift
let daiConfig = GoogleDAIVodConfiguration(videoID: "tears-of-steel", contentSourceID: "2548831", apiKey: "", authToken: nil, streamActivityMonitorID: nil, adTagParameters: nil)
let typedSource = GoogleDAITypedSource(ssai: daiConfig)
theoplayer.source = SourceDescription(source: typedSource)
```

or

```swift
let daiConfig = GoogleDAILiveConfiguration(assetKey: "c-rArva4ShKVIAkNfy6HUQ", apiKey: "", authToken: nil, streamActivityMonitorID: nil, adTagParameters: nil)
let typedSource = GoogleDAITypedSource(ssai: daiConfig)
theoplayer.source = SourceDescription(source: typedSource)
```

And THEOplayer will take care of the rest.

Additional DAI APIs can be found on the `imaIntegration.dai` endpoint.

## Resources

* [Google DAI website](https://developers.google.com/interactive-media-ads)
* [Google DAI iOS Reference](https://developers.google.com/interactive-media-ads/docs/sdks/ios/dai)
