View a markdown version of this page

⭐ Football Update: mediatailor/latest/ug/monetization functions hooks.html - Pertandingan Hari Ini

Functions lifecycle hooks

A lifecycle hook defines when MediaTailor runs your function during playback. This page is a complete reference for input fields, output namespaces, and the rules that govern data flow at each hook.

Overview

You can use the following five lifecycle hooks:

  • PRE_SESSION_INITIALIZATION fires once when a viewer starts a new session. Use it for one-time setup work such as fetching audience segments. At this point, no ad break has occurred, so ad break context is not available.

  • POST_ORIGIN_RESPONSE fires after MediaTailor fetches a manifest from the content origin, before it parses ad markers and calls the ADS. Use it to filter, rewrite, or remove HLS tags, such as SCTE-35 signals, and to start or end a blackout.

  • PRE_ADS_REQUEST fires before every ad decision server (ADS) request — once per ad break in the stream. Use it to customize the ADS request with targeting data, modify the ADS URL, or add headers.

  • POST_ADS_RESPONSE fires after MediaTailor receives and parses the ADS response, including resolution of Video Ad Serving Template (VAST) wrapper redirects. Use it to filter, reorder, modify, or supplement the ads that the ADS returned, before MediaTailor selects ads to insert.

  • PRE_MANIFEST_INSERTION fires at the end of ad break personalization, after ad selection, transcode checks, and fill policy, immediately before MediaTailor writes ads into the manifest. Use it to inspect or modify the final ad set, including injecting additional ads into underfilled ad breaks.

The hooks differ in timing and scope. PRE_SESSION_INITIALIZATION runs once and sets up data that persists for the entire session. POST_ORIGIN_RESPONSE runs on each origin manifest fetch and processes each matching tag once per session. PRE_ADS_REQUEST and POST_ADS_RESPONSE run around each ADS interaction. PRE_ADS_REQUEST shapes the outgoing request, and POST_ADS_RESPONSE acts on the parsed response before ad selection. PRE_MANIFEST_INSERTION runs after selection is complete and sees the final ad set for all newly personalized ad breaks in a single invocation.

Important

The PRE_ADS_REQUEST, POST_ADS_RESPONSE, and PRE_MANIFEST_INSERTION hooks share a combined execution budget of 2,000 ms for a single request. This budget is in addition to each hook's own 2,000 ms timeout. A hook's effective timeout is the smaller of its own timeout and the remaining budget. Time spent by an earlier hook reduces the time available to later hooks in the same request. If the remaining budget is exhausted before a hook starts, MediaTailor skips that hook and continues processing the request without it. PRE_SESSION_INITIALIZATION and POST_ORIGIN_RESPONSE run outside this combined budget. For more information, see Limits.

Note

In this documentation, an ad break is also called an avail. Input field names (such as avail.availId and avails.avails) and CloudWatch metrics use the avail form.

Input field reference

The following table lists the input fields available at each lifecycle hook. In the Field column, parent[].child notation indicates a field of each element in the parent array.

