AdTracker API allows you to track video advertisement events. Use this to measure ad views, engagement, clicks, and completions within video content.
Overview
AdTracker provides comprehensive video ad tracking:
- Automatic lifecycle tracking - Tracks VideoAdView and VideoAdCompletion events
- Engagement metrics - Measures time spent watching ads
- Click tracking - Tracks ad interactions
- Custom events - Track custom ad-related events
- Shared context - Can share View ID with parent MediaTracker
Creating an AdTracker
AdTracker can be created in two ways:1. From MediaTracker (Recommended)
Use this when the ad is related to video content currently being viewed. The AdTracker will share the same View ID with the MediaTracker:2. Standalone AdTracker
Use this for standalone video ads not associated with specific video content:Ad Events
AdTracker automatically generates these events:1. VideoAdView Event
Tracked when AdTracker is created:2. VideoAdCompletion Event
Tracked whencompletion() is called:
3. VideoAdClicked Event
Tracked whenclicked() is called:
AdTracker Methods
play()
Call when the ad starts playing. AdTracker initializes in a paused state, so call this immediately if the ad auto-plays:play(positionMs)
Call when playback position changes (e.g., seeking):pause()
Call when the ad is paused or buffering:clicked()
Call when the user clicks on the ad. This tracks a VideoAdClicked event:completion()
Call when the ad is no longer being shown. This tracks a VideoAdCompletion event with engagement properties:
⚠️ Important
Once completion() is called, the AdTracker is closed and subsequent method calls will have no effect.
Custom Events
Track custom ad-related events:Ad Properties
Standard Ad Properties
Property Reference
| Property | Type | Description |
|---|---|---|
| title | String | Ad title or name |
| durationInSeconds | Int | Ad duration in seconds |
| isMuted | Boolean | Whether ad started muted |
| campaignId | String | Ad campaign identifier |
| creativeId | String | Ad creative identifier |
Complete Example
Kotlin - Pre-Roll Ad
Java - Pre-Roll Ad
Use Cases
- Pre-Roll Ad
- Mid-Roll Ad
- Standalone Ad
- Ad Pod
Ad shown before video content starts:
Tracking Ad Interactions
Click Tracking
Skip Tracking
Error Tracking
Troubleshooting
VideoAdCompletion Not Tracked
VideoAdCompletion Not Tracked
Problem: VideoAdCompletion events not appearing.Cause:
completion() not called.Solution: Always call completion() when ad finishes:Ad and Video Using Same ID
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:
Engagement Time Incorrect
Engagement Time Incorrect
Problem: Engaged time is wrong.Causes:
- Not calling
play()when ad starts - Not calling
pause()for buffering
Multiple Completion Events
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.Best Practices
- Do
- Don't
- Always call
completion()when ad finishes - Track play/pause accurately
- Use
clicked()for click tracking - Create from MediaTracker for in-content ads
- Provide campaign and creative IDs
- Call
play()immediately if ad auto-plays
Related Documentation
Video Tracking
Track video content
Event Properties
Custom properties
Page Tracking
Track pages
Issues
Solve common issues
API Reference
For complete API documentation, see the Javadocs.AdTracker Interface
play()- Start/resume ad playbackplay(positionMs: Long)- Start at specific positionpause()- Pause ad playbackclicked()- Track ad click (sends VideoAdClicked event)completion()- Complete ad tracking (sends VideoAdCompletion event)trackWithAdProperties(eventName: String)- Track custom event with ad propertiestrackWithAdProperties(eventName: String, customProperties: EventProperties)- Track custom event with ad and custom properties
Creating AdTracker
MediaTracker.trackAdView(durationMs, adProperties, customEventProperties)- Create from MediaTracker (shares View ID)Permutive.trackVideoAdView(durationMs, adProperties, customEventProperties)- Create standalone AdTracker
AdProperties
AdTracker.AdProperties(title, durationInSeconds, isMuted, campaignId, creativeId)- Ad property container