stormcloud-video-player 0.6.8 → 0.6.10

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/lib/index.cjs CHANGED
@@ -1119,6 +1119,7 @@ function createVastAdLayer(contentVideo, options) {
1119
1119
  var adHls;
1120
1120
  var adContainerEl;
1121
1121
  var currentAd;
1122
+ var currentMediaFile;
1122
1123
  var sessionId;
1123
1124
  var destroyed = false;
1124
1125
  var tornDown = false;
@@ -1365,7 +1366,12 @@ function createVastAdLayer(contentVideo, options) {
1365
1366
  adContainerEl.style.display = "none";
1366
1367
  adContainerEl.style.pointerEvents = "none";
1367
1368
  }
1368
- emit("ad_impression");
1369
+ emit("ad_impression", {
1370
+ adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
1371
+ adTitle: currentAd === null || currentAd === void 0 ? void 0 : currentAd.title,
1372
+ adUrl: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.url,
1373
+ mediaType: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.type
1374
+ });
1369
1375
  emit("content_resume");
1370
1376
  }
1371
1377
  function handleAdError() {
@@ -1387,6 +1393,7 @@ function createVastAdLayer(contentVideo, options) {
1387
1393
  adHls.destroy();
1388
1394
  adHls = void 0;
1389
1395
  }
1396
+ currentMediaFile = void 0;
1390
1397
  if (adVideoElement) {
1391
1398
  if (singleElementMode && adVideoElement === contentVideo) {
1392
1399
  contentVideo.pause();
@@ -1551,6 +1558,7 @@ function createVastAdLayer(contentVideo, options) {
1551
1558
  adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
1552
1559
  adVideoElement.muted = false;
1553
1560
  mediaFile2 = selectBestMediaFile(ad.mediaFiles);
1561
+ currentMediaFile = mediaFile2;
1554
1562
  if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
1555
1563
  startPlayback(mediaFile2);
1556
1564
  return [
@@ -1597,6 +1605,7 @@ function createVastAdLayer(contentVideo, options) {
1597
1605
  }
1598
1606
  emit("content_pause");
1599
1607
  mediaFile = selectBestMediaFile(ad.mediaFiles);
1608
+ currentMediaFile = mediaFile;
1600
1609
  if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile.url));
1601
1610
  startPlayback(mediaFile);
1602
1611
  return [
@@ -1762,6 +1771,7 @@ function createVastAdLayer(contentVideo, options) {
1762
1771
  ];
1763
1772
  mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1764
1773
  teardownCurrentPlayback();
1774
+ currentMediaFile = slot.mediaFile;
1765
1775
  adVideoElement = contentVideo;
1766
1776
  adHls = void 0;
1767
1777
  adPlaying = true;
@@ -1796,6 +1806,7 @@ function createVastAdLayer(contentVideo, options) {
1796
1806
  case 2:
1797
1807
  if (smartTVMode && !slot.videoEl) {
1798
1808
  teardownCurrentPlayback();
1809
+ currentMediaFile = slot.mediaFile;
1799
1810
  if (adVideoElement) {
1800
1811
  adVideoElement.remove();
1801
1812
  adVideoElement = void 0;
@@ -1827,6 +1838,7 @@ function createVastAdLayer(contentVideo, options) {
1827
1838
  ];
1828
1839
  }
1829
1840
  teardownCurrentPlayback();
1841
+ currentMediaFile = slot.mediaFile;
1830
1842
  if (adVideoElement && adVideoElement !== slot.videoEl) {
1831
1843
  adVideoElement.remove();
1832
1844
  }
@@ -1958,6 +1970,7 @@ function createVastAdLayer(contentVideo, options) {
1958
1970
  }
1959
1971
  }
1960
1972
  currentAd = void 0;
1973
+ currentMediaFile = void 0;
1961
1974
  tornDown = false;
1962
1975
  return [
1963
1976
  2
@@ -2010,6 +2023,7 @@ function createVastAdLayer(contentVideo, options) {
2010
2023
  }
2011
2024
  adContainerEl = void 0;
2012
2025
  currentAd = void 0;
2026
+ currentMediaFile = void 0;
2013
2027
  listeners.clear();
2014
2028
  },
2015
2029
  isAdPlaying: function isAdPlaying() {
@@ -2323,24 +2337,30 @@ function getBrowserID(clientInfo) {
2323
2337
  });
2324
2338
  })();
2325
2339
  }
2326
- var TRACK_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track";
2340
+ var PLAYER_TRACKING_BASE_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking";
2341
+ var TRACK_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/metrics/ingest");
2342
+ var HEARTBEAT_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/heartbeat");
2343
+ var IMPRESSIONS_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/impressions/ingest");
2344
+ function buildHeaders(licenseKey) {
2345
+ var headers = {
2346
+ "Content-Type": "application/json"
2347
+ };
2348
+ if (licenseKey) {
2349
+ headers["Authorization"] = "Bearer ".concat(licenseKey);
2350
+ }
2351
+ return headers;
2352
+ }
2327
2353
  function sendTrackRequest(licenseKey, body) {
2328
2354
  return _async_to_generator(function() {
2329
- var headers, response;
2355
+ var response;
2330
2356
  return _ts_generator(this, function(_state) {
2331
2357
  switch(_state.label){
2332
2358
  case 0:
2333
- headers = {
2334
- "Content-Type": "application/json"
2335
- };
2336
- if (licenseKey) {
2337
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2338
- }
2339
2359
  return [
2340
2360
  4,
2341
2361
  fetch(TRACK_URL, {
2342
2362
  method: "POST",
2343
- headers: headers,
2363
+ headers: buildHeaders(licenseKey),
2344
2364
  body: JSON.stringify(body)
2345
2365
  })
2346
2366
  ];
@@ -2362,14 +2382,86 @@ function sendTrackRequest(licenseKey, body) {
2362
2382
  });
2363
2383
  })();
2364
2384
  }
2365
- function sendInitialTracking(licenseKey) {
2385
+ function postJson(url, licenseKey, body) {
2366
2386
  return _async_to_generator(function() {
2367
- var clientInfo, browserId, trackingData, headers, response, error;
2387
+ var response;
2388
+ return _ts_generator(this, function(_state) {
2389
+ switch(_state.label){
2390
+ case 0:
2391
+ return [
2392
+ 4,
2393
+ fetch(url, {
2394
+ method: "POST",
2395
+ headers: buildHeaders(licenseKey),
2396
+ body: JSON.stringify(body)
2397
+ })
2398
+ ];
2399
+ case 1:
2400
+ response = _state.sent();
2401
+ if (!response.ok) {
2402
+ throw new Error("HTTP error! status: ".concat(response.status));
2403
+ }
2404
+ return [
2405
+ 4,
2406
+ response.json()
2407
+ ];
2408
+ case 2:
2409
+ _state.sent();
2410
+ return [
2411
+ 2
2412
+ ];
2413
+ }
2414
+ });
2415
+ })();
2416
+ }
2417
+ function buildPlayerMetricEvent(_0) {
2418
+ return _async_to_generator(function(licenseKey) {
2419
+ var context, flags, _flags_captureAt, clientInfo, browserId, captureAt;
2420
+ var _arguments = arguments;
2368
2421
  return _ts_generator(this, function(_state) {
2369
2422
  switch(_state.label){
2370
2423
  case 0:
2424
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, flags = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2425
+ clientInfo = getClientInfo();
2426
+ return [
2427
+ 4,
2428
+ getBrowserID(clientInfo)
2429
+ ];
2430
+ case 1:
2431
+ browserId = _state.sent();
2432
+ captureAt = (_flags_captureAt = flags.captureAt) !== null && _flags_captureAt !== void 0 ? _flags_captureAt : /* @__PURE__ */ new Date().toISOString();
2433
+ return [
2434
+ 2,
2435
+ {
2436
+ player_id: browserId,
2437
+ browserId: browserId,
2438
+ device_type: clientInfo.deviceType,
2439
+ deviceType: clientInfo.deviceType,
2440
+ input_stream_type: context.inputStreamType,
2441
+ os: clientInfo.os,
2442
+ ad_loaded: flags.adLoaded,
2443
+ ad_detect: flags.adDetect,
2444
+ license_key: licenseKey,
2445
+ capture_at: captureAt,
2446
+ timestamp: captureAt
2447
+ }
2448
+ ];
2449
+ }
2450
+ });
2451
+ }).apply(this, arguments);
2452
+ }
2453
+ function sendInitialTracking(_0) {
2454
+ return _async_to_generator(function(licenseKey) {
2455
+ var context, clientInfo, browserId, trackingData, error;
2456
+ var _arguments = arguments;
2457
+ return _ts_generator(this, function(_state) {
2458
+ switch(_state.label){
2459
+ case 0:
2460
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
2461
+ _state.label = 1;
2462
+ case 1:
2371
2463
  _state.trys.push([
2372
- 0,
2464
+ 1,
2373
2465
  4,
2374
2466
  ,
2375
2467
  5
@@ -2379,34 +2471,29 @@ function sendInitialTracking(licenseKey) {
2379
2471
  4,
2380
2472
  getBrowserID(clientInfo)
2381
2473
  ];
2382
- case 1:
2474
+ case 2:
2383
2475
  browserId = _state.sent();
2384
2476
  trackingData = _object_spread({
2385
2477
  browserId: browserId
2386
2478
  }, clientInfo);
2387
- headers = {
2388
- "Content-Type": "application/json"
2389
- };
2390
- if (licenseKey) {
2391
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2392
- }
2393
2479
  return [
2394
2480
  4,
2395
- fetch(TRACK_URL, {
2396
- method: "POST",
2397
- headers: headers,
2398
- body: JSON.stringify(trackingData)
2481
+ sendTrackRequest(licenseKey, {
2482
+ events: [
2483
+ {
2484
+ player_id: browserId,
2485
+ device_type: clientInfo.deviceType,
2486
+ input_stream_type: context.inputStreamType,
2487
+ os: clientInfo.os,
2488
+ ad_loaded: false,
2489
+ ad_detect: false,
2490
+ license_key: licenseKey,
2491
+ capture_at: /* @__PURE__ */ new Date().toISOString()
2492
+ }
2493
+ ],
2494
+ trackingData: trackingData
2399
2495
  })
2400
2496
  ];
2401
- case 2:
2402
- response = _state.sent();
2403
- if (!response.ok) {
2404
- throw new Error("HTTP error! status: ".concat(response.status));
2405
- }
2406
- return [
2407
- 4,
2408
- response.json()
2409
- ];
2410
2497
  case 3:
2411
2498
  _state.sent();
2412
2499
  return [
@@ -2426,36 +2513,30 @@ function sendInitialTracking(licenseKey) {
2426
2513
  ];
2427
2514
  }
2428
2515
  });
2429
- })();
2516
+ }).apply(this, arguments);
2430
2517
  }
2431
- function sendAdDetectTracking(licenseKey, adDetectInfo) {
2432
- return _async_to_generator(function() {
2433
- var clientInfo, browserId, trackingData, error;
2518
+ function sendAdDetectTracking(_0, _1) {
2519
+ return _async_to_generator(function(licenseKey, adDetectInfo) {
2520
+ var context, error;
2521
+ var _arguments = arguments;
2434
2522
  return _ts_generator(this, function(_state) {
2435
2523
  switch(_state.label){
2436
2524
  case 0:
2525
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2526
+ _state.label = 1;
2527
+ case 1:
2437
2528
  _state.trys.push([
2438
- 0,
2529
+ 1,
2439
2530
  3,
2440
2531
  ,
2441
2532
  4
2442
2533
  ]);
2443
- clientInfo = getClientInfo();
2444
- return [
2445
- 4,
2446
- getBrowserID(clientInfo)
2447
- ];
2448
- case 1:
2449
- browserId = _state.sent();
2450
- trackingData = _object_spread({
2451
- browserId: browserId
2452
- }, clientInfo);
2453
2534
  return [
2454
2535
  4,
2455
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2456
- licenseKey: licenseKey,
2457
- adDetectInfo: adDetectInfo
2458
- }))
2536
+ sendHeartbeat(licenseKey, context, {
2537
+ adDetect: true,
2538
+ captureAt: adDetectInfo.timestamp
2539
+ })
2459
2540
  ];
2460
2541
  case 2:
2461
2542
  _state.sent();
@@ -2476,36 +2557,30 @@ function sendAdDetectTracking(licenseKey, adDetectInfo) {
2476
2557
  ];
2477
2558
  }
2478
2559
  });
2479
- })();
2560
+ }).apply(this, arguments);
2480
2561
  }
2481
- function sendAdLoadedTracking(licenseKey, adLoadedInfo) {
2482
- return _async_to_generator(function() {
2483
- var clientInfo, browserId, trackingData, error;
2562
+ function sendAdLoadedTracking(_0, _1) {
2563
+ return _async_to_generator(function(licenseKey, adLoadedInfo) {
2564
+ var context, error;
2565
+ var _arguments = arguments;
2484
2566
  return _ts_generator(this, function(_state) {
2485
2567
  switch(_state.label){
2486
2568
  case 0:
2569
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2570
+ _state.label = 1;
2571
+ case 1:
2487
2572
  _state.trys.push([
2488
- 0,
2573
+ 1,
2489
2574
  3,
2490
2575
  ,
2491
2576
  4
2492
2577
  ]);
2493
- clientInfo = getClientInfo();
2494
- return [
2495
- 4,
2496
- getBrowserID(clientInfo)
2497
- ];
2498
- case 1:
2499
- browserId = _state.sent();
2500
- trackingData = _object_spread({
2501
- browserId: browserId
2502
- }, clientInfo);
2503
2578
  return [
2504
2579
  4,
2505
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2506
- licenseKey: licenseKey,
2507
- adLoadedInfo: adLoadedInfo
2508
- }))
2580
+ sendHeartbeat(licenseKey, context, {
2581
+ adLoaded: true,
2582
+ captureAt: adLoadedInfo.timestamp
2583
+ })
2509
2584
  ];
2510
2585
  case 2:
2511
2586
  _state.sent();
@@ -2526,103 +2601,95 @@ function sendAdLoadedTracking(licenseKey, adLoadedInfo) {
2526
2601
  ];
2527
2602
  }
2528
2603
  });
2529
- })();
2604
+ }).apply(this, arguments);
2530
2605
  }
2531
- function sendAdImpressionTracking(licenseKey, adImpressionInfo) {
2532
- return _async_to_generator(function() {
2533
- var clientInfo, browserId, trackingData, error;
2606
+ function sendAdImpressionTracking(_0, _1) {
2607
+ return _async_to_generator(function(licenseKey, adImpressionInfo) {
2608
+ var context, metricEvent, error;
2609
+ var _arguments = arguments;
2534
2610
  return _ts_generator(this, function(_state) {
2535
2611
  switch(_state.label){
2536
2612
  case 0:
2613
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2614
+ _state.label = 1;
2615
+ case 1:
2537
2616
  _state.trys.push([
2538
- 0,
2539
- 3,
2617
+ 1,
2618
+ 4,
2540
2619
  ,
2541
- 4
2620
+ 5
2542
2621
  ]);
2543
- clientInfo = getClientInfo();
2544
2622
  return [
2545
2623
  4,
2546
- getBrowserID(clientInfo)
2624
+ buildPlayerMetricEvent(licenseKey, context, {
2625
+ captureAt: adImpressionInfo.timestamp
2626
+ })
2547
2627
  ];
2548
- case 1:
2549
- browserId = _state.sent();
2550
- trackingData = _object_spread({
2551
- browserId: browserId
2552
- }, clientInfo);
2628
+ case 2:
2629
+ metricEvent = _state.sent();
2553
2630
  return [
2554
2631
  4,
2555
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2556
- licenseKey: licenseKey,
2557
- adImpressionInfo: adImpressionInfo
2558
- }))
2632
+ Promise.all([
2633
+ postJson(HEARTBEAT_URL, licenseKey, metricEvent),
2634
+ postJson(IMPRESSIONS_URL, licenseKey, {
2635
+ events: [
2636
+ {
2637
+ player_id: metricEvent.player_id,
2638
+ ad_played_count: 1,
2639
+ ad_url: adImpressionInfo.adUrl,
2640
+ license_key: licenseKey,
2641
+ capture_at: adImpressionInfo.timestamp
2642
+ }
2643
+ ]
2644
+ })
2645
+ ])
2559
2646
  ];
2560
- case 2:
2647
+ case 3:
2561
2648
  _state.sent();
2562
2649
  return [
2563
2650
  3,
2564
- 4
2651
+ 5
2565
2652
  ];
2566
- case 3:
2653
+ case 4:
2567
2654
  error = _state.sent();
2568
2655
  console.error("[StormcloudVideoPlayer] Error sending ad impression tracking:", error);
2569
2656
  return [
2570
2657
  3,
2571
- 4
2658
+ 5
2572
2659
  ];
2573
- case 4:
2660
+ case 5:
2574
2661
  return [
2575
2662
  2
2576
2663
  ];
2577
2664
  }
2578
2665
  });
2579
- })();
2666
+ }).apply(this, arguments);
2580
2667
  }
2581
- function sendHeartbeat(licenseKey) {
2582
- return _async_to_generator(function() {
2583
- var clientInfo, browserId, heartbeatData, headers, response, error;
2668
+ function sendHeartbeat(_0) {
2669
+ return _async_to_generator(function(licenseKey) {
2670
+ var context, flags, heartbeatData, error;
2671
+ var _arguments = arguments;
2584
2672
  return _ts_generator(this, function(_state) {
2585
2673
  switch(_state.label){
2586
2674
  case 0:
2675
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, flags = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2676
+ _state.label = 1;
2677
+ case 1:
2587
2678
  _state.trys.push([
2588
- 0,
2679
+ 1,
2589
2680
  4,
2590
2681
  ,
2591
2682
  5
2592
2683
  ]);
2593
- clientInfo = getClientInfo();
2594
2684
  return [
2595
2685
  4,
2596
- getBrowserID(clientInfo)
2597
- ];
2598
- case 1:
2599
- browserId = _state.sent();
2600
- heartbeatData = {
2601
- browserId: browserId,
2602
- timestamp: /* @__PURE__ */ new Date().toISOString()
2603
- };
2604
- headers = {
2605
- "Content-Type": "application/json"
2606
- };
2607
- if (licenseKey) {
2608
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2609
- }
2610
- return [
2611
- 4,
2612
- fetch("https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/heartbeat", {
2613
- method: "POST",
2614
- headers: headers,
2615
- body: JSON.stringify(heartbeatData)
2616
- })
2686
+ buildPlayerMetricEvent(licenseKey, context, flags)
2617
2687
  ];
2618
2688
  case 2:
2619
- response = _state.sent();
2620
- if (!response.ok) {
2621
- throw new Error("HTTP error! status: ".concat(response.status));
2622
- }
2689
+ heartbeatData = _state.sent();
2623
2690
  return [
2624
2691
  4,
2625
- response.json()
2692
+ postJson(HEARTBEAT_URL, licenseKey, heartbeatData)
2626
2693
  ];
2627
2694
  case 3:
2628
2695
  _state.sent();
@@ -2643,7 +2710,7 @@ function sendHeartbeat(licenseKey) {
2643
2710
  ];
2644
2711
  }
2645
2712
  });
2646
- })();
2713
+ }).apply(this, arguments);
2647
2714
  }
2648
2715
  // src/utils/polyfills.ts
2649
2716
  function polyfillURLSearchParams() {
@@ -3683,17 +3750,67 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3683
3750
  return "vast";
3684
3751
  }
3685
3752
  },
3753
+ {
3754
+ key: "getInputStreamType",
3755
+ value: function getInputStreamType() {
3756
+ var src = this.config.src.toLowerCase();
3757
+ if (src.includes(".m3u8")) return "hls";
3758
+ if (src.includes(".mpd")) return "dash";
3759
+ if (src.includes(".mp4")) return "mp4";
3760
+ return this.isLiveStream ? "live" : "vod";
3761
+ }
3762
+ },
3763
+ {
3764
+ key: "getAnalyticsContext",
3765
+ value: function getAnalyticsContext() {
3766
+ return {
3767
+ inputStreamType: this.getInputStreamType()
3768
+ };
3769
+ }
3770
+ },
3771
+ {
3772
+ key: "getAdUrlFromBids",
3773
+ value: function getAdUrlFromBids(bids) {
3774
+ var _bids_;
3775
+ return bids === null || bids === void 0 ? void 0 : (_bids_ = bids[0]) === null || _bids_ === void 0 ? void 0 : _bids_.vastUrl;
3776
+ }
3777
+ },
3778
+ {
3779
+ key: "trackAdLoaded",
3780
+ value: function trackAdLoaded(bids) {
3781
+ if (!this.config.licenseKey) return;
3782
+ var adUrl = this.getAdUrlFromBids(bids);
3783
+ if (adUrl) {
3784
+ this.lastServedAdUrl = adUrl;
3785
+ }
3786
+ sendAdLoadedTracking(this.config.licenseKey, _object_spread_props(_object_spread({
3787
+ source: this.getAdSource()
3788
+ }, adUrl ? {
3789
+ vastUrl: adUrl
3790
+ } : {}), {
3791
+ timestamp: /* @__PURE__ */ new Date().toISOString()
3792
+ }), this.getAnalyticsContext());
3793
+ }
3794
+ },
3686
3795
  {
3687
3796
  key: "attachAdLayerEventListeners",
3688
3797
  value: function attachAdLayerEventListeners() {
3689
3798
  var _this = this;
3690
- this.adLayer.on("ad_impression", function() {
3799
+ this.adLayer.on("ad_impression", function(payload) {
3691
3800
  if (_this.config.licenseKey) {
3692
- sendAdImpressionTracking(_this.config.licenseKey, {
3801
+ var _ref;
3802
+ var adUrl = (_ref = payload === null || payload === void 0 ? void 0 : payload.adUrl) !== null && _ref !== void 0 ? _ref : _this.lastServedAdUrl;
3803
+ if (adUrl) {
3804
+ _this.lastServedAdUrl = adUrl;
3805
+ }
3806
+ sendAdImpressionTracking(_this.config.licenseKey, _object_spread_props(_object_spread({
3693
3807
  source: _this.getAdSource(),
3694
- adIndex: _this.currentAdIndex,
3808
+ adIndex: _this.currentAdIndex
3809
+ }, adUrl ? {
3810
+ adUrl: adUrl
3811
+ } : {}), {
3695
3812
  timestamp: /* @__PURE__ */ new Date().toISOString()
3696
- });
3813
+ }), _this.getAnalyticsContext());
3697
3814
  }
3698
3815
  });
3699
3816
  this.adLayer.on("ad_error", function(errorPayload) {
@@ -3787,6 +3904,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3787
3904
  _this.isInAdTransition = false;
3788
3905
  if (!_this.inAdBreak) return;
3789
3906
  _this.currentAdIndex++;
3907
+ _this.trackAdLoaded();
3790
3908
  _this.adLayer.playPreloaded(token).catch(function(err) {
3791
3909
  if (_this.config.debugAdTiming) console.warn("[StormcloudVideoPlayer] playPreloaded failed:", err);
3792
3910
  _this.handleAdFailure();
@@ -3816,6 +3934,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3816
3934
  var freshBids = (_this_pendingNextAdBids = _this.pendingNextAdBids) !== null && _this_pendingNextAdBids !== void 0 ? _this_pendingNextAdBids : bids;
3817
3935
  _this.pendingNextAdBids = null;
3818
3936
  _this.currentAdIndex++;
3937
+ _this.trackAdLoaded(freshBids);
3819
3938
  _this.adLayer.playAd(freshBids).catch(function(err) {
3820
3939
  if (_this.config.debugAdTiming) console.warn("[StormcloudVideoPlayer] playAd(pending) failed:", err);
3821
3940
  _this.handleAdFailure();
@@ -4195,7 +4314,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4195
4314
  }, ((_this_pendingAdBreak1 = this.pendingAdBreak) === null || _this_pendingAdBreak1 === void 0 ? void 0 : _this_pendingAdBreak1.detectedAtFragmentSn) != null && {
4196
4315
  detectedAtFragmentSn: this.pendingAdBreak.detectedAtFragmentSn
4197
4316
  });
4198
- sendAdDetectTracking(this.config.licenseKey, adDetectInfo);
4317
+ sendAdDetectTracking(this.config.licenseKey, adDetectInfo, this.getAnalyticsContext());
4199
4318
  }
4200
4319
  var isManifestMarker = this.isManifestBasedMarker(marker);
4201
4320
  var forceImmediate = (_this_config_immediateManifestAds = this.config.immediateManifestAds) !== null && _this_config_immediateManifestAds !== void 0 ? _this_config_immediateManifestAds : true;
@@ -4264,6 +4383,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4264
4383
  var bids = this.pendingNextAdBids;
4265
4384
  this.pendingNextAdBids = null;
4266
4385
  this.currentAdIndex++;
4386
+ this.trackAdLoaded(bids);
4267
4387
  this.adLayer.playAd(bids).catch(function() {
4268
4388
  return _this.handleAdFailure();
4269
4389
  });
@@ -4518,7 +4638,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4518
4638
  key: "initializeTracking",
4519
4639
  value: function initializeTracking() {
4520
4640
  var _this = this;
4521
- sendInitialTracking(this.config.licenseKey).then(function() {
4641
+ sendInitialTracking(this.config.licenseKey, this.getAnalyticsContext()).then(function() {
4522
4642
  _this.heartbeatInterval = window.setInterval(function() {
4523
4643
  _this.sendHeartbeatIfNeeded();
4524
4644
  }, 5e3);
@@ -4539,7 +4659,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4539
4659
  var now = Date.now();
4540
4660
  if (!this.lastHeartbeatTime || now - this.lastHeartbeatTime > 3e4) {
4541
4661
  this.lastHeartbeatTime = now;
4542
- sendHeartbeat(this.config.licenseKey).catch(function(error) {
4662
+ sendHeartbeat(this.config.licenseKey, this.getAnalyticsContext()).catch(function(error) {
4543
4663
  if (_this.config.debugAdTiming) {
4544
4664
  console.warn("[StormcloudVideoPlayer] Failed to send heartbeat:", error);
4545
4665
  }
@@ -4932,12 +5052,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4932
5052
  10
4933
5053
  ];
4934
5054
  _this.currentAdIndex++;
4935
- if (_this.config.licenseKey) {
4936
- sendAdLoadedTracking(_this.config.licenseKey, {
4937
- source: _this.getAdSource(),
4938
- timestamp: /* @__PURE__ */ new Date().toISOString()
4939
- });
4940
- }
5055
+ _this.trackAdLoaded(bids1);
4941
5056
  return [
4942
5057
  4,
4943
5058
  _this.adLayer.playAd(bids1)
@@ -5042,12 +5157,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5042
5157
  ];
5043
5158
  case 18:
5044
5159
  _this.currentAdIndex++;
5045
- if (_this.config.licenseKey) {
5046
- sendAdLoadedTracking(_this.config.licenseKey, {
5047
- source: _this.getAdSource(),
5048
- timestamp: /* @__PURE__ */ new Date().toISOString()
5049
- });
5050
- }
5160
+ _this.trackAdLoaded(bids2);
5051
5161
  return [
5052
5162
  4,
5053
5163
  _this.adLayer.playAd(bids2)
@@ -5206,12 +5316,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5206
5316
  6
5207
5317
  ];
5208
5318
  this.currentAdIndex++;
5209
- if (this.config.licenseKey) {
5210
- sendAdLoadedTracking(this.config.licenseKey, {
5211
- source: this.getAdSource(),
5212
- timestamp: /* @__PURE__ */ new Date().toISOString()
5213
- });
5214
- }
5319
+ this.trackAdLoaded();
5215
5320
  _state.label = 1;
5216
5321
  case 1:
5217
5322
  _state.trys.push([
@@ -5405,12 +5510,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5405
5510
  5
5406
5511
  ];
5407
5512
  case 3:
5408
- if (this.config.licenseKey) {
5409
- sendAdLoadedTracking(this.config.licenseKey, {
5410
- source: this.getAdSource(),
5411
- timestamp: /* @__PURE__ */ new Date().toISOString()
5412
- });
5413
- }
5513
+ this.trackAdLoaded(bids);
5414
5514
  return [
5415
5515
  4,
5416
5516
  this.adLayer.playAd(bids)
@@ -5556,6 +5656,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5556
5656
  ,
5557
5657
  7
5558
5658
  ]);
5659
+ this.trackAdLoaded(bids);
5559
5660
  return [
5560
5661
  4,
5561
5662
  this.adLayer.playAd(bids)