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 Theaggregations.VideoEngagement.completionproperty requires a known duration to be set. Passduration(in seconds) when callingcreateVideoTracker(...).
Basic Usage
Creating a Video Tracker
Create a video tracker when playback begins. The iOS SDK does not auto-nest publisher properties undervideo like Android does — hand-build the nested EventProperties dictionary so the emitted event matches the canonical schema (video.title, video.content_type, …). See CTV Video Tracking for the full schema.
MediaTracker Lifecycle
Expected Usage Flow
- Create MediaTracker instance with properties
- Call
play()when playback begins - Track buffering with
pause()/play() - Track scrubbing with
play(position) - Call
stop()when playback completes
⚠️ Single Instance Limitation Only a single instance ofPageTrackerorMediaTrackeris available at any time. Creating a new tracker automatically stops any existing one.
Playback Control Methods
play()
Call when video starts playing:play(position:)
Call when playback position changes (e.g., seeking). Position is aTimeInterval in seconds.
pause()
Call when video is paused or buffering:stop()
Call when video playback completes or user exits:set(duration:)
Call to update the video duration if it wasn’t known when the tracker was created:
⚠️ Important: Always Call stop()
Failing to call stop() will prevent VideoCompletion events from being tracked.
Video Properties
The iOS SDK accepts an untypedEventProperties dictionary. Build the nested shape that matches the canonical schema — properties under a top-level video parent, in snake_case. There is no auto-mapping or auto-nesting like on Android.
Standard Video Properties
Schema Reference
💡 Best Practice Track as many properties as possible to enable richer cohort creation and insights.
Page Context (Optional)
If the video is displayed within a page context (e.g., embedded in an article), pass aContext to associate the tracker with that page:
Context Reference
Custom Properties
The iOS SDK does not take a separate “custom properties” parameter — add custom keys directly to the sameEventProperties dictionary, alongside the video schema fields. Custom keys are emitted at the top level of the event:
Complete Example
Tracking Custom Events
Track custom video-related events using thetrack(event:properties:) method. Both parameters are required (pass nil for properties if there are none).
Video Ad Tracking
Use Cases
Movie/TV App
Movie/TV App
Educational/Tutorial App
Educational/Tutorial App
Series/Episode Tracking
Series/Episode Tracking
tvOS Considerations
tvOS Note: MediaTracker works identically on tvOS. Use the same APIs with your TVUIKit video player or AVPlayerViewController.
Troubleshooting
VideoCompletion Not Tracked
VideoCompletion Not Tracked
Problem: VideoCompletion events not appearing.Cause:
stop() not called.Solution: Always call stop() in viewWillDisappear:Engagement Time Incorrect
Engagement Time Incorrect
Problem: Engaged time is inaccurate.Causes:
- Not calling
play()when video plays - Not calling
pause()when video pauses/buffers
Completion Percentage Missing
Completion Percentage Missing
Problem:
aggregations.VideoEngagement.completion is missing or nil.Cause: Duration not provided when creating the video tracker.Solution: Always provide duration (in seconds):Multiple Tracker Error
Multiple Tracker Error
Problem: Error about multiple trackers.Cause: Creating a new PageTracker or video tracker without closing the existing one.Solution: Close the existing tracker first:See Common Errors for more troubleshooting.
Best Practices
- Do
- Don't
- 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
Related Documentation
Video Ad Tracking
Track video advertisements
Page Tracking
Track non-video content
Event Properties
Custom properties
Issues
Solve common issues
API Reference
MediaTrackerProtocol
play()— Start/resume video playbackplay(position: TimeInterval)— Start at a specific position (seconds)pause()— Pause video playbackstop()— Complete video tracking (sendsVideoCompletion)set(duration: TimeInterval)— Update video duration (seconds), if it wasn’t known at creationtrack(event: String, properties: EventProperties?) throws— Track a custom event
Creating a Video Tracker
Permutive.shared.createVideoTracker(duration: TimeInterval, properties: EventProperties?, context: Context?) throws -> NSObject & MediaTrackerProtocol