Class: AdDisplayContainer

Constructor

AdDisplayContainer

new AdDisplayContainer(containerElement, opt_videoElement, opt_clickTrackingElement)

This class represents a container for displaying ads. The SDK will automatically create structures inside the containerElement parameter to house video and overlay ads.

When an instance of this class is created, it creates an IFRAME in the containerElement and loads the SDK core. This IFRAME must be preserved in order for the SDK to function properly. Once all ads have been played and the SDK is no longer needed, use the destroy() method to unload the SDK.

The containerElement parameter must be an element that is part of the DOM. It is necessary to correctly position the containerElement in order for the ads to be displayed correctly. It is recommended to position it above the content video player and size it to cover the whole video player. Please refer to the SDK documentation for details about recommended implementations.

Note: It is always necessary to call the initialize() method in code that was directly invoked by a user action (such as a click or tap).

Parameter

containerElement

Element

The element to display the ads in. The element must be inserted into the DOM before creating ima.AdDisplayContainer.

Value must not be null.

opt_videoElement

Optional

HTMLVideoElement

Specifies the alternative video ad playback element. We recommend always passing in your content video player.

Value must not be null.

opt_clickTrackingElement

Optional

Element

Specifies the alternative video ad click element. Leave this null to let the SDK handle clicks. Even if supplied, the SDK will only use the custom click tracking element when non-AdSense/AdX creatives are displayed in environments that do not support UI elements overlaying a video player (e.g., iPhone or pre-4.0 Android). The custom click tracking element should never be rendered over the video player because it can intercept clicks to UI elements that the SDK renders. Also note that the SDK will not modify the visibility of the custom click tracking element. This means that if a custom click tracking element is supplied, it must be properly displayed when the linear ad is played. You can check ima.AdsManager.isCustomClickTrackingUsed when the ima.AdEvent.Type.STARTED event is fired to determine whether or not to display your custom click tracking element. If appropriate for your UI, you should hide the click tracking element when the ima.AdEvent.Type.CONTENT_RESUME_REQUESTED event fires.

Value must not be null.

Methods

destroy

destroy()

Destroys internal state and previously created DOM elements. The IMA SDK will be unloaded and no further calls to any APIs should be made.

initialize

initialize()

Initializes the video playback. On mobile platforms, including iOS and Android browsers, first interaction with video playback is only allowed within a user action (a click or tap) to prevent unexpected bandwidth costs. Call this method as a direct result of a user action before starting the ad playback. This method has no effect on desktop platforms and when custom video playback is used.