Use this file to discover all available pages before exploring further.
The AdTracker API allows you to track video advertisement events. Use this to measure ad views, engagement, clicks, and completions within video content.
Android is the only Permutive SDK with a native ad tracker. iOS / tvOS and Web CTV publishers emit ad events manually via track(...). The typed AdTracker lifecycle below is unique to Android — use it instead of generic track() calls so the emitted events match the canonical schema automatically.
// Track without additional propertiesadTracker.trackWithAdProperties("AdMuted")// Track with additional propertiesadTracker.trackWithAdProperties( "AdQualityChanged", EventProperties.from( "from_quality" to "480p", "to_quality" to "720p" ))
// Create video tracker firstval videoTracker = permutive.trackVideoView(...)// Create ad tracker from video trackerval preRollAd = videoTracker.trackAdView( durationMs = 15000, adProperties = AdTracker.AdProperties( title = "Pre-Roll Ad", durationInSeconds = 15, campaignId = "preroll_123" ))// Play adpreRollAd.play()// ... ad plays ...preRollAd.completion()// Then play main videovideoTracker.play()
Ad shown during video content:
// Main video playingvideoTracker.pause()// Create mid-roll adval midRollAd = videoTracker.trackAdView( durationMs = 30000, adProperties = AdTracker.AdProperties( title = "Mid-Roll Ad", durationInSeconds = 30, campaignId = "midroll_456" ))midRollAd.play()// ... ad plays ...midRollAd.completion()// Resume main videovideoTracker.play()
Ad not associated with video content:
// Ad not associated with video contentval standaloneAd = permutive.trackVideoAdView( durationMs = 30000, adProperties = AdTracker.AdProperties( title = "Standalone Video Ad", durationInSeconds = 30, campaignId = "standalone_789" ))standaloneAd.play()// ... ad plays ...standaloneAd.completion()
Multiple ads played in sequence:
val ads = listOf( AdInfo("Ad 1", 15000, "camp_1", "creative_1"), AdInfo("Ad 2", 15000, "camp_2", "creative_2"), AdInfo("Ad 3", 30000, "camp_3", "creative_3"))ads.forEach { adInfo -> val adTracker = videoTracker.trackAdView( durationMs = adInfo.duration, adProperties = AdTracker.AdProperties( title = adInfo.title, durationInSeconds = adInfo.duration / 1000, campaignId = adInfo.campaignId, creativeId = adInfo.creativeId ) ) // Play ad adTracker.play() // ... wait for completion ... adTracker.completion()}
The canonical schema defines VideoAdView, VideoAdEngagement, VideoAdCompletion, and VideoAdClicked — there is no standard “skipped” event. If you want to capture skips, emit a custom event via trackWithAdProperties(...) and add the event name to your workspace schema:
// User skips ad (custom event — register the name in your workspace schema)skipButton.setOnClickListener { adTracker.trackWithAdProperties( "VideoAdSkipped", EventProperties.from( "time_watched_seconds" to getWatchedTime() ) ) adTracker.completion() loadMainContent()}
Errors are likewise not in the standard schema — emit a custom event if you need to capture ad-load failures:
// Ad fails to load (custom event — register the name in your workspace schema)adPlayer.setErrorListener { error -> adTracker.trackWithAdProperties( "VideoAdError", EventProperties.from( "error_code" to error.code, "error_message" to error.message ) ) adTracker.completion()}
Problem: VideoAdCompletion events not appearing.Cause:completion() not called.Solution: Always call completion() when ad finishes:
// When ad endsadTracker.completion()
Ad and Video Using Same ID
Problem: Ad events have same View ID as video.Cause: This is expected when creating AdTracker from MediaTracker.This is correct behavior - it links ad to video content. For independent tracking, use standalone AdTracker:
player.addListener(object : Player.Listener { override fun onIsPlayingChanged(isPlaying: Boolean) { if (isPlaying) adTracker.play() else adTracker.pause() }})
Multiple Completion Events
Problem: Multiple VideoAdCompletion events tracked.Cause: Calling completion() multiple times.Solution: Call completion() only once. After calling it, AdTracker is closed.See Common Errors for more troubleshooting.