Skip to main content
The MediaTracker API allows you to track video content events with Permutive. Use this for tracking video playback, engagement, and completion metrics.

Basic Usage

Properties

Use Cases

Ad Tracking

Connected TV IntegrationVideo event tracking described below is available once the connected TV integration has been enabled. Please contact your Customer Success Manager (CSM) to enable this feature.

Overview

MediaTracker provides comprehensive video tracking capabilities:
  • Automatic lifecycle tracking - Tracks Videoview and VideoCompletion events
  • Engagement metrics - Measures time spent watching and completion percentage
  • Custom events - Track custom video-related events
  • Rich metadata - Support for extensive video properties

Video Events

MediaTracker automatically tracks two event types:

1. Videoview Event

Tracked when MediaTracker is created:

2. VideoCompletion Event

Tracked when video is stopped:
📘 Note The aggregations.VideoEngagement.completion property requires a known duration to be set. Pass durationMilliseconds when creating the MediaTracker.

Basic Usage

Creating a MediaTracker

Create a MediaTracker when video playback begins:

MediaTracker Lifecycle

Expected Usage Flow

  1. Create MediaTracker instance with properties
  2. Call play() when playback begins
  3. Track buffering with pause() / play()
  4. Track scrubbing with play(position)
  5. Call stop() when playback completes
⚠️ Single Instance Limitation Only a single instance of PageTracker or MediaTracker is available at any time. Close existing trackers before creating new ones.

Playback Control Methods

play()

Call when video starts playing:

play(positionMs)

Call when playback position changes (e.g., seeking):

pause()

Call when video is paused or buffering:

stop()

Call when video playback completes or user exits:
⚠️ Important: Always Call stop() Failing to call stop() will prevent VideoCompletion events from being tracked.

Video Properties

Standard Video Properties

The SDK provides standard video properties for consistent tracking:

Property Reference

These are the Kotlin SDK parameter names. The SDK maps them to the snake_case event schema and nests them under the video parent automatically.
💡 Best Practice Track as many properties as possible to enable richer cohort creation and insights.

Page Properties (Optional)

If the video is displayed within a page context (e.g., embedded in article), include page properties:

PageProperties Reference


Custom Properties

Add custom properties specific to your event schema:

Complete Example


Tracking Custom Events

Track custom video-related events using the track() method:

Video Ad Tracking

If you need to track video ads within video content, use the AdTracker API:
See Video Ad Tracking for complete documentation.

Use Cases


Troubleshooting

Problem: VideoCompletion events not appearing.Cause: stop() not called.Solution: Always call stop() in onDestroy():
Problem: Engaged time is inaccurate.Causes:
  1. Not calling play() when video plays
  2. Not calling pause() when video pauses/buffers
Solution: Track all play/pause events:
Problem: completion property is missing or null.Cause: Duration not provided when creating MediaTracker.Solution: Always provide durationMilliseconds:
Problem: Error about multiple trackers.Cause: Creating new PageTracker or MediaTracker without closing existing one.Solution: Close existing tracker first:
See Common Errors for more troubleshooting.

Best Practices

  • Always call stop() when video finishes
  • Provide duration for completion tracking
  • Track play/pause events accurately
  • Include as many video properties as possible
  • Close tracker before creating a new one
  • Track buffering with pause/play

Video Ad Tracking

Track video advertisements

Page Tracking

Track non-video content

Event Properties

Custom properties

Issues

Solve common issues

API Reference

For complete API documentation, see the Javadocs.

MediaTracker Interface

  • play() - Start/resume video playback
  • play(positionMs: Long) - Start at specific position
  • pause() - Pause video playback
  • stop() - Complete video tracking (sends VideoCompletion)
  • setDuration(durationMs: Long) - Update video duration
  • track(eventName: String) - Track custom event
  • track(eventName: String, properties: EventProperties) - Track custom event with properties
  • trackAdView(...) - Create AdTracker for video ad

Creating MediaTracker

  • Permutive.trackVideoView(durationMilliseconds, videoProperties, pageProperties, customEventProperties) - Create MediaTracker