PageTracker is the recommended approach for tracking user interactions in your iOS and tvOS apps. It automatically generates Pageview events, measures engagement time, and enables contextual cohorts when URLs are provided.
Lifecycle
Events
Engagement
Overview
PageTracker provides:
- Automatic
Pageviewevents on first resume - Engagement time tracking between resume and pause
PageViewCompleteevents when stopped- Contextual cohort generation when URLs are provided
- Linked event tracking with consistent view IDs
Creating a PageTracker
PageTracker Lifecycle
State Diagram
Lifecycle Methods
UIViewController Integration
SwiftUI Integration
For SwiftUI, useonAppear and onDisappear modifiers:
Tracking Events
Track additional events linked to the current page view:Events tracked via
PageTracker.track() include the same Context and view ID as the Pageview event, enabling linked analysis.Engagement Tracking
Scroll Depth
Track how much content users have viewed:Engagement Time
Engagement time is automatically tracked:- Timer starts when
resume()is called - Timer pauses when
pause()is called - Total engagement time sent with
PageViewCompleteevent
Context Object
TheContext object provides page metadata:
Background Handling
The SDK automatically handles app backgrounding:tvOS Considerations
tvOS Note: PageTracker works identically on tvOS. Use focus-based navigation events instead of touch-based scrolling for engagement tracking.
Error Handling
Best Practices
- Do
- Don't
- Create PageTracker in
viewDidLoad - Call
resume()inviewDidAppear - Call
pause()inviewDidDisappear - Call
stop()indeinit - Always provide URLs for contextual targeting
- Track meaningful events with descriptive names
- Update scroll percentage as user scrolls
Troubleshooting
Pageview event not firing
Pageview event not firing
Problem: No Pageview event in logs.Solutions:
- Ensure
resume()is called after creating the PageTracker - Check that SDK is initialized before creating PageTracker
- Verify no errors when creating PageTracker
- Enable debug logging:
options.logModes = LogMode.all
Previous PageTracker stopped unexpectedly
Previous PageTracker stopped unexpectedly
Problem: PageTracker stops when navigating.Cause: Creating a new PageTracker stops any existing one.Solution: This is expected behavior. Only one tracker can be active. Stop the previous tracker explicitly if needed, or let the new one replace it.
Events rejected
Events rejected
Problem: Events tracked via PageTracker are rejected.Solutions:
- Check event names match your schema
- Verify property names and types
- Enable debug logging to see schema errors
Related Documentation
Event Tracking
Track custom events
Contextual Data
Content-based targeting
Google Ad Manager
Ad targeting with PageTracker
Event Properties
Structuring event data