tracking-lib-ott 1.0.13 → 1.0.14

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/dist/index.d.cts CHANGED
@@ -99,29 +99,20 @@ declare const getSessionDuration: () => number;
99
99
 
100
100
  type TrackingConfig = {
101
101
  baseURL: string;
102
- appName?: string;
103
- appId?: string;
104
- packageId?: string;
105
- platform?: "Web" | "Ios" | "Android" | string;
106
102
  debug?: boolean;
107
103
  sessionCookieConfig?: SessionCookieConfig;
108
- sessionId?: string;
104
+ appId: string;
105
+ packageId: string;
106
+ sessionId: string;
109
107
  sessionSign: string;
110
- userId: number;
111
108
  deviceId: string;
109
+ platform: "Android" | "Ios" | "WebPC" | "WebMobile" | "SmartTV" | "AndroidTV";
112
110
  deviceModel: string;
113
111
  deviceBrand: string;
114
- ipAddress: string;
112
+ events: any[];
115
113
  adId?: string;
116
- osVersion?: string;
117
- netType?: string;
118
- carrierNet?: string;
114
+ deviceOsVersion?: string;
119
115
  sdkVersion?: string;
120
- appVersion?: string;
121
- buildNumber?: string;
122
- language?: string;
123
- country?: string;
124
- events?: any[];
125
116
  };
