Enable Google DAI playback

Enable ad playback with the Google Dynamic Ad Insertion ad client in an iOS app.

After adding the Google IMA Dynamic Ad Insertion (DAI) SDK to your app and acquiring the required items listed in the Requirements section, you can enable Google DAI ad playback in your iOS app.


Requirements

Property Description
apiKey NSString          Stream request API key
assetKey NSString Stream asset key, used for live streams

You can find this ID in your Google Ad Manager portal. Ask your Google representative for assistance locating this ID.
cmsID NSString Content management system ID of the video, used for video on demand

You can find this ID in your Google Ad Manager portal. Ask your Google representative for assistance locating this ID.
videoID NSString Identifier of the DAI video to be displayed, used for video on demand

You can find this ID in your Google Ad Manager portal. Ask your Google representative for assistance locating this ID.



Specify ad content for a single playlist item

Use the following steps to set up dynamic ad insertion for a single playlist item.

IMPORTANT

For the following reasons, be sure that the video URL (videoURL in our code examples) used to set up the player is consistent with the media content registered with DAI for your videoID or assetKey:

• If the DAI request fails, the video URL will play as a fallback.
• Analytics will be attributed to correct media item.


  1. Define your Google account information.
    • If you are displaying a video on demand, define cmsID and videoID.
    • If you are displaying a live stream, define assetKey.
  2. Instantiate a JWGoogimaDaiConfig object. In our code example, we name this daiConfig.
    • If you are displaying a video on demand, use initWithVideoID:cmsID:.
    • If you are displaying a live stream, use initWithAssetKey:.
  3. If your content is protected, set the apiKey property with your Google DAI API key.
  4. Create a JWAdConfig and set the client to JWAdClientGoogimaDAI.
  5. Assign the JWGoogimaDaiConfig to your JWAdConfig and place it in your JWConfig.


In the code examples below, we have added a JWGoogimaDaiConfig for a video-on-demand playlist item.

@property (nonatomic) JWPlayerController *player;
@property (nonatomic, weak) IBOutlet UIView *playerContainerView;
@end

@implementation ObjCViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Create the DAI Config
    JWGoogimaDaiConfig *daiConfig = [[JWGoogimaDaiConfig alloc] initWithVideoID:VIDEO_ID cmsID:CMS_ID];
    daiConfig.apiKey = API_KEY;

    // Create the Ad Config
    JWAdConfig *adConfig = [JWAdConfig new];
    adConfig.client = JWAdClientGoogimaDAI;
    adConfig.googimaDaiSettings = daiConfig;

    // Initialize the JWConfig and create the JWPlayerController
    // The content URL supplied here will be used if the DAI video fails to load.
    JWConfig *config = [JWConfig configWithContentURL:FALLBACK_CONTENT_URL];
    config.advertising = adConfig;

    self.player = [[JWPlayerController alloc] initWithConfig:config];
}

- (void)viewDidAppear {
    [super viewDidAppear];
    [self.view addSubview:self.player.view];
}
class ViewController: UIViewController {
    @IBOutlet weak var playerContainerView: UIView!
    var player: JWPlayerController?

    override func viewDidLoad() {
        super.viewDidLoad()

        // Create the DAI Config
        let daiConfig = JWGoogimaDaiConfig(videoID: VIDEO_ID, cmsID: CMS_ID)
        daiConfig.apiKey = API_KEY

        // Create the Ad Config
        let adConfig = JWAdConfig()
        adConfig.client = .googimaDAI
        adConfig.googimaDaiSettings = daiConfig

        // Initialize the JWConfig and create the JWPlayerController
        // The content URL supplied here will be used if the DAI video fails to load.
        let config = JWConfig(contentURL: FALLBACK_CONTENT_URL)
        config.advertising = adConfig

        player = JWPlayerController(config: config)
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        playerContainerView.addSubview(player!.view)
    }
}



Specify ad content for multiple playlist items

