tracking-lib-ott 1.0.13 → 1.0.15

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