Field Type PRE_SESSION_INITIALIZATION POST_ORIGIN_RESPONSE PRE_ADS_REQUEST POST_ADS_RESPONSE PRE_MANIFEST_INSERTION
session.idLong✓✗✓✓✓
session.uuidString✓✗✓✓✓
session.client_ipString✓✗✓✓✓
session.user_agentString✓✗✓✓✓
session.referer*String✓✗✓✗✗
session.avail_duration_secsLong✗✗✓✗✗
session.avail_duration_msLong✗✗✓✗✗
session.streaming_modeString✗✗✗✓✓
session.media_protocolString✗✗✗✗✓
player_params.*String✓✓✓✓✓
event.idString✓✓✓✓✓
event.hookString✓✓✓✓✓
event.timestampString✓✓✓✓✓
event.streamFormatString✗✓✗✗✗
event.streamIdString✗✓✗✗✗
event.playbackConfigNameString✗✓✗✗✗
event.lastProcessedString✗✓✗✗✗
avail.indexInt✗✗✓✗✗
avail.randomLong✗✗✓✗✗
avail.source_content_time_epoch_msLong✗✗✓✗✗
avail.availId†String✗✗✗✓✗
avail.durationSeconds†Number✗✗✗✓✗
avail.startTime†String✗✗✗✓✗
scte.event_idInt✗✗✓✗✗
scte.avail_numInt✗✗✓✗✗
scte.segmentation_event_idInt✗✗✓✗✗
scte.segmentation_type_idInt✗✗✓✗✗
scte.segmentation_upidString✗✗✓✗✗
scte.segmentation_upid.assetIdString✗✗✓✗✗
scte.segmentation_upid.cueData.keyString✗✗✓✗✗
scte.segmentation_upid.cueData.valueString✗✗✓✗✗
scte.unique_program_idInt✗✗✓✗✗
scte.archive_allowed_flagBoolean✗✗✓✗✗
scte.delivery_not_restricted_flagBoolean✗✗✓✗✗
scte.device_restrictionsInt✗✗✓✗✗
scte.no_regional_blackout_flagBoolean✗✗✓✗✗
scte.segment_numInt✗✗✓✗✗
scte.segments_expectedInt✗✗✓✗✗
scte.sub_segment_numInt✗✗✓✗✗
scte.sub_segments_expectedInt✗✗✓✗✗
scte.avails_expectedLong✗✗✓✗✗
asset.*String✗✗✓✗✗
inference.enrichedBoolean✗✗✓✗✗
inference.feedIdString✗✗✓✗✗
inference.dataEndpointString✗✗✓✗✗
inference.ptsLong✗✗✓✗✗
inference.timescaleLong✗✗✓✗✗
inference.regionString✗✗✓✗✗
inference.previousBreakEndPtsLong✗✗✓✗✗
inference.parseErrorBoolean✗✗✓✗✗
adsRequest.urlString✗✗✓✓✗
adsRequest.methodString✗✗✓✓✗
adsRequest.headers.<key>String✗✗✓✓✗
adsRequest.bodyString✗✗✓✗✗
adsResponse.responseTypeString✗✗✗✓✗
adsResponse.adsArray✗✗✗✓✗
adsResponse.ads[].adId‡String✗✗✗✓✗
adsResponse.ads[].durationSecondsNumber✗✗✗✓✗
adsResponse.ads[].adSystemString✗✗✗✓✗
adsResponse.ads[].adTitleString✗✗✗✓✗
adsResponse.ads[].creativeIdString✗✗✗✓✗
adsResponse.ads[].sequenceInt✗✗✗✓✗
adsResponse.ads[].mediaFilesArray✗✗✗✓✗
adsResponse.ads[].mediaFiles[].urlString✗✗✗✓✗
adsResponse.ads[].mediaFiles[].mimeTypeString✗✗✗✓✗
adsResponse.ads[].mediaFiles[].widthInt✗✗✗✓✗
adsResponse.ads[].mediaFiles[].heightInt✗✗✗✓✗
adsResponse.ads[].mediaFiles[].bitrateInt✗✗✗✓✗
adsResponse.ads[].trackingEvents.<eventType>Array of String✗✗✗✓✗
avails.availsArray✗✗✗✗✓
avails.avails[].availIdString✗✗✗✗✓
avails.avails[].durationSecondsNumber✗✗✗✗✓
avails.avails[].startTimeNumber✗✗✗✗✓
avails.avails[].mediaProtocolString (HLS | DASH)✗✗✗✗✓
avails.avails[].streamingModeString (LIVE | VOD)✗✗✗✗✓
avails.avails[].fillDurationSecondsNumber✗✗✗✗✓
avails.avails[].fillRateNumber (0–1)✗✗✗✗✓
avails.avails[].mutableBoolean✗✗✗✗✓
avails.avails[].adsArray✗✗✗✗✓
avails.avails[].ads[].adId§String✗✗✗✗✓
avails.avails[].ads[].vastAdIdString✗✗✗✗✓
avails.avails[].ads[].creativeIdString✗✗✗✗✓
avails.avails[].ads[].insertionUuidString✗✗✗✗✓
avails.avails[].ads[].sequenceInAvailInt✗✗✗✗✓
avails.avails[].ads[].durationSecondsNumber✗✗✗✗✓
avails.avails[].ads[].adSystemString✗✗✗✗✓
avails.avails[].ads[].adTitleString✗✗✗✗✓
avails.avails[].ads[].mediaUrlString✗✗✗✗✓
avails.avails[].ads[].trackingEvents.<eventType>Array of String✗✗✗✗✓
avails.avails[].ads[].mediaFilesArray✗✗✗✗✓
avails.avails[].skippedAdsArray✗✗✗✗✓
avails.avails[].skippedAds[].adIdString✗✗✗✗✓
avails.avails[].skippedAds[].vastAdIdString✗✗✗✗✓
avails.avails[].skippedAds[].durationSecondsNumber✗✗✗✗✓
avails.avails[].skippedAds[].creativeUrlString✗✗✗✗✓
avails.avails[].skippedAds[].reasonString✗✗✗✗✓
mediaPlayList.*Object✗✓✗✗✗
tag.*Object✗✓✗✗✗

For the POST_ORIGIN_RESPONSE fields, including the mediaPlayList.* and tag variables, see Media playlist and tag variables (mediaPlayList.*, tag).

* session.referer is only present when a Referer header is included in the session initialization request. Use $exists(session.referer) to check before accessing.

† The avail namespace is present only when the ADS response applies to a single ad break. It is not present for multi-break (VMAP) responses or prefetched responses. Use $exists(avail) to check before accessing.

‡ At POST_ADS_RESPONSE, adId is the id attribute of the VAST <Ad> element.

§ At PRE_MANIFEST_INSERTION, adId is an internal placement identifier. It is stable for an ad within its ad break, but it is not the VAST ad ID and is not comparable across ad breaks or across hooks. For identity checks that span ad breaks or hooks, use vastAdId (the id attribute of the VAST <Ad> element) or creativeId.

On DASH VOD streams, adTitle and adSystem are null at this hook. Use vastAdId or creativeId in predicates there.