Use the following steps to associate new DAI ad content with another playlist item. You should follow the steps in the previous section first.

  1. Define your Google account information.
    • If you are displaying a video on demand, define create new cmsID and videoID properties.
    • If you are displaying a live stream, define a new assetKey property.
  2. For a specific JWPlaylistItem, create a JWGoogimaDaiConfig object.
    • If you are displaying a video on demand, use initWithVideoID:cmsID:.
    • If you are displaying a live stream, use initWithAssetKey:.
  3. If your content is protected, set the apiKey property with your Google DAI API key.
  4. Assign the JWGoogimaDaiConfig to the JWPlaylistItem.
  5. Repeat steps 1-4 to associate DAI ad content with another playlist item.


@property (nonatomic) JWPlayerController *player;
@property (nonatomic, weak) IBOutlet UIView *playerContainerView;
@end

@implementation ObjCViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Create the playlist items, and give them their own unique DAI configs
    JWPlaylistItem *item = [JWPlaylistItem new];
    item.file = FALLBACK_CONTENT_URL;
    item.googimaDaiSettings = [[JWGoogimaDaiConfig alloc] initWithVideoID:VIDEO_ID cmsID:CMS_ID];

    JWPlaylistItem *item2 = [JWPlaylistItem new];
    item2.file = FALLBACK_CONTENT2_URL;
    item2.googimaDaiSettings = [[JWGoogimaDaiConfig alloc] initWithVideoID:VIDEO2_ID cmsID:CMS2_ID];

    // Create the default DAI Config
    // This config is used if a playlist item does not specify a DAI config.
    JWGoogimaDaiConfig *daiConfig = [[JWGoogimaDaiConfig alloc] initWithVideoID:DEFAULT_VIDEO_ID cmsID:DEFAULT_CMS_ID];
    daiConfig.apiKey = API_KEY;

    // Create the Ad Config
    JWAdConfig *adConfig = [JWAdConfig new];
    adConfig.client = JWAdClientGoogimaDAI;
    adConfig.googimaDaiSettings = daiConfig;

    // Initialize the JWConfig and create the JWPlayerController
    // The content URL supplied here will be used if the DAI video fails to load.
    JWConfig *config = [JWConfig configWithContentURL:DEFAULT_FALLBACK_CONTENT_URL];
    config.advertising = adConfig;
    config.playlist = @[item, item2];

    self.player = [[JWPlayerController alloc] initWithConfig:config];
}

- (void)viewDidAppear {
    [super viewDidAppear];
    [self.view addSubview:self.player.view];
}

class ViewController: UIViewController {
    @IBOutlet weak var playerContainerView: UIView!
    var player: JWPlayerController?

    override func viewDidLoad() {
        super.viewDidLoad()

        // Create the playlist items, and give them their own unique DAI configs
        let item = JWPlaylistItem()
        item.file = FALLBACK_CONTENT_URL
        item.googimaDaiSettings = JWGoogimaDaiConfig(videoID: VIDEO_ID, cmsID: CMS_ID)

        let item2 = JWPlaylistItem()
        item2.file = FALLBACK_CONTENT2_URL
        item2.googimaDaiSettings = JWGoogimaDaiConfig(videoID: VIDEO2_ID, cmsID: CMS2_ID)

        // Create the default DAI Config
        // This config is used if a playlist item does not specify a DAI config.
        let daiConfig = JWGoogimaDaiConfig(videoID: DEFAULT_VIDEO_ID, cmsID: DEFAULT_CMS_ID)
        daiConfig.apiKey = API_KEY

        // Create the Ad Config
        let adConfig = JWAdConfig()
        adConfig.client = .googimaDAI
        adConfig.googimaDaiSettings = daiConfig

        // Initialize the JWConfig and create the JWPlayerController
        // The content URL supplied here will be used if the DAI video fails to load.
        let config = JWConfig(contentURL: DEFAULT_FALLBACK_CONTENT_URL)
        config.advertising = adConfig
        config.playlist = [item, item2]

        player = JWPlayerController(config: config)
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        playerContainerView.addSubview(player!.view)
    }
}

Updated 7 days ago


Enable Google DAI playback


Enable ad playback with the Google Dynamic Ad Insertion ad client in an iOS app.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.