Skip to main content

Server Side Ad Insertion using MediaTailor

MediaTailor Ads

The MediaTailor library provides seamless integration with AWS MediaTailor for server-side ad insertion (SSAI) in video streaming applications.

Setup

Wiring Authorization Response

Once an asset is authorized for Playback (refer Authorize Playback for an Asset), the authorization response indicates the ssaiAdProvider should be mediatailor, adtype be ssai andcustom field will have mtSessionUrl. The mediatailor ad player must be setup only when all of the metadata are available.

NameDescription
ssaiAdProviderIndicates the ad provider
adtypetype of the ad being served either csai or ssai
mtSessionUrlmediatailor session url to get content url and ad tracking url

Usage

This first step is the creation of a MediaTailor Manager instance that will be used to intialize the session to retrieve playback URL and ad tracking URL to create MediaTailor Ad player.

Create a Mediatailor Manager

const mediatailorSession = flAdsMediatailor.createMediaTailorSession();

Session creation

The initialize method orchestrates the MediaTailor session creation process


const mediaTailorSessionConfiguration: MediatailorSessionConfiguration = {
adsParams: { customAd: "value1" },
playerParams: { playerType: "web" },
manifestParams: { format: "hls" },
availSuppression: {
mode: flAdsMediatailor.AvailSuppressionMode.BEHIND_LIVE_EDGE,
value: "00:00:21",
},
adSignaling: true,
originParams: {
customOriginParam1: "value1",
customOriginParam2: "value2",
region: "us-east-1"
},
overlayAvails: flAdsMediatailor.OverlayAvailsMode.ON,
reportingMode: flAdsMediatailor.ReportingMode.SERVER,

};

const mediatailorInitializationData: MediatailorInitializationData = {
sessionUrl: playbackAsset.mtSessionUrl,
fallbackUrl: playbackAsset.contentUrl,
mediaTailorSessionConfiguration: mediaTailorSessionConfiguration,
maxRetries: 1,
connectionTimeoutInMS: 1000,
}

try {
const mediatailorMetadata: MediatailorMetadata = await mediatailorSession.initialize(
mediatailorInitializationData,
palConfiguration,
)
} catch (error: Error) {
console.log('Mediatailor session failure', error)
}
MediatailorInitializationData
NameTypeOptionalDescription
sessionUrlstringfalseMediaTailor session url.
fallbackUrlstringfalsecontent url given by playback Authorization response in case of session failure
mediaTailorSessionConfigurationMediaTailorSessionConfigurationtrueAd targetting parameters.
maxRetriesnumbertrueMaxinum number of retries on network failures
connectionTimeoutInMSnumbertrueMaximum amount of time (in milliseconds) to wait while trying to establish a connection before giving up.
MediatailorSessionConfiguration
ParameterTypeDescription
adsParamsMap<String, Any>?Key-value pairs that MediaTailor can read and send to the ad server in all session requests
playerParamsMap<String, Any>?Preceding configuration used for session initialization request that defines the player variables and their aliases.
manifestParamsMap<String, Any>?Query parameters included in the parent manifest and tracking URLs in the response.
availSuppressionAvailSuppressionavailSuppression
adSignalingbooleanTo enable ad ID signaling, add an adSignaling object as a top level object, and inside, add a parameter called enabled and value of true. The default adSignaling value is disabled.
originParamsMap<String, Any>?custom origin parameters for the session.
overlayAvailsOverlayAvailsModeMediaTailor support for overlay ads is enabled by default. A specific SCTE-35 ad-marker type in the manifest triggers the insertion of an overlay ad. Because some players might not support client-side rendering of overlay ads, you can disable the feature at the session level.
reportingModeReportingModeMediaTailor supports a hybrid mode for session tracking. In this mode, the service emits playback-related ad-tracking events, but makes the complete client-side tracking payload available for the session.
AvailSuppression
ParameterTypeDescription
modeAvailSuppressionModead break suppression
valuestringA time relative to the live edge in a live stream
AvailSuppressionMode
ParameterDescription
OFFAd suppression is OFF
BEHIND_LIVE_EDGEWhen set to BEHIND_LIVE_EDGE, MediaTailor doesn't fill ad breaks on or behind the aws.availSuppressionValue time
AFTER_LIVE_EDGE_FULL_AVAIL_ONLYMediaTailor doesn't fill ad breaks on or behind the avail suppression period and full avail suppression policy
AFTER_LIVE_EDGE_PARTIAL_AVAILMediaTailor doesn't fill ad breaks on or behind the avail suppression period and invoke partial ad break fills when and session starts mid-break

OverlayAvailsMode

ParameterDescription
ONEnabling overlaying ads
OFFDisabling overlaying ads
ReportingMode
ParameterDescription
SERVERMediaTailor supports a hybrid mode for session tracking. In this mode, the service emits playback-related ad-tracking events, but makes the complete client-side tracking payload available for the session
PALConfiguration
PropertyTypeDescription
willAdAutoPlaybooleanDefines whether the ad will be auto played without waiting for user interaction or not.
willAdPlayMutedbooleanDefines whether the ad will be played while muted or not.
continuousPlaybackbooleanDefines whether the player intends to continuously play the content videos one after another similar to TV broadcast or video playlist.
descriptionUrlstringDefines the description URL of the content during which the ad will be played.
iconsSupportedbooleanDefines whether VAST icons are supported by the video player.
nonceLengthLimitnumberDefines the length limit of the generated nonce.
omidPartnerNamenumberThe name of the partner integrating OMID measurement.
omidPartnerVersionstringThe version of the partner integrating OMID measurement.
omidVersionstringThe version of OMID that the player responsible for ad playback integrates with.
playerTypestringThe partner provided player type.
playerVersionstringThe partner provided player version.
ppidstringThe publisher provided ID.
videoHeightnumberThe height of the ad video element.
videoWidthnumberThe width of the ad video element.
MediatailorMetadata
NameTypeOptionalDescription
manifestUrlstringfalsecontent url
statusstringfalseDecribes session initialization status . sucsess or failure
reasonstringfalseDetailed description on session status
trackingUrlstringtrueMediaTailor ad tracking url used to retrieve ad metadata

Create Ad Composed Player

AdComposedPlayer managers both content and ad playback. It basically extends the conventional Player functionality and adds ads rendering to it.

const contentPlayer: Player = flPlayer
.createPlayerBuilder()
.mediaElement(mediaElement)
.mediaUrl(mediatailorMetadata.manifestUrl)
.mediaType(MediaType.HLS)
.build();

const adsPlayer = mediatailorSession.createMediatailorPlayer(
contentPlayer,
logger,
mediatailorMetadata?.trackingUrl
);

Listening to Ad Events

To listen to ad events, subscribe to any of the following events adbreakstart, adbreakend, adstart or adend.

adsPlayer.subscribe('adbreakstart', (adBreakInfo: AdBreakInfo) => {
console.log('Ad break started', adBreakInfo);
});

adsPlayer.subscribe('adstart', (adInfo: AdInfo) => {
console.log('Ad started', adInfo);
});

adsPlayer.subscribe('adend', (adInfo: AdInfo) => {
console.log('Ad ended', adInfo);
});

adsPlayer.subscribe('adbreakend', (adBreakInfo: AdBreakInfo) => {
console.log('Ad break ended', adBreakInfo);
});