The Adgent SDK is highly configurable to support various Smart TV platforms and advertising requirements. This guide covers all available configuration options with practical examples.
The minimal configuration requires only two parameters:
import { AdPlayer } from 'adgent-sdk';const player = new AdPlayer({ container: document.getElementById('ad-container'), vastUrl: 'https://example.com/vast.xml'});await player.init();
Container element to render the ad player into. The video element and UI overlays will be appended as children.
const container = document.getElementById('ad-container');if (!container) throw new Error('Container not found');const player = new AdPlayer({ container, vastUrl: 'https://example.com/vast.xml'});
Target bitrate in kbps for media file selection. The SDK selects the closest match from available VAST MediaFiles.Default: 2500 (approximately 1080p quality)Use cases:
High-end TVs (4K): 5000-8000 kbps
Standard 1080p TVs: 2500-3500 kbps
Budget/720p TVs: 1500-2000 kbps
Low bandwidth: 800-1200 kbps
// Optimize for budget Smart TVsconst player = new AdPlayer({ container: document.getElementById('ad-container'), vastUrl: 'https://example.com/vast.xml', targetBitrate: 1500 // Lower bitrate for older hardware});
The SDK uses a “closest match” algorithm defined in src/core/AdPlayer.ts:124. It automatically filters out excessively high bitrates that may cause buffering on TV platforms.
Network request timeout in milliseconds for VAST fetching.Default: 10000 (10 seconds)Use cases:
Fast networks: 5000-7000 ms
Standard: 10000 ms (default)
Slow TV WiFi: 15000-20000 ms
const player = new AdPlayer({ container: document.getElementById('ad-container'), vastUrl: 'https://example.com/vast.xml', timeout: 15000 // Longer timeout for TV WiFi});
Custom “Start Ad” overlay UI element for autoplay fallback scenarios.When autoplay fails (common on TVs), the SDK shows an interactive overlay. By default, it creates a play button, but you can provide your own custom element.
// Create custom overlayconst customOverlay = document.createElement('div');customOverlay.innerHTML = ` <div style="display: flex; align-items: center; justify-content: center; height: 100%;"> <button id="start-btn" style="padding: 20px 40px; font-size: 24px;"> ▶ Play Advertisement </button> </div>`;const player = new AdPlayer({ container: document.getElementById('ad-container'), vastUrl: 'https://example.com/vast.xml', customStartOverlay: customOverlay});
The overlay is shown when autoplay fails (src/core/AdPlayer.ts:287) and removed when user clicks start.
Triggered when user clicks the ad video. Receives the click-through URL from VAST.
const player = new AdPlayer({ container: document.getElementById('ad-container'), vastUrl: 'https://example.com/vast.xml', onClick: (url) => { console.log('Ad clicked:', url); // Ad is automatically paused // Click tracking pixels are automatically fired // URL is opened via platform.openExternalLink() }});
const player = new AdPlayer({ container: document.getElementById('ad-container'), vastUrl: 'https://example.com/vast.xml', debug: true // Enable for development});
When enabled, logs:
VAST parsing steps
Media file selection
Video element events (loadstart, canplay, playing, etc.)
Key presses and actions
Tracking pixel fires
Disable in production to reduce console noise and improve performance.
const player = new AdPlayer({ container: document.getElementById('ad-container'), vastUrl: 'https://example.com/vast.xml', targetBitrate: 2500, // Conservative for older LG models timeout: 15000, // WebOS networking can be slower debug: false});