0.0.10 β€’ Published 5 months ago

@dailymotion/ad-sdk-web v0.0.10

Weekly downloads
-
License
-
Repository
github
Last release
5 months ago

Ad SDK Web

A lightweight web wrapper for Dailymotion's Ad SDK – load, manage, and interact with video ads easily in modern web players.

npm

βš™οΈ Required HTML & CSS Setup for the Player Container

To use our Ad SDK Web, you must define an HTML player container element styled correctly to hold both your content video tag and Ad SDK playback elements.

CSS styles to add

.videoPlayerContainer {
  position: relative;
  width: auto;
  height: 100%;
  aspect-ratio: 16 / 9;
}

.videoPlayerContainer is the wrapper where the SDK mounts the ad container and your video element.

The container is positioned relative to allow absolute positioning of ad overlays if needed.

The aspect ratio keeps the player consistent across screen sizes.

Example implementation reference

πŸ‘‰ Check out an example implementation here: https://dailymotion.github.io/ad-sdk-sample/

πŸ“˜ Public API Documentation

async initialize(playerContainer: HTMLElement): Promise<void>

Loads the external ad SDK script and creates internal DOM elements for ad playback. This method should be called before any other function of the SDK and once per page.

Parameters:

  • playerContainer: HTMLElement The DOM element where the ad container will be mounted.

Throws: If the container is missing or the script fails to load.


loadAdsSequence(appState: AppState): void

Loads ads sequence with the provided contextual information.

After this call, the ad SDK will listen to the progress of the video and will trigger an AD_BREAK_START event whenever an ad break is about to begin. When this event occurs, the video player is expected to pause playback. Playback should resume only after the corresponding AD_BREAK_END event is received.

A preroll ad may start automatically after this call. If no preroll is available, the SDK will send an AD_BREAK_END event to indicate that content playback can proceed.

This method should be called once per video, before starting the main content.

Parameters:

  • appState: AppState A structured object providing ad targeting and playback environment data.
    πŸ‘‰ See full structure below or jump to AppState

playAd(): void

Request the SDK to start the ad playback.

Throws:
If the SDK is not initialized.


pauseAd(): void

Request the SDK to pause the ad.

Throws:
If the SDK is not initialized.


skipAd(): void

Request the SDK to skip the currently playing ad.

Throws:
If the SDK is not initialized.


getAdDetails(): AdDetails

Returns detailed information about the currently playing ad.

Returns:
An AdDetails object containing properties such as position, ad duration, and other metadata.

πŸ‘‰ See full structure below or jump to AdDetails


on(event: AdEvents, callback: () => void): void

Subscribes to a specific Ad SDK event.

Parameters:

  • event: AdEvents
    The event name to listen for.
    πŸ‘‰ See AdEvents for available event names.

  • callback: () => void
    The callback function to execute when the event occurs.

Throws:
If the Ad SDK is not initialized.


off(event: AdEvents, callback: () => void): void

Unsubscribes from a specific Ad SDK event.

Parameters:

  • event: AdEvents
    The event name to stop listening for.
    πŸ‘‰ See AdEvents for available event names.

  • callback: () => void
    The callback function to remove.

Throws:
If the Ad SDK is not initialized.


updateAppState(appState: AppState): void

Updates the SDK with a new state payload.

Parameters:

  • appState: AppState
    Updated app context data. πŸ‘‰ See full structure below or jump to AppState

Data structures

AppState

ParameterTypeRequiredDescription
consentConsentyesUser consent and privacy settings relevant for ad personalization and legal compliance.
videoVideoStateyesCurrent video playback state and characteristics affecting ad behavior.
environmentEnvironmentContextyesContext about the app environment, locale, and device details.
playerPlayerContextyesSettings and references related to the video player instance.

Consent

ParameterTypeRequiredDescription
ccpaConsentstringyesUser’s consent status under the California Consumer Privacy Act.
tcfConsentstringyesConsent string according to the IAB Transparency and Consent Framework (TCF).
isEnabledForTcfbooleanyesFlag indicating if TCF enforcement is enabled for this user/session.
tcf2HasConsentForGooglebooleanyesWhether consent has been given for Google in TCF v2 context.
tcf2HasConsentForDailymotionbooleanyesWhether consent has been given for Dailymotion in TCF v2 context.
isGdprApplicablebooleanyesIndicates if GDPR regulations apply to the current user/session.

VideoState

ParameterTypeRequiredDescription
idstringyesThe video id
isAutoplaybooleanyesWhether the video is set to autoplay.
typestringyesIndicates if the type of the video. LIVE | STREAM
isCurrentTimeDVRbooleanyesWhether the current playback position is within a DVR window.
isSeekablebooleanyesWhether the video player supports seeking functionality.
durationnumbernoThe duration of the video
viewIdstringyesUnique identifier for the video view or playback session.

EnvironmentContext

ParameterTypeRequiredDescription
appNamestringyesName of the app or website embedding the player.
localestringyesLocale or language setting for the user session.
topDomainstringyesThe top-level domain of the page embedding the player.
embedderstringyesIdentifier or name of the embedding entity or partner.
clientTypestringyesType of client (e.g., web, mobile app, CTV).
deviceIdstringyesUnique identifier for the user’s device.
trafficSegmentnumberyesNumeric segment ID used for traffic or user segmentation.
v1ststringyesA unique ID automatically assigned to your device by Dailymotion.

PlayerContext

ParameterTypeRequiredDescription
videoTagHTMLVideoElementyesReference to the HTML video element.
isPlayerControlsEnabledbooleanyesWhether the player controls are enabled.
is3rdPartyCookiesAvailablebooleanyesIndicates if third-party cookies are accessible in this context.
playedVideosCounternumberyesCount of videos played during the session/user lifecycle.

Internal data models

AdDetails

ParameterTypeDescription
skipOffsetnumberTime in seconds after which the ad can be skipped.
durationnumberTotal duration of the ad in seconds.
mediaFilestringURL of the media file (video/audio) for the ad.
impressionTrackerstringURL used to track ad impressions (views).
midrollTimenumberTimestamp in the main content when a midroll ad should play.
position'preroll' | 'midroll' | 'postroll'Indicates the ad position relative to the main content.

AdEvents

ParameterDescription
AD_BREAK_STARTSent when the ad break has started
AD_BREAK_ENDSent when the ad break has ended
AD_LOADSent when the ad has loaded
CONTENT_PAUSE_REQUESTEDSent to pause the content for midroll ads
AD_STARTSent when the ad has started
AD_PLAYSent when the ad is played
AD_PAUSESent when the ad is paused
AD_ENDSent when an ad has ended
AD_ERRORSent when an error preventing to play an ad occurs
CONTENT_RESUME_REQUESTEDSent to resume content after an ad

SDK and Events sequences for each ad position

Preroll sequence

Midroll sequence

Postroll sequence

0.0.10

5 months ago

0.0.9

5 months ago

0.0.8

5 months ago

0.0.7

5 months ago

0.0.6

5 months ago

0.0.5

5 months ago

0.0.4

5 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago