@scarlett-player/analytics 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +473 -0
- package/dist/index.cjs +609 -0
- package/dist/index.d.cts +269 -0
- package/dist/index.d.ts +269 -0
- package/dist/index.js +582 -0
- package/package.json +62 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { Plugin } from '@scarlett-player/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Analytics Plugin Type Definitions
|
|
5
|
+
*
|
|
6
|
+
* Type-safe analytics events, metrics, and configuration for Scarlett Player.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Analytics event types.
|
|
10
|
+
*/
|
|
11
|
+
type AnalyticsEventType = 'viewStart' | 'viewEnd' | 'playRequest' | 'videoStart' | 'heartbeat' | 'pause' | 'seeking' | 'rebufferStart' | 'rebufferEnd' | 'qualityChange' | 'error';
|
|
12
|
+
/**
|
|
13
|
+
* Viewer plan/subscription type.
|
|
14
|
+
*/
|
|
15
|
+
type ViewerPlan = 'free' | 'ppv' | 'subscriber' | 'premium' | string;
|
|
16
|
+
/**
|
|
17
|
+
* Exit type enumeration.
|
|
18
|
+
*/
|
|
19
|
+
type ExitType = 'completed' | 'abandoned' | 'error' | 'background' | null;
|
|
20
|
+
/**
|
|
21
|
+
* Playback state for session tracking.
|
|
22
|
+
*/
|
|
23
|
+
type SessionPlaybackState = 'loading' | 'playing' | 'paused' | 'ended' | 'error';
|
|
24
|
+
/**
|
|
25
|
+
* Device type enumeration.
|
|
26
|
+
*/
|
|
27
|
+
type DeviceType = 'desktop' | 'mobile' | 'tablet' | 'tv' | 'unknown';
|
|
28
|
+
/**
|
|
29
|
+
* Analytics plugin configuration.
|
|
30
|
+
*/
|
|
31
|
+
interface AnalyticsConfig {
|
|
32
|
+
/** Your API endpoint for receiving analytics beacons */
|
|
33
|
+
beaconUrl: string;
|
|
34
|
+
/** Optional API key for authentication */
|
|
35
|
+
apiKey?: string;
|
|
36
|
+
/** Unique video identifier (required) */
|
|
37
|
+
videoId: string;
|
|
38
|
+
/** Human-readable video title */
|
|
39
|
+
videoTitle?: string;
|
|
40
|
+
/** Video series/collection name */
|
|
41
|
+
videoSeries?: string;
|
|
42
|
+
/** Total video duration in seconds (if known) */
|
|
43
|
+
videoDuration?: number;
|
|
44
|
+
/** Whether this is live content */
|
|
45
|
+
isLive?: boolean;
|
|
46
|
+
/** Unique viewer identifier (auto-generated if not provided) */
|
|
47
|
+
viewerId?: string;
|
|
48
|
+
/** Viewer's plan/subscription type */
|
|
49
|
+
viewerPlan?: ViewerPlan;
|
|
50
|
+
/** Additional custom dimensions to include with all events */
|
|
51
|
+
customDimensions?: Record<string, string | number | boolean>;
|
|
52
|
+
/** Heartbeat interval in milliseconds (default: 10000) */
|
|
53
|
+
heartbeatInterval?: number;
|
|
54
|
+
/** Error sampling rate 0-1 (default: 1.0 = 100%) */
|
|
55
|
+
errorSampleRate?: number;
|
|
56
|
+
/** Disable analytics in development (default: false) */
|
|
57
|
+
disableInDev?: boolean;
|
|
58
|
+
/** Custom beacon transport function (for testing) */
|
|
59
|
+
customBeacon?: BeaconFunction;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Bitrate/quality change event.
|
|
63
|
+
*/
|
|
64
|
+
interface BitrateChange {
|
|
65
|
+
/** Timestamp when bitrate changed */
|
|
66
|
+
time: number;
|
|
67
|
+
/** New bitrate in bits per second */
|
|
68
|
+
bitrate: number;
|
|
69
|
+
/** Video width in pixels */
|
|
70
|
+
width: number;
|
|
71
|
+
/** Video height in pixels */
|
|
72
|
+
height: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Error event details.
|
|
76
|
+
*/
|
|
77
|
+
interface ErrorEvent {
|
|
78
|
+
/** Timestamp when error occurred */
|
|
79
|
+
time: number;
|
|
80
|
+
/** Error type/category */
|
|
81
|
+
type: string;
|
|
82
|
+
/** Error message */
|
|
83
|
+
message: string;
|
|
84
|
+
/** Whether error was fatal (stopped playback) */
|
|
85
|
+
fatal: boolean;
|
|
86
|
+
/** Optional error code */
|
|
87
|
+
code?: string | number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* View session data - tracks a single viewing attempt.
|
|
91
|
+
*/
|
|
92
|
+
interface ViewSession {
|
|
93
|
+
/** Unique view ID (one per playback attempt) */
|
|
94
|
+
viewId: string;
|
|
95
|
+
/** Session ID (persists across views in same browsing session) */
|
|
96
|
+
sessionId: string;
|
|
97
|
+
/** Viewer ID (persists across sessions) */
|
|
98
|
+
viewerId: string;
|
|
99
|
+
/** When view started (player initialized) */
|
|
100
|
+
viewStart: number;
|
|
101
|
+
/** When play was requested (user clicked play) */
|
|
102
|
+
playRequestTime: number | null;
|
|
103
|
+
/** When first frame rendered */
|
|
104
|
+
firstFrameTime: number | null;
|
|
105
|
+
/** When view ended */
|
|
106
|
+
viewEnd: number | null;
|
|
107
|
+
/** Total time from viewStart to viewEnd (ms) */
|
|
108
|
+
watchTime: number;
|
|
109
|
+
/** Actual playback time (excludes rebuffer/pause) (ms) */
|
|
110
|
+
playTime: number;
|
|
111
|
+
/** Number of times user paused */
|
|
112
|
+
pauseCount: number;
|
|
113
|
+
/** Total time spent paused (ms) */
|
|
114
|
+
pauseDuration: number;
|
|
115
|
+
/** Number of seek operations */
|
|
116
|
+
seekCount: number;
|
|
117
|
+
/** Time from play request to first frame (ms) */
|
|
118
|
+
startupTime: number | null;
|
|
119
|
+
/** Number of rebuffer events */
|
|
120
|
+
rebufferCount: number;
|
|
121
|
+
/** Total rebuffer time (ms) */
|
|
122
|
+
rebufferDuration: number;
|
|
123
|
+
/** Number of errors encountered */
|
|
124
|
+
errorCount: number;
|
|
125
|
+
/** Array of error events */
|
|
126
|
+
errors: ErrorEvent[];
|
|
127
|
+
/** History of bitrate changes */
|
|
128
|
+
bitrateHistory: BitrateChange[];
|
|
129
|
+
/** Number of quality level changes */
|
|
130
|
+
qualityChanges: number;
|
|
131
|
+
/** Maximum bitrate achieved (bps) */
|
|
132
|
+
maxBitrate: number;
|
|
133
|
+
/** Average bitrate during playback (bps) */
|
|
134
|
+
avgBitrate: number;
|
|
135
|
+
/** Current playback state */
|
|
136
|
+
playbackState: SessionPlaybackState;
|
|
137
|
+
/** How the view ended */
|
|
138
|
+
exitType: ExitType;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Beacon payload structure sent to analytics endpoint.
|
|
142
|
+
*/
|
|
143
|
+
interface BeaconPayload {
|
|
144
|
+
/** Event type */
|
|
145
|
+
event: AnalyticsEventType | string;
|
|
146
|
+
/** Event timestamp */
|
|
147
|
+
timestamp: number;
|
|
148
|
+
/** Current view ID */
|
|
149
|
+
viewId: string;
|
|
150
|
+
/** Current session ID */
|
|
151
|
+
sessionId: string;
|
|
152
|
+
/** Viewer ID */
|
|
153
|
+
viewerId: string;
|
|
154
|
+
/** Video ID */
|
|
155
|
+
videoId: string;
|
|
156
|
+
/** Video title */
|
|
157
|
+
videoTitle?: string;
|
|
158
|
+
/** Whether video is live */
|
|
159
|
+
isLive?: boolean;
|
|
160
|
+
/** Player version */
|
|
161
|
+
playerVersion: string;
|
|
162
|
+
/** Player name */
|
|
163
|
+
playerName: string;
|
|
164
|
+
/** Browser name */
|
|
165
|
+
browser: string;
|
|
166
|
+
/** Operating system */
|
|
167
|
+
os: string;
|
|
168
|
+
/** Device type */
|
|
169
|
+
deviceType: DeviceType;
|
|
170
|
+
/** Screen resolution */
|
|
171
|
+
screenSize: string;
|
|
172
|
+
/** Player size */
|
|
173
|
+
playerSize: string;
|
|
174
|
+
/** Network connection type */
|
|
175
|
+
connectionType: string;
|
|
176
|
+
/** Any custom dimensions from config */
|
|
177
|
+
[key: string]: unknown;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Custom beacon transport function.
|
|
181
|
+
*/
|
|
182
|
+
type BeaconFunction = (url: string, payload: BeaconPayload) => void | Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Public API exposed by Analytics plugin.
|
|
185
|
+
*/
|
|
186
|
+
interface IAnalyticsPlugin {
|
|
187
|
+
/** Plugin metadata */
|
|
188
|
+
readonly id: string;
|
|
189
|
+
readonly name: string;
|
|
190
|
+
readonly version: string;
|
|
191
|
+
readonly type: 'analytics';
|
|
192
|
+
/** Initialize plugin */
|
|
193
|
+
init(api: unknown, config?: Partial<AnalyticsConfig>): void | Promise<void>;
|
|
194
|
+
/** Destroy plugin */
|
|
195
|
+
destroy(): void | Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Get current view ID.
|
|
198
|
+
* @returns Current view ID
|
|
199
|
+
*/
|
|
200
|
+
getViewId(): string;
|
|
201
|
+
/**
|
|
202
|
+
* Get current session ID.
|
|
203
|
+
* @returns Current session ID
|
|
204
|
+
*/
|
|
205
|
+
getSessionId(): string;
|
|
206
|
+
/**
|
|
207
|
+
* Get calculated QoE score (0-100).
|
|
208
|
+
* @returns Quality of Experience score
|
|
209
|
+
*/
|
|
210
|
+
getQoEScore(): number;
|
|
211
|
+
/**
|
|
212
|
+
* Get current metrics/session data.
|
|
213
|
+
* @returns Partial view session data
|
|
214
|
+
*/
|
|
215
|
+
getMetrics(): Partial<ViewSession>;
|
|
216
|
+
/**
|
|
217
|
+
* Track a custom event.
|
|
218
|
+
* @param name - Event name
|
|
219
|
+
* @param data - Event data
|
|
220
|
+
*/
|
|
221
|
+
trackEvent(name: string, data?: Record<string, unknown>): void;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Analytics Plugin for Scarlett Player
|
|
226
|
+
*
|
|
227
|
+
* Collects Quality of Experience (QoE) metrics and engagement data.
|
|
228
|
+
* Designed for live event monitoring and viewer analytics.
|
|
229
|
+
*
|
|
230
|
+
* Features:
|
|
231
|
+
* - QoE metrics (startup time, rebuffering, errors)
|
|
232
|
+
* - Engagement tracking (watch time, pause/seek behavior)
|
|
233
|
+
* - Quality tracking (bitrate changes, quality levels)
|
|
234
|
+
* - Custom event tracking
|
|
235
|
+
* - Automatic heartbeat reporting
|
|
236
|
+
* - Persistent viewer identification
|
|
237
|
+
*/
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Create an Analytics Plugin instance.
|
|
241
|
+
*
|
|
242
|
+
* @param config - Plugin configuration
|
|
243
|
+
* @returns Analytics Plugin instance
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* import { createAnalyticsPlugin } from '@scarlett-player/analytics';
|
|
248
|
+
*
|
|
249
|
+
* const player = await createPlayer({
|
|
250
|
+
* container: '#player',
|
|
251
|
+
* src: 'video.m3u8',
|
|
252
|
+
* plugins: [
|
|
253
|
+
* hlsPlugin(),
|
|
254
|
+
* createAnalyticsPlugin({
|
|
255
|
+
* beaconUrl: 'https://api.example.com/analytics',
|
|
256
|
+
* videoId: 'event-123',
|
|
257
|
+
* videoTitle: 'Live Event',
|
|
258
|
+
* isLive: true,
|
|
259
|
+
* viewerId: user?.id,
|
|
260
|
+
* viewerPlan: 'ppv',
|
|
261
|
+
* }),
|
|
262
|
+
* uiPlugin(),
|
|
263
|
+
* ],
|
|
264
|
+
* });
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
declare function createAnalyticsPlugin(config: AnalyticsConfig): Plugin & IAnalyticsPlugin;
|
|
268
|
+
|
|
269
|
+
export { type AnalyticsConfig, type AnalyticsEventType, type BeaconPayload, type BitrateChange, type ErrorEvent, type IAnalyticsPlugin, type ViewSession, createAnalyticsPlugin, createAnalyticsPlugin as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { Plugin } from '@scarlett-player/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Analytics Plugin Type Definitions
|
|
5
|
+
*
|
|
6
|
+
* Type-safe analytics events, metrics, and configuration for Scarlett Player.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Analytics event types.
|
|
10
|
+
*/
|
|
11
|
+
type AnalyticsEventType = 'viewStart' | 'viewEnd' | 'playRequest' | 'videoStart' | 'heartbeat' | 'pause' | 'seeking' | 'rebufferStart' | 'rebufferEnd' | 'qualityChange' | 'error';
|
|
12
|
+
/**
|
|
13
|
+
* Viewer plan/subscription type.
|
|
14
|
+
*/
|
|
15
|
+
type ViewerPlan = 'free' | 'ppv' | 'subscriber' | 'premium' | string;
|
|
16
|
+
/**
|
|
17
|
+
* Exit type enumeration.
|
|
18
|
+
*/
|
|
19
|
+
type ExitType = 'completed' | 'abandoned' | 'error' | 'background' | null;
|
|
20
|
+
/**
|
|
21
|
+
* Playback state for session tracking.
|
|
22
|
+
*/
|
|
23
|
+
type SessionPlaybackState = 'loading' | 'playing' | 'paused' | 'ended' | 'error';
|
|
24
|
+
/**
|
|
25
|
+
* Device type enumeration.
|
|
26
|
+
*/
|
|
27
|
+
type DeviceType = 'desktop' | 'mobile' | 'tablet' | 'tv' | 'unknown';
|
|
28
|
+
/**
|
|
29
|
+
* Analytics plugin configuration.
|
|
30
|
+
*/
|
|
31
|
+
interface AnalyticsConfig {
|
|
32
|
+
/** Your API endpoint for receiving analytics beacons */
|
|
33
|
+
beaconUrl: string;
|
|
34
|
+
/** Optional API key for authentication */
|
|
35
|
+
apiKey?: string;
|
|
36
|
+
/** Unique video identifier (required) */
|
|
37
|
+
videoId: string;
|
|
38
|
+
/** Human-readable video title */
|
|
39
|
+
videoTitle?: string;
|
|
40
|
+
/** Video series/collection name */
|
|
41
|
+
videoSeries?: string;
|
|
42
|
+
/** Total video duration in seconds (if known) */
|
|
43
|
+
videoDuration?: number;
|
|
44
|
+
/** Whether this is live content */
|
|
45
|
+
isLive?: boolean;
|
|
46
|
+
/** Unique viewer identifier (auto-generated if not provided) */
|
|
47
|
+
viewerId?: string;
|
|
48
|
+
/** Viewer's plan/subscription type */
|
|
49
|
+
viewerPlan?: ViewerPlan;
|
|
50
|
+
/** Additional custom dimensions to include with all events */
|
|
51
|
+
customDimensions?: Record<string, string | number | boolean>;
|
|
52
|
+
/** Heartbeat interval in milliseconds (default: 10000) */
|
|
53
|
+
heartbeatInterval?: number;
|
|
54
|
+
/** Error sampling rate 0-1 (default: 1.0 = 100%) */
|
|
55
|
+
errorSampleRate?: number;
|
|
56
|
+
/** Disable analytics in development (default: false) */
|
|
57
|
+
disableInDev?: boolean;
|
|
58
|
+
/** Custom beacon transport function (for testing) */
|
|
59
|
+
customBeacon?: BeaconFunction;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Bitrate/quality change event.
|
|
63
|
+
*/
|
|
64
|
+
interface BitrateChange {
|
|
65
|
+
/** Timestamp when bitrate changed */
|
|
66
|
+
time: number;
|
|
67
|
+
/** New bitrate in bits per second */
|
|
68
|
+
bitrate: number;
|
|
69
|
+
/** Video width in pixels */
|
|
70
|
+
width: number;
|
|
71
|
+
/** Video height in pixels */
|
|
72
|
+
height: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Error event details.
|
|
76
|
+
*/
|
|
77
|
+
interface ErrorEvent {
|
|
78
|
+
/** Timestamp when error occurred */
|
|
79
|
+
time: number;
|
|
80
|
+
/** Error type/category */
|
|
81
|
+
type: string;
|
|
82
|
+
/** Error message */
|
|
83
|
+
message: string;
|
|
84
|
+
/** Whether error was fatal (stopped playback) */
|
|
85
|
+
fatal: boolean;
|
|
86
|
+
/** Optional error code */
|
|
87
|
+
code?: string | number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* View session data - tracks a single viewing attempt.
|
|
91
|
+
*/
|
|
92
|
+
interface ViewSession {
|
|
93
|
+
/** Unique view ID (one per playback attempt) */
|
|
94
|
+
viewId: string;
|
|
95
|
+
/** Session ID (persists across views in same browsing session) */
|
|
96
|
+
sessionId: string;
|
|
97
|
+
/** Viewer ID (persists across sessions) */
|
|
98
|
+
viewerId: string;
|
|
99
|
+
/** When view started (player initialized) */
|
|
100
|
+
viewStart: number;
|
|
101
|
+
/** When play was requested (user clicked play) */
|
|
102
|
+
playRequestTime: number | null;
|
|
103
|
+
/** When first frame rendered */
|
|
104
|
+
firstFrameTime: number | null;
|
|
105
|
+
/** When view ended */
|
|
106
|
+
viewEnd: number | null;
|
|
107
|
+
/** Total time from viewStart to viewEnd (ms) */
|
|
108
|
+
watchTime: number;
|
|
109
|
+
/** Actual playback time (excludes rebuffer/pause) (ms) */
|
|
110
|
+
playTime: number;
|
|
111
|
+
/** Number of times user paused */
|
|
112
|
+
pauseCount: number;
|
|
113
|
+
/** Total time spent paused (ms) */
|
|
114
|
+
pauseDuration: number;
|
|
115
|
+
/** Number of seek operations */
|
|
116
|
+
seekCount: number;
|
|
117
|
+
/** Time from play request to first frame (ms) */
|
|
118
|
+
startupTime: number | null;
|
|
119
|
+
/** Number of rebuffer events */
|
|
120
|
+
rebufferCount: number;
|
|
121
|
+
/** Total rebuffer time (ms) */
|
|
122
|
+
rebufferDuration: number;
|
|
123
|
+
/** Number of errors encountered */
|
|
124
|
+
errorCount: number;
|
|
125
|
+
/** Array of error events */
|
|
126
|
+
errors: ErrorEvent[];
|
|
127
|
+
/** History of bitrate changes */
|
|
128
|
+
bitrateHistory: BitrateChange[];
|
|
129
|
+
/** Number of quality level changes */
|
|
130
|
+
qualityChanges: number;
|
|
131
|
+
/** Maximum bitrate achieved (bps) */
|
|
132
|
+
maxBitrate: number;
|
|
133
|
+
/** Average bitrate during playback (bps) */
|
|
134
|
+
avgBitrate: number;
|
|
135
|
+
/** Current playback state */
|
|
136
|
+
playbackState: SessionPlaybackState;
|
|
137
|
+
/** How the view ended */
|
|
138
|
+
exitType: ExitType;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Beacon payload structure sent to analytics endpoint.
|
|
142
|
+
*/
|
|
143
|
+
interface BeaconPayload {
|
|
144
|
+
/** Event type */
|
|
145
|
+
event: AnalyticsEventType | string;
|
|
146
|
+
/** Event timestamp */
|
|
147
|
+
timestamp: number;
|
|
148
|
+
/** Current view ID */
|
|
149
|
+
viewId: string;
|
|
150
|
+
/** Current session ID */
|
|
151
|
+
sessionId: string;
|
|
152
|
+
/** Viewer ID */
|
|
153
|
+
viewerId: string;
|
|
154
|
+
/** Video ID */
|
|
155
|
+
videoId: string;
|
|
156
|
+
/** Video title */
|
|
157
|
+
videoTitle?: string;
|
|
158
|
+
/** Whether video is live */
|
|
159
|
+
isLive?: boolean;
|
|
160
|
+
/** Player version */
|
|
161
|
+
playerVersion: string;
|
|
162
|
+
/** Player name */
|
|
163
|
+
playerName: string;
|
|
164
|
+
/** Browser name */
|
|
165
|
+
browser: string;
|
|
166
|
+
/** Operating system */
|
|
167
|
+
os: string;
|
|
168
|
+
/** Device type */
|
|
169
|
+
deviceType: DeviceType;
|
|
170
|
+
/** Screen resolution */
|
|
171
|
+
screenSize: string;
|
|
172
|
+
/** Player size */
|
|
173
|
+
playerSize: string;
|
|
174
|
+
/** Network connection type */
|
|
175
|
+
connectionType: string;
|
|
176
|
+
/** Any custom dimensions from config */
|
|
177
|
+
[key: string]: unknown;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Custom beacon transport function.
|
|
181
|
+
*/
|
|
182
|
+
type BeaconFunction = (url: string, payload: BeaconPayload) => void | Promise<void>;
|
|
183
|
+
/**
|
|
184
|
+
* Public API exposed by Analytics plugin.
|
|
185
|
+
*/
|
|
186
|
+
interface IAnalyticsPlugin {
|
|
187
|
+
/** Plugin metadata */
|
|
188
|
+
readonly id: string;
|
|
189
|
+
readonly name: string;
|
|
190
|
+
readonly version: string;
|
|
191
|
+
readonly type: 'analytics';
|
|
192
|
+
/** Initialize plugin */
|
|
193
|
+
init(api: unknown, config?: Partial<AnalyticsConfig>): void | Promise<void>;
|
|
194
|
+
/** Destroy plugin */
|
|
195
|
+
destroy(): void | Promise<void>;
|
|
196
|
+
/**
|
|
197
|
+
* Get current view ID.
|
|
198
|
+
* @returns Current view ID
|
|
199
|
+
*/
|
|
200
|
+
getViewId(): string;
|
|
201
|
+
/**
|
|
202
|
+
* Get current session ID.
|
|
203
|
+
* @returns Current session ID
|
|
204
|
+
*/
|
|
205
|
+
getSessionId(): string;
|
|
206
|
+
/**
|
|
207
|
+
* Get calculated QoE score (0-100).
|
|
208
|
+
* @returns Quality of Experience score
|
|
209
|
+
*/
|
|
210
|
+
getQoEScore(): number;
|
|
211
|
+
/**
|
|
212
|
+
* Get current metrics/session data.
|
|
213
|
+
* @returns Partial view session data
|
|
214
|
+
*/
|
|
215
|
+
getMetrics(): Partial<ViewSession>;
|
|
216
|
+
/**
|
|
217
|
+
* Track a custom event.
|
|
218
|
+
* @param name - Event name
|
|
219
|
+
* @param data - Event data
|
|
220
|
+
*/
|
|
221
|
+
trackEvent(name: string, data?: Record<string, unknown>): void;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Analytics Plugin for Scarlett Player
|
|
226
|
+
*
|
|
227
|
+
* Collects Quality of Experience (QoE) metrics and engagement data.
|
|
228
|
+
* Designed for live event monitoring and viewer analytics.
|
|
229
|
+
*
|
|
230
|
+
* Features:
|
|
231
|
+
* - QoE metrics (startup time, rebuffering, errors)
|
|
232
|
+
* - Engagement tracking (watch time, pause/seek behavior)
|
|
233
|
+
* - Quality tracking (bitrate changes, quality levels)
|
|
234
|
+
* - Custom event tracking
|
|
235
|
+
* - Automatic heartbeat reporting
|
|
236
|
+
* - Persistent viewer identification
|
|
237
|
+
*/
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Create an Analytics Plugin instance.
|
|
241
|
+
*
|
|
242
|
+
* @param config - Plugin configuration
|
|
243
|
+
* @returns Analytics Plugin instance
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* import { createAnalyticsPlugin } from '@scarlett-player/analytics';
|
|
248
|
+
*
|
|
249
|
+
* const player = await createPlayer({
|
|
250
|
+
* container: '#player',
|
|
251
|
+
* src: 'video.m3u8',
|
|
252
|
+
* plugins: [
|
|
253
|
+
* hlsPlugin(),
|
|
254
|
+
* createAnalyticsPlugin({
|
|
255
|
+
* beaconUrl: 'https://api.example.com/analytics',
|
|
256
|
+
* videoId: 'event-123',
|
|
257
|
+
* videoTitle: 'Live Event',
|
|
258
|
+
* isLive: true,
|
|
259
|
+
* viewerId: user?.id,
|
|
260
|
+
* viewerPlan: 'ppv',
|
|
261
|
+
* }),
|
|
262
|
+
* uiPlugin(),
|
|
263
|
+
* ],
|
|
264
|
+
* });
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
declare function createAnalyticsPlugin(config: AnalyticsConfig): Plugin & IAnalyticsPlugin;
|
|
268
|
+
|
|
269
|
+
export { type AnalyticsConfig, type AnalyticsEventType, type BeaconPayload, type BitrateChange, type ErrorEvent, type IAnalyticsPlugin, type ViewSession, createAnalyticsPlugin, createAnalyticsPlugin as default };
|