Livestream Analytics
The social.plus Video SDK provides comprehensive analytics capabilities for tracking viewer engagement and watch time during live and recorded room playback. This feature enables you to collect valuable insights about how users interact with your video content.Overview
Watch Session Tracking
Track viewer watch time
- Create watch sessions for viewers
- Separate tracking for live and recorded content
Network Resilient Sync
Reliable data collection
- Local persistence of analytics data
- Automatic sync with jitter delay
- Network-aware retry logic
Key Concepts
Watch Sessions
A watch session represents a period of time during which a viewer is actively watching a room. Key characteristics:- Unique Session IDs: Each session has a unique identifier with prefixes indicating content type
room_prefix for live room watchingroom_playback_prefix for recorded content
Getting Started
API Reference
AmityRoom Extension
TheAmityRoom class is extended with an analytics capability:
AmityRoomAnalytics
The main class for managing room analytics operations:createWatchSession
createWatchSession
Create a new watch session for the current roomCreates a unique watch session to track viewer engagement. The session ID format depends on the room status:
Returns:
- Live rooms:
room_<unique-id> - Recorded rooms:
room_playback_<unique-id>
| Parameter | Type | Required | Description |
|---|---|---|---|
startedAt | Date | Yes | The timestamp when watching started |
Promise<String> - Unique session identifierThrows: BusinessException if room is not in watchable state (not LIVE or RECORDED)updateWatchSession
updateWatchSession
Update an existing watch session with durationUpdates the watch session with the current accumulated watch time. Call this periodically (recommended: every 1 second) while the viewer is actively watching.Parameters:
Returns:
| Parameter | Type | Required | Description |
|---|---|---|---|
sessionId | String | Yes | The unique identifier of the watch session |
duration | Number | Yes | The total watch duration in seconds |
endedAt | Date | Yes | The timestamp when this update occurred |
Promise<void>syncPendingWatchSessions
syncPendingWatchSessions
Sync all pending watch sessions to backendTriggers synchronization of all locally stored watch sessions that haven’t been synced yet.Returns:
voidBest Practices
Session Creation
Session Creation
When to create sessions:
- Create a session when a viewer enters the room player page
- Only create for actual viewers (not hosts or co-hosts)
- Only create for LIVE or RECORDED rooms
- Prevent duplicate sessions by tracking the current room ID
Duration Tracking
Duration Tracking
Accurate time tracking:
- Only count time when video is actively playing
- Pause tracking during buffering states
- Use accumulated time + elapsed since last resume for accurate totals
Sync Timing
Sync Timing
When to sync:
- ✅ When user leaves the room player page
- ✅ When user transitions from viewer to co-host
- ❌ Do NOT sync on video pause
- ❌ Do NOT sync on app background
Role Transitions
Role Transitions
Handle viewer ↔ co-host transitions:
- When becoming a co-host: Stop tracking and sync immediately
- When returning to viewer: Create a fresh new session
- Never reuse session IDs across role transitions
Error Handling
Common Errors
| Error | Cause | Solution |
|---|---|---|
BusinessException: room is not in watchable state | Attempting to create session for room that is not LIVE or RECORDED | Check room status before creating session |