Test SSAI Ad Events by Joining Markers, Decisions and Beacons
An ad server can count a pod as complete while finance finds impressions short. Join the playlist's break markers, the stitcher's decision, the VAST beacons and the content resume point on AdServingId, deduplicate retried beacons, and check the IN marker's duration against the media stitched.

EXT-X-DATERANGE with SCTE35-OUT and SCTE35-IN), the stitcher's decision for each slot, the tracking beacons the collector received, and the point where content resumed. Join on the VAST AdServingId, distinct for each ad in a pod. Deduplicate beacons on AdServingId plus event, never on the URL, because a retry carries a new [CACHEBUSTING] and [TIMESTAMP]. Check the IN tag's DURATION against the media actually stitched: RFC 8216 requires the actual duration, not the planned one.The ad server's report for break splice-6FFFFFF0 shows two complete events for a two-ad pod: the pod completed. Finance finds one billable impression. Both read the same beacon log, and both are arithmetically correct. One of the two completes is a retry of the first creative's beacon. The second creative's rendition never arrived at the stitcher, which played a slate in its place and reported VAST error 402. The playlist also claims the break lasted 12 seconds when 10 seconds of media were stitched, so the player puts the content in-point two seconds after the content actually resumed.
That break comes from the lab below. A check that counts complete beacons passes it. A correlator that joins marker, decision, beacons and resume position fails it on two rows and names the owner of each.
This is part 6 of the streaming quality series. Part 1 listed ads as one contract, splice markers joined to the beacons the player sent; this part builds that join. Playlist syntax belongs to part 2's manifest validator; here only the ad-break tags matter.
npm install --save-exact, on macOS against http://localhost only, with synthetic ffmpeg lavfi media. VAST 4.3 (December 2022) is the latest published VAST; the 4.4 text in the same repository says "Publication Date TBD". RFC 8216bis revision 22 (1 May 2026) is an Internet-Draft, not a standard, and its printed expiry of 2 November 2026 had passed. Splice semantics here come from RFC 8216's mapping of SCTE-35, not from the SCTE-35 standard itself.One break, four records, four authors
Every stitched break leaves four records, each from a system that can be wrong on its own:
| Record | Written by | What it claims |
|---|---|---|
| Break markers in the media playlist | Packager or stitcher | Where the break starts, how long it was planned to be, and how long it actually was |
| Decision record | Stitcher, from the ad server's VAST | Which ad filled each slot, by AdServingId, and why a slot was filled with something else |
| Beacon log | Collector, from player or stitcher requests | Which events fired for which ad, when, and from which side |
| Player log | The player | Which segment played when, including the first content after the break |
The join key is the AdServingId. VAST 4.3 requires an ad server returning an InLine ad to generate a pseudo-unique ID, put it in <AdServingId> and include it on all outgoing tracking pixels, with a distinct value for each <Ad> in a pod. The [ADSERVINGID] macro that puts it on a tracking URL is marked Optional in the IAB's macro list, so check that your stitcher fills it before building anything else.
Rules the break markers must obey
RFC 8216 maps SCTE-35 splices onto EXT-X-DATERANGE tags. A splice out and its splice in share one ID, unique to the pair, with the hexadecimal sections in SCTE35-OUT and SCTE35-IN. The rules worth testing:
- The OUT tag may carry
PLANNED-DURATION, the planned length of the splice. - The IN tag's
DURATIONmust be the actual program duration between the out-point and the in-point, and itsEND-DATEthe actual in-point. The RFC writes "actual (not planned)" twice. - A playlist with any
EXT-X-DATERANGEmust also contain anEXT-X-PROGRAM-DATE-TIMEtag, which maps START-DATE onto media time. - Tags sharing an ID must agree on every attribute they both carry, and every variant stream must contain the same set of date ranges.
- A canceled splice should not appear at all.
The same-ID rule has a sharp edge in hls.js 1.7.4. Its DateRange class merges same-ID tags, and when a shared attribute differs it logs a warning and marks the range invalid ("Date range <attribute> mismatch"). A stitcher that rounds START-DATE differently on the IN tag invalidates its own break.
Revision 22 of the RFC 8216bis draft keeps these rules and lets a later tag omit START-DATE when an earlier tag with the same ID supplied it. Its interstitials (CLASS="com.apple.hls.interstitial") carry X-RESUME-OFFSET, which states where primary playback resumes. A stitched stream has no such attribute: the IN marker is the only statement of where the break ends.
What a tracking beacon can and cannot prove
VAST 4.3 defines firstQuartile, midpoint and thirdQuartile as the creative having played continuously for at least 25%, 50% and 75% of its duration at normal speed, and complete as 100%. All <Impression> URIs for an ad, wrappers included, should fire at the same time. A beacon proves that a request reached the collector. It does not prove which ad played, that it played once, or that nobody else sent the same event.
- Retries look like new events. The macro list defines
[CACHEBUSTING]as a random 8-digit integer and[TIMESTAMP]as the time the URI is accessed, both Required on tracking pixels. A player that refills macros on retry sends a different URL each time, so URL-level deduplication keeps every retry. - The server may count for the player. VAST 4.3 lets a stitcher send tracking on the player's behalf, reporting an impression as the ad is sent on the stitched stream or at session end, while quoting measurement guidelines that favour client-initiated counting. The
[SERVERSIDE]macro records the sender: 0 for the client, 1 for a server acting on the client's instruction, 2 for a server acting on its own decision. - Failures have codes. 402 is a timeout of the MediaFile URI, 407 a mezzanine still being transcoded (the ad is skipped), 206 a shortened break. A slot filled by something other than its creative should produce an error beacon and no impression.
A two-ad pod whose second creative never arrives
The lab stitches a two-ad pod, planned at 6 seconds per creative, into the middle of a 16-second programme. One local server is the VAST 4.3 ad server, an ad-media origin where creative 2 never answers, and a beacon collector. Install and build the media:
npm init -y
npm i --save-exact [email protected] [email protected]
bash build-media.sh
#!/usr/bin/env bash
# Synthetic media only: programme, one creative, one slate. 2 s TS segments.
set -euo pipefail
cd "$(dirname "$0")"
rm -rf media && mkdir -p media/content media/ads/c1 media/slate
enc() { # $1 video src, $2 audio src, $3 seconds, $4 out dir
ffmpeg -hide_banner -loglevel error -f lavfi -i "$1" -f lavfi -i "$2" -t "$3" \
-c:v libx264 -profile:v main -preset veryfast -g 60 -keyint_min 60 -sc_threshold 0 -b:v 800k -pix_fmt yuv420p \
-c:a aac -b:a 96k -ac 2 -ar 48000 \
-f hls -hls_time 2 -hls_playlist_type vod -hls_segment_filename "$4/seg%02d.ts" "$4/index.m3u8"
}
enc "testsrc2=size=640x360:rate=30" "sine=frequency=440:sample_rate=48000" 16 media/content
enc "testsrc=size=640x360:rate=30" "sine=frequency=880:sample_rate=48000" 6 media/ads/c1
enc "smptebars=size=640x360:rate=30" "anullsrc=r=48000:cl=stereo" 4 media/slate
The collector writes every request to a JSON-lines file the moment it arrives. For the first complete it then holds the response for 2.5 seconds, longer than the player's one-second beacon timeout, so the event is recorded but the player never learns that:
if (path === "/t") {
const q = Object.fromEntries(url.searchParams);
await appendFile("beacons.jsonl", JSON.stringify({ at: Date.now(), ...q }) + "\n");
if (q.e === "complete" && holdNextComplete) {
holdNextComplete = false;
setTimeout(() => res.writeHead(204, { "access-control-allow-origin": "*" }).end(), 2500);
return;
}
res.writeHead(204, { "access-control-allow-origin": "*" }).end();
return;
}
if (path.startsWith("/ad-media/c2/")) return; // creative 2's origin never answers
The stitcher and its one bug
The stitcher requests the pod, fetches each creative's rendition with a 1.5-second deadline, and fills a failed slot with a 4-second slate after firing the ad's <Error> URL with code 402:
for (const ad of ads) {
try {
const r = await fetch(ad.media, { signal: AbortSignal.timeout(1500) });
if (!r.ok) throw new Error(`HTTP ${r.status}`);
decision.slots.push({ seq: ad.seq, adId: ad.id, asid: ad.asid, filled: "creative", media: segs(`ads/c${ad.seq}`) });
tracking[ad.asid] = ad.tracking;
} catch (e) {
// VAST 402: timeout of MediaFile URI. Reported server-side, then slate.
await fetch(fill(ad.error, { asid: ad.asid, code: 402 }));
decision.slots.push({ seq: ad.seq, adId: ad.id, asid: ad.asid, filled: "slate", reason: `402 ${e.name}`, media: segs("slate") });
}
}
Its bug is one line, and a common shape: the IN tag's DURATION is the sum of the creatives it was given, not the media it stitched.
const plannedSum = ads.reduce((a, ad) => a + ad.duration, 0); // the bug
L.push(`#EXT-X-DATERANGE:ID="${SPLICE}",START-DATE="${iso(outAt)}",DURATION=${plannedSum.toFixed(3)},SCTE35-IN=${IN}`);
The splice bytes are copied from RFC 8216's example in section 8.10 and never decoded. Each slot gets its own date range, with the AdServingId in an X- attribute, the namespace RFC 8216 reserves for client-defined attributes:
#EXT-X-DATERANGE:ID="splice-6FFFFFF0",START-DATE="2026-11-18T10:00:08.000Z",PLANNED-DURATION=12.000,SCTE35-OUT=0xFC002F0000000000FF000014056FFFFFF000E011622DCAFF000052636200000000000A0008029896F50000008700000000
#EXT-X-DATERANGE:ID="dec-20261118-0007-1",CLASS="com.example.ssai.ad",START-DATE="2026-11-18T10:00:08.000Z",DURATION=6.000,X-COM-EXAMPLE-DECISION="dec-20261118-0007",X-COM-EXAMPLE-ADSERVINGID="labsrv-3f1c9a2e-0001"
#EXT-X-DISCONTINUITY
#EXT-X-PROGRAM-DATE-TIME:2026-11-18T10:00:08.000Z
#EXTINF:2.000,
media/ads/c1/seg00.ts
#EXTINF:2.000,
media/ads/c1/seg01.ts
#EXTINF:2.000,
media/ads/c1/seg02.ts
#EXT-X-DATERANGE:ID="dec-20261118-0007-2",CLASS="com.example.ssai.slate",START-DATE="2026-11-18T10:00:14.000Z",DURATION=4.000,X-COM-EXAMPLE-DECISION="dec-20261118-0007",X-COM-EXAMPLE-ADSERVINGID="labsrv-3f1c9a2e-0002"
#EXT-X-DISCONTINUITY
#EXT-X-PROGRAM-DATE-TIME:2026-11-18T10:00:14.000Z
#EXTINF:2.000,
media/slate/seg00.ts
#EXTINF:2.000,
media/slate/seg01.ts
#EXT-X-DATERANGE:ID="splice-6FFFFFF0",START-DATE="2026-11-18T10:00:08.000Z",DURATION=12.000,SCTE35-IN=0xFC002A0000000000FF00000F056FFFFFF000401162802E6100000000000A0008029896F50000008700000000
#EXT-X-DISCONTINUITY
#EXT-X-PROGRAM-DATE-TIME:2026-11-18T10:00:18.000Z
#EXTINF:2.000,
media/content/seg04.ts
The player fires its own beacons
The page reads details.dateRanges from hls.js on LEVEL_LOADED, and for each com.example.ssai.ad slot fires impression, start, the quartiles and complete from timeupdate as the playhead crosses each share. Macros are filled per attempt, and a failed attempt is retried once:
async function beacon(tpl, asid, event, adPlayhead) {
for (let attempt = 1; attempt <= 2; attempt++) {
const url = tpl.replaceAll("[ADSERVINGID]", encodeURIComponent(asid))
.replaceAll("[ADPLAYHEAD]", encodeURIComponent(hhmmss(adPlayhead)))
.replaceAll("[CACHEBUSTING]", String(Math.floor(1e7 + Math.random() * 9e7)))
.replaceAll("[TIMESTAMP]", encodeURIComponent(new Date().toISOString()))
.replaceAll("[SERVERSIDE]", "0");
try {
await fetch(url, { signal: AbortSignal.timeout(1000) });
rec("beacon", { event, asid, attempt, ok: true });
return;
} catch (e) {
rec("beacon", { event, asid, attempt, ok: false, error: e.name });
}
}
}
The retry is reasonable: a beacon lost to a dropped response is lost revenue. Recognising it is the correlator's job.
The count says complete; the join says one ad
One real-time playback in Playwright's Chromium took 31.5 seconds of wall clock; the correlator then reads the four records. The output as printed:
$ node run.mjs
slot 1 labsrv-3f1c9a2e-0001 -> creative
slot 2 labsrv-3f1c9a2e-0002 -> slate (402 TimeoutError)
played in 29.6 s with 151.0.7922.34
$ node correlate.mjs
naive check: complete beacons 2, ads in pod decision 2 -> PASS
marker pair PASS splice-6FFFFFF0: OUT at 8.000 s, IN present, same ID
break duration FAIL IN DURATION=12.000 (PLANNED 12.000), stitched media 10.000 s
decision join PASS 2 slot tags carry dec-20261118-0007, AdServingIds in pod order
slot 1 creative PASS labsrv-3f1c9a2e-0001 tagged com.example.ssai.ad 6.000 s; events impression,start,firstQuartile,midpoint,thirdQuartile,complete
slot 1 dedupe INFO raw 7, unique 6; complete twice, cb 24862842 then 55644167, 1001 ms apart
slot 2 slate PASS labsrv-3f1c9a2e-0002 tagged com.example.ssai.slate 4.000 s; events error; decision 402 TimeoutError
slot 2 dedupe INFO raw 1, unique 1
resume programme PASS resumed at programme 8.000 s, left it at 8.000 s
resume vs IN FAIL media/content/seg04.ts played from media 18.125 s; IN marker puts the in-point at 20.000 s
billable after correlation: impressions 1, completes 1 of 2 decided
The collector's raw lines show why a URL-level dedupe would keep both completes. Same AdServingId, same ad playhead, a different cachebuster and a timestamp one second later:
{"at":1794970503543,"e":"error","code":"402","asid":"labsrv-3f1c9a2e-0002","cb":"44385748","ts":"2026-11-18T02:55:03.540Z","ss":"2"}
{"at":1794970518193,"e":"complete","asid":"labsrv-3f1c9a2e-0001","ap":"00:00:06.000","cb":"24862842","ts":"2026-11-18T02:55:18.192Z","ss":"0"}
{"at":1794970519194,"e":"complete","asid":"labsrv-3f1c9a2e-0001","ap":"00:00:06.000","cb":"55644167","ts":"2026-11-18T02:55:19.192Z","ss":"0"}
Both completes belong to creative 1. Creative 2's only event is error 402 from the stitcher (ss 2), the right terminal event for an ad that never played. And the IN tag says 12 seconds where the playlist holds 10.
The player believes the marker. hls.js merges the OUT and IN tags into one date range, and the page's log reports the break with the IN tag's duration:
{"type":"daterange","ct":0,"id":"splice-6FFFFFF0","start":8,"duration":12}
{"type":"daterange","ct":0,"id":"dec-20261118-0007-1","class":"com.example.ssai.ad","start":8,"duration":6}
{"type":"daterange","ct":0,"id":"dec-20261118-0007-2","class":"com.example.ssai.slate","start":14,"duration":4}
An ad countdown, a no-seek-during-ads rule, or a server computing content position from that range is two seconds wrong. The resume check measures it: content segment 4 played from 18.125 s, the marker's in-point is 20.000 s. The extra 0.125 s is not the marker's fault. hls.js placed each segment after a discontinuity slightly later than the playlist arithmetic (8.003 s, 14.088 s, 18.125 s), so compare positions with a tolerance; the lab's 0.5 s is a policy, not a number from any specification.
Joining on AdServingId, not on the URL
The correlator is about 80 lines. It records every date range at its position on the playlist's media timeline (the running sum of EXTINF), so the IN tag's DURATION can be compared with what was stitched before the first content segment. Beacons are deduplicated on AdServingId plus event, and each slot's expected events depend on what the decision says filled it:
const EXPECT = { creative: ["impression", "start", "firstQuartile", "midpoint", "thirdQuartile", "complete"], slate: ["error"] };
for (const b of mine) {
const key = `${b.asid}|${b.e}`;
if (unique.has(key)) dupes.push([unique.get(key), b]); else unique.set(key, b);
}
const got = [...unique.values()].map((b) => b.e);
const missing = EXPECT[slot.filled].filter((e) => !got.includes(e));
const extra = got.filter((e) => !EXPECT[slot.filled].includes(e));
const early = [...unique.values()].filter((b) => SHARE[b.e] && secs(b.ap) + 0.001 < SHARE[b.e] * Number(tag.DURATION));
The early filter uses [ADPLAYHEAD]: a quartile reported before its share of the creative had played was fired by a clock, not by playback. The resume check makes two comparisons: programme position on each side of the break catches skipped or repeated content, and the player's position against the IN marker catches a dishonest marker.
Which record is lying in your break
Each symptom has its own cause, owner and discriminating check.
More completes than impressions
Group beacons by AdServingId and event. Two completes for one ad, a second or so apart with different cachebusters, are a retry; the counting side owns the fix, deduplicating on AdServingId plus event (plus offset for progress events). Different AdServingIds mean two ads, and the question becomes why the decision lists one.
Impressions for a creative that never played
Join each slot's date range class to the decision's fill. A slot filled with slate whose AdServingId still has an impression means the stitcher tagged the slate as the creative, or fired the impression when it made the decision rather than when it stitched the media. Either way the stitcher owns it. The expected record for that slot is an error beacon (402, 407 or 206, depending on why) and nothing else.
A break longer on paper than on screen
Sum the EXTINF durations from the OUT tag to the first content segment and compare with the IN tag's DURATION. A mismatch equal to a creative's length, or to the difference between creative and slate, means the stitcher wrote the planned duration. If the sum is right and the player still resumes late, look at the player's timestamp handling at the discontinuity instead.
Client and server both counting one ad
Filter one AdServingId and event and look at the [SERVERSIDE] value. A 0 beside a 1 or 2 means the player and the stitcher both fired it. Pick one source per event for billing and keep the other as an audit trail. Server-fired tracking also needs X-Device-IP and X-Device-User-Agent headers, which VAST 4.3 requires so that one server's traffic is not mistaken for invalid traffic.
What this harness costs and misses
It runs in real time, because quartiles are defined at normal speed and a raised playbackRate tests a mode the definitions exclude. Each break costs its length plus startup: one representative break per pull request, a wider set nightly.
Its dedupe rule has a policy edge. Rewinding into a stitched ad in a VOD stream can legitimately replay it under the same AdServingId; decide whether that counts before the correlator decides for you.
It sees one player: a desktop browser through MSE, not a television app with its own timing. It does not decode SCTE-35, so a wrong out_of_network_indicator inside the bytes passes. And it models VOD, where content should resume exactly where it left off. In a live stream the break replaces content, so that check flips: content should resume later by the break's length, or the viewer falls behind live.
Questions about reconciling SSAI beacons
Should the IN tag carry END-DATE as well as DURATION?
Either is enough, and both must then agree: RFC 8216 requires END-DATE to equal START-DATE plus DURATION when a range has both, and each must describe the actual in-point. Carrying both gives a second value to check against the summed segment durations, and a second way for the stitcher to disagree with itself.
Does HLS interstitial playback change any of this?
Partly. With interstitials, the client plays the ad asset itself and the draft defines X-RESUME-OFFSET, so the resume point is stated rather than inferred. The beacon side does not change: you still need one key per ad and deduplication on it.
Is a break with only error beacons a failure?
Not by itself. A pod where every creative timed out and slate filled the break should produce error beacons and no impressions. It becomes a failure when the decision says creative and the beacons say error, or the other way round.
Specifications behind the break checks
- RFC 8216, HTTP Live Streaming. Date range attributes, the SCTE-35 mapping in section 4.3.2.7.1, and the example splice bytes in section 8.10.
- HLS 2nd Edition Internet-Draft, revision 22. START-DATE omissible on a later same-ID tag, and interstitials with
X-RESUME-OFFSET. - IAB Tech Lab VAST 4.3. Stitcher tracking and its headers, AdServingId, impression timing, quartile definitions and error codes.
- IAB Tech Lab VAST 4.4 working text. Still marked "Publication Date TBD".
- IAB Tech Lab VAST 4 macro data. Definitions and support levels of the macros used here.
- hls.js DateRange source at v1.7.4. How same-ID tags merge, and when a range turns invalid.
- hls.js 1.7.4 API reference (docs/API.md). Date range metadata cues and interstitial playback.
Reconcile one production break this week
Take one break from yesterday's traffic on one device family and pull the four records for it: the media playlist as served, with its EXT-X-DATERANGE tags; the stitcher's decision log; every beacon the collector received with that splice's AdServingIds; and, if the player logs segment changes, the first content segment after the break. Then compute four numbers: raw against unique beacons per AdServingId and event, the IN DURATION against the summed EXTINF, impressions on slots whose fill was not the creative, and the resume position against the in-point. Save the joined table beside the ticket as the evidence, so the next disagreement between the ad server and finance starts from a break both can read.