Skip to main content
Adgent SDK provides comprehensive VAST (Video Ad Serving Template) 4.x compliance, designed specifically for Smart TV environments where reliability and performance are critical.

VAST 4.x Specification Support

The SDK implements the IAB VAST 4.x specification with TV-optimized behaviors:
  • InLine Ads: Direct linear video ads with complete creative data
  • Wrapper Ads: Nested VAST documents with configurable depth limits
  • Linear Creatives: Video ads with duration, skip offset, media files, and tracking
  • Tracking Events: Full event lifecycle from impression to completion
  • Error Handling: VAST error codes with automatic fallback mechanisms
VAST 4.x is the industry standard for video ad serving. Adgent SDK focuses on the linear video subset most relevant to TV platforms.

Wrapper Resolution

VAST wrappers allow ad servers to chain multiple VAST documents together. Adgent SDK resolves these chains with configurable depth limits to prevent infinite loops.

Maximum Wrapper Depth

The default maximum wrapper depth is 5 levels (configurable via maxWrapperDepth):
const sdk = new AdgentSDK({
  container: document.getElementById('ad-container')!,
  vastUrl: 'https://example.com/vast.xml',
  maxWrapperDepth: 5  // Default value
});
See: src/core/VASTParser.ts:49 and src/core/VASTParser.ts:91-94

Wrapper Merging Logic

When resolving wrappers, the parser merges tracking events from all levels:
// Wrapper tracking events are prepended to nested ad events
// This ensures all levels of the wrapper chain receive tracking pixels
const mergedTracking = [
  ...wrapperTrackingEvents,
  ...nestedAdTrackingEvents
];
Implementation: src/core/VASTParser.ts:150-174

Fallback Behavior

If a wrapper fails to resolve, the SDK checks the fallbackOnNoAd attribute:
  • fallbackOnNoAd="true": Returns empty ad array (graceful degradation)
  • fallbackOnNoAd="false": Throws error and triggers error callbacks
See: src/core/VASTParser.ts:142-146

Media File Selection Algorithm

Adgent SDK uses an intelligent algorithm to select the best media file for Smart TV playback. The selection prioritizes compatibility over quality to prevent playback failures on older hardware.

