unified-video-framework 1.4.159 → 1.4.160

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.
@@ -1,324 +0,0 @@
1
- /**
2
- * Example: Dynamic Analytics Integration
3
- * Shows how to integrate your existing player analytics API with the video framework
4
- */
5
-
6
- import {
7
- DynamicAnalyticsManager,
8
- createDynamicAnalyticsManager,
9
- createPlayerAnalyticsProviderConfig,
10
- AnalyticsProviderType,
11
- DynamicAnalyticsConfig
12
- } from '../index';
13
-
14
- // Example 1: Basic Player Analytics Integration
15
- export function createBasicPlayerAnalytics() {
16
- const config: DynamicAnalyticsConfig = {
17
- enabled: true,
18
- providers: [
19
- {
20
- name: 'flicknexs-analytics',
21
- type: AnalyticsProviderType.PLAYER_ANALYTICS,
22
- enabled: true,
23
- priority: 1,
24
- config: createPlayerAnalyticsProviderConfig(
25
- 'https://api.flicknexs.com', // Your base URL
26
- 'your-api-key-here', // Your API key
27
- 'video-player-main', // Player ID
28
- {
29
- tenantId: 'flicknexs-tenant', // Optional tenant ID
30
- heartbeatInterval: 10, // 10 seconds
31
- batchSize: 10, // 10 events per batch
32
- flushInterval: 30 // 30 seconds
33
- }
34
- )
35
- }
36
- ],
37
- globalSettings: {
38
- enableConsoleLogging: true,
39
- enableErrorReporting: true,
40
- sessionTimeout: 60 // 60 minutes
41
- }
42
- };
43
-
44
- return createDynamicAnalyticsManager(config);
45
- }
46
-
47
- // Example 2: Multiple Analytics Providers
48
- export function createMultiProviderAnalytics() {
49
- const config: DynamicAnalyticsConfig = {
50
- enabled: true,
51
- providers: [
52
- // Primary: Your Player Analytics API
53
- {
54
- name: 'player-analytics',
55
- type: AnalyticsProviderType.PLAYER_ANALYTICS,
56
- enabled: true,
57
- priority: 1,
58
- config: createPlayerAnalyticsProviderConfig(
59
- process.env.ANALYTICS_BASE_URL || 'https://api.flicknexs.com',
60
- process.env.ANALYTICS_API_KEY || 'your-api-key',
61
- 'main-player',
62
- {
63
- tenantId: process.env.TENANT_ID,
64
- heartbeatInterval: 10,
65
- batchSize: 10,
66
- flushInterval: 30
67
- }
68
- )
69
- },
70
- // Secondary: Custom Analytics Provider (e.g., Google Analytics)
71
- {
72
- name: 'google-analytics',
73
- type: AnalyticsProviderType.CUSTOM,
74
- enabled: true,
75
- priority: 2,
76
- config: {
77
- factory: (config: any) => new CustomGoogleAnalyticsProvider(config),
78
- measurementId: 'G-XXXXXXXXXX',
79
- apiSecret: 'your-ga4-secret'
80
- }
81
- }
82
- ],
83
- globalSettings: {
84
- enableConsoleLogging: process.env.NODE_ENV !== 'production',
85
- enableErrorReporting: true,
86
- sessionTimeout: 90 // 90 minutes
87
- }
88
- };
89
-
90
- return createDynamicAnalyticsManager(config);
91
- }
92
-
93
- // Example 3: Usage with Video Player
94
- export class VideoPlayerWithAnalytics {
95
- private analyticsManager: DynamicAnalyticsManager;
96
- private currentVideoInfo: any = null;
97
-
98
- constructor(analyticsConfig: DynamicAnalyticsConfig) {
99
- this.analyticsManager = createDynamicAnalyticsManager(analyticsConfig);
100
- this.setupAnalyticsEvents();
101
- }
102
-
103
- public loadVideo(videoInfo: {
104
- id: string;
105
- title: string;
106
- type: 'video' | 'series' | 'episode' | 'live';
107
- duration: number;
108
- url: string;
109
- isLive?: boolean;
110
- metadata?: Record<string, any>;
111
- }): void {
112
- this.currentVideoInfo = videoInfo;
113
-
114
- // Start analytics session
115
- const sessionId = this.analyticsManager.startSession(videoInfo, {
116
- userId: this.getCurrentUserId(),
117
- appVersion: '1.0.0',
118
- platform: 'web'
119
- });
120
-
121
- console.log(`Started analytics session: ${sessionId}`);
122
- }
123
-
124
- public play(): void {
125
- // Your player play logic here
126
- // ...
127
-
128
- // Track analytics
129
- this.analyticsManager.trackEvent('play', this.getPlayerState());
130
- }
131
-
132
- public pause(): void {
133
- // Your player pause logic here
134
- // ...
135
-
136
- // Track analytics
137
- this.analyticsManager.trackEvent('pause', this.getPlayerState());
138
- }
139
-
140
- public seek(time: number): void {
141
- const currentTime = this.getPlayerState().currentTime;
142
-
143
- // Your player seek logic here
144
- // ...
145
-
146
- // Track analytics
147
- this.analyticsManager.trackEvent('seeking', this.getPlayerState(), {
148
- seekFrom: currentTime,
149
- seekTo: time
150
- });
151
- }
152
-
153
- public onError(error: any): void {
154
- // Track error
155
- this.analyticsManager.trackCustomEvent('error', {
156
- errorCode: error.code,
157
- errorMessage: error.message,
158
- errorType: 'player_error',
159
- currentTime: this.getPlayerState().currentTime
160
- });
161
- }
162
-
163
- public onQualityChange(newQuality: string, previousQuality: string): void {
164
- this.analyticsManager.trackCustomEvent('quality_change', {
165
- newQuality,
166
- previousQuality,
167
- reason: 'user_selected'
168
- });
169
- }
170
-
171
- public onChapterSkip(chapterId: string, chapterType: string): void {
172
- this.analyticsManager.trackCustomEvent('custom_chapter_skip', {
173
- chapterId,
174
- chapterType,
175
- skipReason: 'manual'
176
- });
177
- }
178
-
179
- public destroy(): void {
180
- // End analytics session before destroying
181
- this.analyticsManager.endSession();
182
- this.analyticsManager.destroy();
183
- }
184
-
185
- private setupAnalyticsEvents(): void {
186
- // Listen to analytics events
187
- this.analyticsManager.on('sessionStart', (data) => {
188
- console.log('Analytics session started:', data);
189
- });
190
-
191
- this.analyticsManager.on('sessionEnd', (data) => {
192
- console.log('Analytics session ended:', data);
193
- });
194
-
195
- this.analyticsManager.on('error', (error) => {
196
- console.error('Analytics error:', error);
197
- });
198
- }
199
-
200
- private getPlayerState(): any {
201
- // Return current player state
202
- // This should come from your actual player implementation
203
- return {
204
- currentTime: 120, // current playback time in seconds
205
- duration: 3600, // total duration in seconds
206
- volume: 0.8, // volume level 0-1
207
- muted: false, // is muted
208
- paused: false, // is paused
209
- ended: false, // has ended
210
- fullscreen: false, // is fullscreen
211
- playbackRate: 1, // playback rate
212
- qualityLevel: '1080p', // current quality
213
- buffered: null, // buffered ranges
214
- seekable: null, // seekable ranges
215
- networkState: 2, // network state
216
- readyState: 4 // ready state
217
- };
218
- }
219
-
220
- private getCurrentUserId(): string {
221
- // Get current user ID from your auth system
222
- return 'user123';
223
- }
224
- }
225
-
226
- // Example 4: Custom Analytics Provider Implementation
227
- class CustomGoogleAnalyticsProvider {
228
- private config: any;
229
- private sessionId: string | null = null;
230
-
231
- constructor(config: any) {
232
- this.config = config;
233
- }
234
-
235
- startSession(videoInfo: any, customData?: any): string {
236
- this.sessionId = `ga_${Date.now()}`;
237
-
238
- // Send to Google Analytics
239
- gtag('event', 'video_start', {
240
- video_title: videoInfo.title,
241
- video_id: videoInfo.id,
242
- custom_parameter_1: customData?.userId
243
- });
244
-
245
- return this.sessionId;
246
- }
247
-
248
- async endSession(): Promise<void> {
249
- if (this.sessionId) {
250
- gtag('event', 'video_end', {
251
- session_id: this.sessionId
252
- });
253
- this.sessionId = null;
254
- }
255
- }
256
-
257
- trackEvent(event: any, playerState?: any, videoInfo?: any): void {
258
- gtag('event', `video_${event.eventType}`, {
259
- video_id: event.videoId,
260
- current_time: event.currentTime,
261
- session_id: this.sessionId
262
- });
263
- }
264
-
265
- trackCustomEvent(eventType: string, data?: any): void {
266
- gtag('event', eventType, {
267
- ...data,
268
- session_id: this.sessionId
269
- });
270
- }
271
-
272
- async flush(): Promise<void> {
273
- // Google Analytics doesn't require explicit flushing
274
- }
275
-
276
- getCurrentSession(): any {
277
- return { sessionId: this.sessionId };
278
- }
279
-
280
- destroy(): void {
281
- this.sessionId = null;
282
- }
283
- }
284
-
285
- // Example 5: Environment-based Configuration
286
- export function createEnvironmentAnalytics() {
287
- const isDevelopment = process.env.NODE_ENV === 'development';
288
- const isProduction = process.env.NODE_ENV === 'production';
289
-
290
- const config: DynamicAnalyticsConfig = {
291
- enabled: !isDevelopment || process.env.ENABLE_DEV_ANALYTICS === 'true',
292
- providers: [
293
- {
294
- name: 'player-analytics',
295
- type: AnalyticsProviderType.PLAYER_ANALYTICS,
296
- enabled: true,
297
- priority: 1,
298
- config: createPlayerAnalyticsProviderConfig(
299
- process.env.ANALYTICS_BASE_URL || 'https://api.flicknexs.com',
300
- process.env.ANALYTICS_API_KEY || '',
301
- process.env.PLAYER_ID || 'default-player',
302
- {
303
- tenantId: process.env.TENANT_ID,
304
- heartbeatInterval: isDevelopment ? 5 : 10, // More frequent in dev
305
- batchSize: isDevelopment ? 5 : 10, // Smaller batches in dev
306
- flushInterval: isDevelopment ? 15 : 30 // More frequent flushing in dev
307
- }
308
- )
309
- }
310
- ],
311
- globalSettings: {
312
- enableConsoleLogging: isDevelopment,
313
- enableErrorReporting: true,
314
- sessionTimeout: isProduction ? 120 : 30 // Longer timeout in production
315
- }
316
- };
317
-
318
- return createDynamicAnalyticsManager(config);
319
- }
320
-
321
- // Global gtag function declaration for TypeScript
322
- declare global {
323
- function gtag(...args: any[]): void;
324
- }
@@ -1,60 +0,0 @@
1
- /**
2
- * Video Player Analytics - Main module exports
3
- * Comprehensive analytics tracking for video players with dynamic provider support
4
- */
5
-
6
- // Core classes
7
- export { PlayerAnalytics } from './core/PlayerAnalytics';
8
- export { EventBatcher } from './core/EventBatcher';
9
- export { AnalyticsProvider, createAnalyticsProvider, getDefaultAnalyticsConfig } from './core/AnalyticsProvider';
10
-
11
- // Dynamic Analytics System
12
- export {
13
- DynamicAnalyticsManager,
14
- createDynamicAnalyticsManager,
15
- createPlayerAnalyticsProviderConfig,
16
- AnalyticsProviderType
17
- } from './core/DynamicAnalyticsManager';
18
- export type {
19
- BaseAnalyticsProvider,
20
- DynamicAnalyticsConfig
21
- } from './core/DynamicAnalyticsManager';
22
-
23
- // Analytics Adapters
24
- export {
25
- PlayerAnalyticsAdapter,
26
- createPlayerAnalyticsAdapter
27
- } from './adapters/PlayerAnalyticsAdapter';
28
- export type {
29
- PlayerAnalyticsConfig,
30
- AnalyticsSession,
31
- VideoInfo,
32
- DeviceData,
33
- PlayerData,
34
- EngagementData,
35
- ErrorData,
36
- AnalyticsEventData,
37
- AnalyticsPayload
38
- } from './adapters/PlayerAnalyticsAdapter';
39
-
40
- // Types and interfaces
41
- export * from './types/AnalyticsTypes';
42
-
43
- // Utilities
44
- export { DeviceDetection, deviceDetection } from './utils/DeviceDetection';
45
-
46
- // Re-export commonly used types for convenience
47
- export type {
48
- AnalyticsEvent,
49
- PlayerSessionInfo,
50
- AnalyticsConfig,
51
- DeviceInfo,
52
- PlayerState,
53
- PlayerEventType,
54
- UserInteractionType,
55
- QualityLevel,
56
- VideoType,
57
- AnalyticsEventHandler,
58
- UseAnalyticsReturn,
59
- AnalyticsContextValue
60
- } from './types/AnalyticsTypes';