126
117
  type PageInfo = {
127
118
  name: string;
@@ -129,6 +120,9 @@ type PageInfo = {
129
120
  };
130
121
  type PageMap = Record<string, PageInfo>;
131
122
  type EventData = Record<string, any>;
123
+ type UserInfo = {
124
+ userId: number;
125
+ };
132
126
  type NextRouterLike = {
133
127
  asPath: string;
134
128
  events: {
@@ -154,6 +148,11 @@ declare const defaultPageMap: PageMap;
154
148
  declare const initTracking: (options?: Partial<TrackingConfig> & {
155
149
  pageMap?: Partial<PageMap>;
156
150
  }) => void;
151
+ /**
152
+ * Cập nhật thông tin người dùng (userId)
153
+ * userId sẽ được tự động thêm vào mỗi event trong events array
154
+ */
155
+ declare const setUserInfo: (userInfo: UserInfo) => void;
157
156
  /**
158
157
  * Lấy thông tin page từ URL
159
158
  */
@@ -170,6 +169,247 @@ declare const trackPageView: (url: string) => void;
170
169
  * Track custom event
171
170
  */
172
171
  declare const trackEvent: (eventName: string, params?: EventData) => void;
172
+ /**
173
+ * Track view content details event
174
+ * @param contentId - ID của content (required)
175
+ * @param contentTitle - Tiêu đề content (required)
176
+ * @param contentType - Loại content: 0=VOD, 1=Event, 2=Channel (required)
177
+ * @param channelId - Mã kênh EPG (optional)
178
+ * @param eventTime - Timestamp Unix (optional, mặc định lấy time hiện tại)
179
+ */
180
+ declare const trackViewContentDetails: (contentId: string, contentTitle: string, contentType: 0 | 1 | 2, channelId?: string, eventTime?: number) => void;
181
+ /**
182
+ * Track playback started event
183
+ * @param params.contentId - ID của content (required)
184
+ * @param params.contentTitle - Tiêu đề content (required)
185
+ * @param params.contentType - Loại content: 0=VOD, 1=Live, 2=Channel (required)
186
+ * @param params.playbackSession - Session ID: MD5(content_id + start_timestamp) (required)
187
+ * @param params.videoQuality - Chất lượng video: 360p, 480p, 720p, 1080p, 2k, 4k (required)
188
+ * @param params.startTimestamp - Unix timestamp khi bắt đầu phát (required)
189
+ * @param params.startPosition - Vị trí bắt đầu: Live=0, VOD: 0 nếu mới, >0 nếu xem lại (required)
190
+ * @param params.duration - Thời lượng: Live=-1, VOD=số giây (required)
191
+ * @param params.channelId - Mã kênh EPG (optional)
192
+ * @param params.subContentId - ID chương trình trong kênh live (optional)
193
+ * @param params.subContentTitle - Title chương trình trong kênh live (optional)
194
+ * @param params.eventTime - Unix timestamp (optional)
195
+ */
196
+ declare const trackPlaybackStarted: (params: {
197
+ contentId: string;
198
+ contentTitle: string;
199
+ contentType: 0 | 1 | 2;
200
+ playbackSession: string;
201
+ videoQuality: "360p" | "480p" | "720p" | "1080p" | "2k" | "4k";
202
+ startTimestamp: number;
203
+ startPosition: number;
204
+ duration: number;
205
+ channelId?: string;
206
+ subContentId?: string;
207
+ subContentTitle?: string;
208
+ eventTime?: number;
209
+ }) => void;
210
+ /**
211
+ * Track playback progress event
212
+ * Gửi định kỳ: loop 1 = 5s, loop 2 = 25s để track thời lượng user xem nội dung
213
+ * Lưu ý: total_watch_time là tổng thời gian xem được (không tính pause)
214
+ *
215
+ * @param params.contentId - ID của content (required)
216
+ * @param params.contentTitle - Tiêu đề content (required)
217
+ * @param params.contentType - Loại content: 0=VOD, 1=Live, 2=Channel (required)
218
+ * @param params.playbackSession - Session ID từ playback_started (required)
219
+ * @param params.totalWatchTime - Tổng thời gian đã xem tính bằng giây (required)
220
+ * @param params.channelId - Mã kênh EPG (optional)
221
+ * @param params.subContentId - ID chương trình trong kênh live (optional)
222
+ * @param params.subContentTitle - Title chương trình trong kênh live (optional)
223
+ * @param params.eventTime - Unix timestamp (optional)
224
+ */
225
+ declare const trackPlaybackProgress: (params: {
226
+ contentId: string;
227
+ contentTitle: string;
228
+ contentType: 0 | 1 | 2;
229
+ playbackSession: string;
230
+ totalWatchTime: number;
231
+ channelId?: string;
232
+ subContentId?: string;
233
+ subContentTitle?: string;
234
+ eventTime?: number;
235
+ }) => void;
236
+ /**
237
+ * Track playback completed event
238
+ * Tương tự playback_progress nhưng là event cuối cùng khi kết thúc xem
239
+ * Với Live có thể thoát chủ động thì tracking event này
240
+ *
241
+ * @param params.contentId - ID của content (required)
242
+ * @param params.contentTitle - Tiêu đề content (required)
243
+ * @param params.contentType - Loại content: 0=VOD, 1=Live, 2=Channel (required)
244
+ * @param params.playbackSession - Session ID từ playback_started (required)
245
+ * @param params.totalWatchTime - Tổng thời gian đã xem tính bằng giây (required)
246
+ * @param params.channelId - Mã kênh EPG (optional)
247
+ * @param params.subContentId - ID chương trình trong kênh live (optional)
248
+ * @param params.subContentTitle - Title chương trình trong kênh live (optional)
249
+ * @param params.eventTime - Unix timestamp (optional)
250
+ */
251
+ declare const trackPlaybackCompleted: (params: {
252
+ contentId: string;
253
+ contentTitle: string;
254
+ contentType: 0 | 1 | 2;
255
+ playbackSession: string;
256
+ totalWatchTime: number;
257
+ channelId?: string;
258
+ subContentId?: string;
259
+ subContentTitle?: string;
260
+ eventTime?: number;
261
+ }) => void;
262
+ /**
263
+ * Track playback error event
264
+ * Trigger khi:
265
+ * - Video không load/play được (network timeout, source 404)
266
+ * - Player error (format không hỗ trợ, DRM error)
267
+ * - Source error (media source and manifest-related errors)
268
+ *
269
+ * @param params.contentId - ID của content (required)
270
+ * @param params.contentTitle - Tiêu đề content (required)
271
+ * @param params.contentType - Loại content: 0=VOD, 1=Live (required)
272
+ * @param params.playbackSession - Session ID từ playback_started (required)
273
+ * @param params.channelId - Mã kênh EPG (optional)
274
+ * @param params.errorCode - Mã lỗi (optional)
275
+ * @param params.errorMessage - Thông báo lỗi (optional)
276
+ * @param params.errorType - Loại lỗi: video_playback_error, network_error... (optional)
277
+ * @param params.eventTime - Unix timestamp (optional)
278
+ */
279
+ declare const trackPlaybackError: (params: {
280
+ contentId: string;
281
+ contentTitle: string;
282
+ contentType: 0 | 1;
283
+ playbackSession: string;
284
+ channelId?: string;
285
+ errorCode?: number;
286
+ errorMessage?: string;
287
+ errorType?: string;
288
+ eventTime?: number;
289
+ }) => void;
290
+ /**
291
+ * Track quality changed event
292
+ * Trigger khi:
293
+ * - Tự động thay đổi do thuật toán ABR
294
+ * - Thay đổi chủ động bởi người dùng
295
+ *
296
+ * @param params.contentId - ID của content (required)
297
+ * @param params.contentTitle - Tiêu đề content (required)
298
+ * @param params.contentType - Loại content: 0=VOD, 1=Live, 2=Channel (required)
299
+ * @param params.playbackSession - Session ID từ playback_started (required)
300
+ * @param params.fromQuality - Chất lượng trước khi đổi (required)
301
+ * @param params.toQuality - Chất lượng sau khi đổi (required)
302
+ * @param params.positionSec - VOD: vị trí hiện tại, Live: số giây từ lúc bắt đầu xem (required)
303
+ * @param params.channelId - Mã kênh EPG (optional)
304
+ * @param params.reason - Lý do: automatic_abr hoặc user_selected (optional)
305
+ * @param params.eventTime - Unix timestamp (optional)
306
+ */
307
+ declare const trackQualityChanged: (params: {
308
+ contentId: string;
309
+ contentTitle: string;
310
+ contentType: 0 | 1 | 2;
311
+ playbackSession: string;
312
+ fromQuality: "360p" | "480p" | "720p" | "1080p" | "2k" | "4k";
313
+ toQuality: "360p" | "480p" | "720p" | "1080p" | "2k" | "4k";
314
+ positionSec: number;
315
+ channelId?: string;
316
+ reason?: "automatic_abr" | "user_selected";
317
+ eventTime?: number;
318
+ }) => void;
319
+ /**
320
+ * Track buffer started event
321
+ * Buffering xảy ra khi video không còn segment kế tiếp để phát, video sẽ pause để tải thêm segment
322
+ *
323
+ * @param params.contentId - ID của content (required)
324
+ * @param params.contentTitle - Tiêu đề content (required)
325
+ * @param params.contentType - Loại content: 0=VOD, 1=Live, 2=Channel (required)
326
+ * @param params.playbackSession - Session ID từ playback_started (required)
327
+ * @param params.videoQuality - Chất lượng video hiện tại (required)
328
+ * @param params.positionSec - VOD: vị trí hiện tại, Live: số giây từ lúc bắt đầu xem (required)
329
+ * @param params.channelId - Mã kênh EPG (optional)
330
+ * @param params.reason - Lý do: seek_operation, network_congestion (optional)
331
+ * @param params.eventTime - Unix timestamp (optional)
332
+ */
333
+ declare const trackBufferStarted: (params: {
334
+ contentId: string;
335
+ contentTitle: string;
336
+ contentType: 0 | 1 | 2;
337
+ playbackSession: string;
338
+ videoQuality: "360p" | "480p" | "720p" | "1080p" | "2k" | "4k";
339
+ positionSec: number;
340
+ channelId?: string;
341
+ reason?: "seek_operation" | "network_congestion";
342
+ eventTime?: number;
343
+ }) => void;
344
+ /**
345
+ * Track buffer ended event
346
+ * Khi buffering kết thúc và video tiếp tục phát
347
+ *
348
+ * @param params.contentId - ID của content (required)
349
+ * @param params.contentTitle - Tiêu đề content (required)
350
+ * @param params.contentType - Loại content: 0=VOD, 1=Live, 2=Channel (required)
351
+ * @param params.playbackSession - Session ID từ playback_started (required)
352
+ * @param params.videoQuality - Chất lượng video hiện tại (required)
353
+ * @param params.positionSec - VOD: vị trí hiện tại, Live: số giây từ lúc bắt đầu xem (required)
354
+ * @param params.bufferDurationSec - Tổng số giây mà buffer xảy ra (required)
355
+ * @param params.channelId - Mã kênh EPG (optional)
356
+ * @param params.reason - Lý do: seek_operation, network_congestion (optional)
357
+ * @param params.eventTime - Unix timestamp (optional)
358
+ */
359
+ declare const trackBufferEnded: (params: {
360
+ contentId: string;
361
+ contentTitle: string;
362
+ contentType: 0 | 1 | 2;
363
+ playbackSession: string;
364
+ videoQuality: "360p" | "480p" | "720p" | "1080p" | "2k" | "4k";
365
+ positionSec: number;
366
+ bufferDurationSec: number;
367
+ channelId?: string;
368
+ reason?: "seek_operation" | "network_congestion";
369
+ eventTime?: number;
370
+ }) => void;
371
+ /**
372
+ * Track playback paused event
373
+ * Khi user pause video
374
+ *
375
+ * @param params.contentId - ID của content (required)
376
+ * @param params.contentTitle - Tiêu đề content (required)
377
+ * @param params.contentType - Loại content: 0=VOD, 1=Live, 2=Channel (required)
378
+ * @param params.playbackSession - Session ID từ playback_started (required)
379
+ * @param params.positionSec - VOD: vị trí hiện tại, Live: số giây từ lúc bắt đầu xem (required)
380
+ * @param params.channelId - Mã kênh EPG (optional)
381
+ * @param params.eventTime - Unix timestamp (optional)
382
+ */
383
+ declare const trackPlaybackPaused: (params: {
384
+ contentId: string;
385
+ contentTitle: string;
386
+ contentType: 0 | 1 | 2;
387
+ playbackSession: string;
388
+ positionSec: number;
389
+ channelId?: string;
390
+ eventTime?: number;
391
+ }) => void;
392
+ /**
393
+ * Track playback resumed event
394
+ * Khi user resume video sau khi pause
395
+ *
396
+ * @param params.contentId - ID của content (required)
397
+ * @param params.contentTitle - Tiêu đề content (required)
398
+ * @param params.contentType - Loại content: 0=VOD, 1=Live, 2=Channel (required)
399
+ * @param params.playbackSession - Session ID từ playback_started (required)
400
+ * @param params.positionSec - VOD: vị trí hiện tại, Live: số giây từ lúc bắt đầu xem (required)
401
+ * @param params.channelId - Mã kênh EPG (optional)
402
+ * @param params.eventTime - Unix timestamp (optional)
403
+ */
404
+ declare const trackPlaybackResumed: (params: {
405
+ contentId: string;
406
+ contentTitle: string;
407
+ contentType: 0 | 1 | 2;
408
+ playbackSession: string;
409
+ positionSec: number;
410
+ channelId?: string;
411
+ eventTime?: number;
412
+ }) => void;
173
413
  /**
174
414
  * Hook cho Next.js - auto track page views
175
415
  * Dùng cho Next.js Pages Router (next/router)
@@ -180,8 +420,110 @@ declare const tracking: {
180
420
  init: (options?: Partial<TrackingConfig> & {
181
421
  pageMap?: Partial<PageMap>;
182
422
  }) => void;
423
+ setUserInfo: (userInfo: UserInfo) => void;
183
424
  trackPageView: (url: string) => void;
184
425
  trackEvent: (eventName: string, params?: EventData) => void;
426
+ trackViewContentDetails: (contentId: string, contentTitle: string, contentType: 0 | 1 | 2, channelId?: string, eventTime?: number) => void;
427
+ trackPlaybackStarted: (params: {
428
+ contentId: string;
429
+ contentTitle: string;
430
+ contentType: 0 | 1 | 2;
431
+ playbackSession: string;
432
+ videoQuality: "360p" | "480p" | "720p" | "1080p" | "2k" | "4k";
433
+ startTimestamp: number;
434
+ startPosition: number;
435
+ duration: number;
436
+ channelId?: string;
437
+ subContentId?: string;
438
+ subContentTitle?: string;
439
+ eventTime?: number;
440
+ }) => void;
441
+ trackPlaybackProgress: (params: {
442
+ contentId: string;
443
+ contentTitle: string;
444
+ contentType: 0 | 1 | 2;
445
+ playbackSession: string;
446
+ totalWatchTime: number;
447
+ channelId?: string;
448
+ subContentId?: string;
449
+ subContentTitle?: string;
450
+ eventTime?: number;
451
+ }) => void;
452
+ trackPlaybackCompleted: (params: {
453
+ contentId: string;
454
+ contentTitle: string;
455
+ contentType: 0 | 1 | 2;
456
+ playbackSession: string;
457
+ totalWatchTime: number;
458
+ channelId?: string;
459
+ subContentId?: string;
460
+ subContentTitle?: string;
461
+ eventTime?: number;
462
+ }) => void;
463
+ trackPlaybackError: (params: {
464
+ contentId: string;
465
+ contentTitle: string;
466
+ contentType: 0 | 1;
467
+ playbackSession: string;
468
+ channelId?: string;
469
+ errorCode?: number;
470
+ errorMessage?: string;
471
+ errorType?: string;
472
+ eventTime?: number;
473
+ }) => void;
474
+ trackQualityChanged: (params: {
475
+ contentId: string;
476
+ contentTitle: string;
477
+ contentType: 0 | 1 | 2;
478
+ playbackSession: string;
479
+ fromQuality: "360p" | "480p" | "720p" | "1080p" | "2k" | "4k";
480
+ toQuality: "360p" | "480p" | "720p" | "1080p" | "2k" | "4k";
481
+ positionSec: number;
482
+ channelId?: string;
483
+ reason?: "automatic_abr" | "user_selected";
484
+ eventTime?: number;
485
+ }) => void;
486
+ trackBufferStarted: (params: {
487
+ contentId: string;
488
+ contentTitle: string;
489
+ contentType: 0 | 1 | 2;
490
+ playbackSession: string;
491
+ videoQuality: "360p" | "480p" | "720p" | "1080p" | "2k" | "4k";
492
+ positionSec: number;
493
+ channelId?: string;
494
+ reason?: "seek_operation" | "network_congestion";
495
+ eventTime?: number;
496
+ }) => void;
497
+ trackBufferEnded: (params: {
498
+ contentId: string;
499
+ contentTitle: string;
500
+ contentType: 0 | 1 | 2;
501
+ playbackSession: string;
502
+ videoQuality: "360p" | "480p" | "720p" | "1080p" | "2k" | "4k";
503
+ positionSec: number;
504
+ bufferDurationSec: number;
505
+ channelId?: string;
506
+ reason?: "seek_operation" | "network_congestion";
507
+ eventTime?: number;
508
+ }) => void;
509
+ trackPlaybackPaused: (params: {
510
+ contentId: string;
511
+ contentTitle: string;
512
+ contentType: 0 | 1 | 2;
513
+ playbackSession: string;
514
+ positionSec: number;
515
+ channelId?: string;
516
+ eventTime?: number;
517
+ }) => void;
518
+ trackPlaybackResumed: (params: {
519
+ contentId: string;
520
+ contentTitle: string;
521
+ contentType: 0 | 1 | 2;
522
+ playbackSession: string;
523
+ positionSec: number;
524
+ channelId?: string;
525
+ eventTime?: number;
526
+ }) => void;
185
527
  sendEvent: (eventData: EventData) => Promise<Response | void>;
186
528
  getPageInfo: (url: string) => PageInfo;
187
529
  usePageViewTracking: (router: NextRouterLike) => (() => void) | undefined;
@@ -192,4 +534,4 @@ declare const tracking: {
192
534
  sessionEnd: () => void;
193
535
  };
194
536
 
195
- export { type EventData, type NextRouterLike, type PageInfo, type PageMap, type SessionConfig, type SessionCookieConfig, type TrackingConfig, cleanupSessionTracking, clearSessionCookie, tracking as default, defaultConfig, defaultPageMap, generateSessionId, getCookie, getOrCreateSessionId, getPageInfo, getSessionDuration, initSessionTracking, initTracking, isSessionStarted, renewSessionCookie, sendEvent, sendSessionEnd, sendSessionProgress, sendSessionStart, setCookie, trackEvent, trackPageView, updateSessionConfig, usePageViewTracking };
537
+ export { type EventData, type NextRouterLike, type PageInfo, type PageMap, type SessionConfig, type SessionCookieConfig, type TrackingConfig, type UserInfo, cleanupSessionTracking, clearSessionCookie, tracking as default, defaultConfig, defaultPageMap, generateSessionId, getCookie, getOrCreateSessionId, getPageInfo, getSessionDuration, initSessionTracking, initTracking, isSessionStarted, renewSessionCookie, sendEvent, sendSessionEnd, sendSessionProgress, sendSessionStart, setCookie, setUserInfo, trackBufferEnded, trackBufferStarted, trackEvent, trackPageView, trackPlaybackCompleted, trackPlaybackError, trackPlaybackPaused, trackPlaybackProgress, trackPlaybackResumed, trackPlaybackStarted, trackQualityChanged, trackViewContentDetails, updateSessionConfig, usePageViewTracking };