Selection Priority

  1. VPAID Filtering: Explicitly excludes VPAID/JavaScript media files
  2. Video-only: Only video/* MIME types are considered
  3. MP4 Preference: Prioritizes video/mp4 for maximum compatibility
  4. 4K Penalty: Penalizes resolutions above 1080p (height > 1080)
  5. Bitrate Matching: Selects closest to targetBitrate (default: 2500 kbps)

Implementation

selectBestMediaFile(
  mediaFiles: MediaFile[],
  targetBitrate = 2500
): MediaFile | null {
  // Filter to supported video MIME types (exclude VPAID/JS)
  const validFiles = mediaFiles.filter(mf => 
    mf.type.toLowerCase().startsWith('video/')
  );

  // Prefer MP4 for maximum compatibility
  const mp4Files = validFiles.filter(
    (mf) => mf.type.includes('mp4')
  );

  const candidates = mp4Files.length > 0 ? mp4Files : validFiles;

  // Sort by closeness to target bitrate, penalizing 4K
  const sorted = [...candidates].sort((a, b) => {
    const aPenalty = a.height > 1080 ? 10000 : 0;
    const bPenalty = b.height > 1080 ? 10000 : 0;

    const aDiff = Math.abs((a.bitrate || 0) - targetBitrate) + aPenalty;
    const bDiff = Math.abs((b.bitrate || 0) - targetBitrate) + bDiff;

    return aDiff - bDiff;
  });

  return sorted[0] || null;
}
Full implementation: src/core/VASTParser.ts:441-479

Why Penalize 4K?

Smart TVs, especially models from 2016-2019, have limited memory and processing power. 4K ads can cause:
  • UI stuttering during playback
  • Memory exhaustion leading to crashes
  • Excessive bandwidth consumption on WiFi
  • Buffer underruns on slower connections
The SDK applies a 10,000 kbps penalty to media files with height > 1080px, making 1080p/720p the preferred resolution even if 4K is available.
For best results, serve ads in 1080p (1920x1080) at 1500-2500 kbps bitrate using H.264 codec in MP4 container.

Tracking Events

The SDK fires all standard VAST tracking events at the appropriate times during ad playback:

Supported Events

EventDescriptionWhen Fired
impressionAd impression (visibility)When ad starts loading
startPlayback startedWhen video begins playing
creativeViewCreative became viewableWhen video begins playing
firstQuartile25% progressAt 25% of duration
midpoint50% progressAt 50% of duration
thirdQuartile75% progressAt 75% of duration
completeAd finishedWhen video ends naturally
skipUser skipped adWhen skip button is clicked
pausePlayback pausedWhen user pauses
resumePlayback resumedWhen playback resumes
muteAudio mutedWhen user mutes
unmuteAudio unmutedWhen user unmutes
errorPlayback errorOn any error condition

Quartile Tracking

Quartile events are fired once per session using a Set to track which quartiles have been fired:
private quartilesFired: Set<number> = new Set();

private fireQuartileEvents(percentage: number): void {
  const quartiles = [
    { threshold: 25, event: 'firstQuartile' },
    { threshold: 50, event: 'midpoint' },
    { threshold: 75, event: 'thirdQuartile' }
  ];

  for (const { threshold, event } of quartiles) {
    if (percentage >= threshold && !this.quartilesFired.has(threshold)) {
      this.quartilesFired.add(threshold);
      this.tracker?.track(event);
    }
  }
}
Implementation: src/core/AdPlayer.ts:486-501

Error Tracking

VAST errors include standard error codes from the specification:
enum VASTErrorCode {
  NO_VAST_RESPONSE = 303,
  GENERAL_WRAPPER_ERROR = 300,
  GENERAL_LINEAR_ERROR = 400,
  FILE_NOT_FOUND = 401,
  MEDIA_NOT_SUPPORTED = 403,
  UNDEFINED_ERROR = 900
}
Error pixels are fired automatically when errors occur, using the [ERRORCODE] macro replacement.

What’s NOT Supported

VPAID Explicitly Excluded

Adgent SDK does not support VPAID (Video Player-Ad Interface Definition). VPAID media files are automatically filtered out during media selection.

Why No VPAID?

VPAID is deliberately excluded for Smart TV platforms due to:
  1. Performance: VPAID requires executing arbitrary JavaScript within the player context, which severely degrades performance on resource-constrained TV hardware
  2. Stability: Third-party VPAID scripts are a common source of memory leaks and application crashes on long-running TV apps
  3. Security: Executing unverified external code poses significant security risks
  4. Modern Alternatives: The industry has moved towards VAST 4.x and OMID for measurement, rendering VPAID obsolete
See: src/core/VASTParser.ts:447-452 and README.md:372-382

Non-Linear & Companion Ads

The SDK focuses exclusively on linear video ads. Non-linear (overlay) and companion (banner) ads are not parsed or displayed. This design decision reflects the TV use case where full-screen linear video is the primary ad format.

Advanced Features

The following VAST 4.x features are not currently supported:
  • Interactive creatives (requires VPAID)
  • Ad pods with complex sequencing
  • Conditional ads
  • Verification resources (OMID/OM SDK)
  • Industry icons
  • Ad parameters for custom data passing
If you need advanced features like OMID verification or ad pods, please contact [email protected] to discuss custom implementations.

Configuration

VAST parser behavior can be customized via the SDK configuration:
const sdk = new AdgentSDK({
  container: document.getElementById('ad-container')!,
  vastUrl: 'https://example.com/vast.xml',
  
  // VAST configuration
  maxWrapperDepth: 5,       // Maximum wrapper chain depth
  timeout: 10000,           // VAST fetch timeout (ms)
  targetBitrate: 2500,      // Preferred bitrate (kbps)
  
  // Debugging
  debug: true               // Enable detailed logging
});
See the Configuration Reference for all available options.

Platform Support

Learn about platform detection and capabilities

Nuclear Mute Strategy

Understand the autoplay strategy for Smart TVs

Build docs developers (and LLMs) love