All skills
google avatar

/ima-dai-sdk

@8f57a0d
by googlegoogle/skills21k stars
1,698

Integrates the Google Interactive Media Ads (IMA) Dynamic Ad Insertion (DAI) SDK into websites, web apps, mobile apps, or TV apps. Use when: - A video player needs to load and play HLS or DASH streams in web apps, Android apps, iOS apps, tvOS apps, Cast (CAF) receivers, or Roku channels. - The app needs to make use of a Google DAI livestream event asset key, or content source CMS ID, video ID for video on demand. Don't use this skill to load and play a VAST or VMAP URL.

Use this Skill: https://skilld.dev/gh/google/skills/ima-dai-sdk

This session only. Nothing lands on disk.

referencesios-IMAStreamRequest-guide.md

≈1.5k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Google IMA DAI SDK iOS/tvOS - IMAStreamRequest Guide

For Google full-service DAI, use IMALiveStreamRequest to request a livestream and IMAVODStreamRequest to request a VOD stream.

Table of Contents

Dependencies

Use Swift Package Manager

For iOS, add this package:

https://github.com/googleads/swift-package-manager-google-interactive-media-ads-ios

For tvOS, add this package:

https://github.com/googleads/swift-package-manager-google-interactive-media-ads-tvos

SDK Initialization

Initialize the IMAAdsLoader early, such as in ViewController.viewDidLoad event.

import GoogleInteractiveMediaAds

class ViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    adsLoader = IMAAdsLoader(settings: IMASettings())
  }
}

UI Setup & Video Player

Create IMAAdDisplayContainer object using the videoView containing the AVPlayer. Ad UI components will be rendered within the videoView over the player.

adDisplayContainer = IMAAdDisplayContainer(adContainer: videoView)

Create IMAAVPlayerVideoDisplay with the AVPlayer instance so that the IMA DAI SDK can listen to the video player for timed metadata during ad breaks.

imaVideoDisplay = IMAAVPlayerVideoDisplay(avPlayer: videoPlayer)

Make stream requests

Reuse the same AdsLoader instance to make stream requests.

Request a livestream

Instantiate IMALiveStreamRequest with the asset key and network code:

let request = IMALiveStreamRequest(
  assetKey: <ASSET_KEY_PLACEHOLDER>,
  networkCode: <NETWORK_CODE_PLACEHOLDER>,
  adDisplayContainer: adDisplayContainer,
  videoDisplay: imaVideoDisplay,
  userContext: nil)
adsLoader.requestStream(with: request)

Provide the following parameters:

  • <NETWORK_CODE_PLACEHOLDER>: The Google Ad Manager network code.
  • <ASSET_KEY_PLACEHOLDER>: The livestream asset key configured in Google Ad Manager.

Request a VOD stream

Instantiate IMAVODStreamRequest with content source ID (CMS ID) and video ID:

let request = IMAVODStreamRequest(
  contentSourceID: <CONTENT_SOURCE_ID_PLACEHOLDER>,
  videoID: <VIDEO_ID_PLACEHOLDER>,
  networkCode: <NETWORK_CODE_PLACEHOLDER>,
  adDisplayContainer: adDisplayContainer,
  videoDisplay: imaVideoDisplay,
  userContext: nil)
adsLoader.requestStream(with: request)

Provide the following parameters:

  • <NETWORK_CODE_PLACEHOLDER>: The Google Ad Manager network code.
  • <CONTENT_SOURCE_ID_PLACEHOLDER>: The CMS ID in Google Ad Manager.
  • <VIDEO_ID_PLACEHOLDER>: The video ID in the CMS.

For testing purposes, use values of DAI sample streams from https://developers.google.com/ad-manager/dynamic-ad-insertion/streams.md.txt?utm_source=agent-skills&utm_medium=content&utm_campaign=adr-ss-ai&utm_content=ima-dai-sdk

Listen to Stream Load Events

Implement IMAAdsLoaderDelegate to handle stream initialization or failure:

func adsLoader(_ loader: IMAAdsLoader, adsLoadedWith adsLoadedData: IMAAdsLoadedData) {
  print("DAI session ID: \(adsLoadedData.streamManager!.streamId!)")
  adsLoadedData.streamManager.initialize(with: nil)
}

func adsLoader(_ loader: IMAAdsLoader, failedWith adErrorData: IMAAdLoadingErrorData) {
  print("Failed to load DAI stream. Error: \(adErrorData.adError.message ?? "")")
  playBackupStream()
}

Listen to Stream and Ad Events

Implement IMAStreamManagerDelegate to receive stream events, ad lifecycle events, and errors:

func streamManager(_ streamManager: IMAStreamManager, didReceive event: IMAAdEvent) {
  print("Ad event: \(event.typeString)")
  switch event.type {
  case IMAAdEventType.STARTED:
    if let ad = event.ad {
      let extendedAdPodInfo = String(
        format: "Showing ad %zd/%zd, bumper: %@, title: %@, "
          +   "description: %@, contentType:%@, pod index: %zd, "
          +   "time offset: %lf, max duration: %lf.",
        ad.adPodInfo.adPosition,
        ad.adPodInfo.totalAds,
        ad.adPodInfo.isBumper ? "YES" : "NO",
        ad.adTitle,
        ad.adDescription,
        ad.contentType,
        ad.adPodInfo.podIndex,
        ad.adPodInfo.timeOffset,
        ad.adPodInfo.maxDuration)
      print("\(extendedAdPodInfo)")
    }
    break
  case IMAAdEventType.AD_BREAK_STARTED:
    print("Ad break started.")
    break
  case IMAAdEventType.AD_BREAK_ENDED:
    print("Ad break ended.")
    break
  case IMAAdEventType.AD_PERIOD_STARTED:
    print("Ad period started.")
    break
  case IMAAdEventType.AD_PERIOD_ENDED:
    print("Ad period ended.")
    break
  default:
    break
  }
}

func streamManager(_ streamManager: IMAStreamManager, didReceive error: IMAAdError) {
  print("Failed to play DAI stream. Error: \(error.message ?? "Unknown Error")")
  playBackupStream()
}

Reference Implementation

BasicExample:

Source: SKILL.md on GitHub

1 warning1mo3 checks · Risk SAFE
  • Gen Agent Trust Hub1mo

    This skill provides documentation and integration guides for the Google Interactive Media Ads (IMA) Dynamic Ad Insertion (DAI) SDK across multiple platforms. The external dependencies and code references originate from official Google infrastructure and repositories, aligning with standard development practices for these services. No security issues were identified.

  • Socket1mo

    No alerts

  • Snyk1mo

    Risk: MEDIUM · 2 issues

Signed by skilld at 8f57a0d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 2 months ago
metadata
{
  "author": "Google LLC",
  "version": "1.0.0",
  "category": "GoogleAds"
}

README badge

README badge for google/skills/ima-dai-sdk