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.
@@ -1025,6 +1025,7 @@ function createVastAdLayer(contentVideo, options) {
1025
1025
  var adHls;
1026
1026
  var adContainerEl;
1027
1027
  var currentAd;
1028
+ var currentMediaFile;
1028
1029
  var sessionId;
1029
1030
  var destroyed = false;
1030
1031
  var tornDown = false;
@@ -1271,7 +1272,12 @@ function createVastAdLayer(contentVideo, options) {
1271
1272
  adContainerEl.style.display = "none";
1272
1273
  adContainerEl.style.pointerEvents = "none";
1273
1274
  }
1274
- emit("ad_impression");
1275
+ emit("ad_impression", {
1276
+ adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
1277
+ adTitle: currentAd === null || currentAd === void 0 ? void 0 : currentAd.title,
1278
+ adUrl: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.url,
1279
+ mediaType: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.type
1280
+ });
1275
1281
  emit("content_resume");
1276
1282
  }
1277
1283
  function handleAdError() {
@@ -1293,6 +1299,7 @@ function createVastAdLayer(contentVideo, options) {
1293
1299
  adHls.destroy();
1294
1300
  adHls = void 0;
1295
1301
  }
1302
+ currentMediaFile = void 0;
1296
1303
  if (adVideoElement) {
1297
1304
  if (singleElementMode && adVideoElement === contentVideo) {
1298
1305
  contentVideo.pause();
@@ -1457,6 +1464,7 @@ function createVastAdLayer(contentVideo, options) {
1457
1464
  adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
1458
1465
  adVideoElement.muted = false;
1459
1466
  mediaFile2 = selectBestMediaFile(ad.mediaFiles);
1467
+ currentMediaFile = mediaFile2;
1460
1468
  if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
1461
1469
  startPlayback(mediaFile2);
1462
1470
  return [
@@ -1503,6 +1511,7 @@ function createVastAdLayer(contentVideo, options) {
1503
1511
  }
1504
1512
  emit("content_pause");
1505
1513
  mediaFile = selectBestMediaFile(ad.mediaFiles);
1514
+ currentMediaFile = mediaFile;
1506
1515
  if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile.url));
1507
1516
  startPlayback(mediaFile);
1508
1517
  return [
@@ -1668,6 +1677,7 @@ function createVastAdLayer(contentVideo, options) {
1668
1677
  ];
1669
1678
  mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1670
1679
  teardownCurrentPlayback();
1680
+ currentMediaFile = slot.mediaFile;
1671
1681
  adVideoElement = contentVideo;
1672
1682
  adHls = void 0;
1673
1683
  adPlaying = true;
@@ -1702,6 +1712,7 @@ function createVastAdLayer(contentVideo, options) {
1702
1712
  case 2:
1703
1713
  if (smartTVMode && !slot.videoEl) {
1704
1714
  teardownCurrentPlayback();
1715
+ currentMediaFile = slot.mediaFile;
1705
1716
  if (adVideoElement) {
1706
1717
  adVideoElement.remove();
1707
1718
  adVideoElement = void 0;
@@ -1733,6 +1744,7 @@ function createVastAdLayer(contentVideo, options) {
1733
1744
  ];
1734
1745
  }
1735
1746
  teardownCurrentPlayback();
1747
+ currentMediaFile = slot.mediaFile;
1736
1748
  if (adVideoElement && adVideoElement !== slot.videoEl) {
1737
1749
  adVideoElement.remove();
1738
1750
  }
@@ -1864,6 +1876,7 @@ function createVastAdLayer(contentVideo, options) {
1864
1876
  }
1865
1877
  }
1866
1878
  currentAd = void 0;
1879
+ currentMediaFile = void 0;
1867
1880
  tornDown = false;
1868
1881
  return [
1869
1882
  2
@@ -1916,6 +1929,7 @@ function createVastAdLayer(contentVideo, options) {
1916
1929
  }
1917
1930
  adContainerEl = void 0;
1918
1931
  currentAd = void 0;
1932
+ currentMediaFile = void 0;
1919
1933
  listeners.clear();
1920
1934
  },
1921
1935
  isAdPlaying: function isAdPlaying() {
@@ -2229,24 +2243,30 @@ function getBrowserID(clientInfo) {
2229
2243
  });
2230
2244
  })();
2231
2245
  }
2232
- var TRACK_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track";
2246
+ var PLAYER_TRACKING_BASE_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking";
2247
+ var TRACK_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/metrics/ingest");
2248
+ var HEARTBEAT_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/heartbeat");
2249
+ var IMPRESSIONS_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/impressions/ingest");
2250
+ function buildHeaders(licenseKey) {
2251
+ var headers = {
2252
+ "Content-Type": "application/json"
2253
+ };
2254
+ if (licenseKey) {
2255
+ headers["Authorization"] = "Bearer ".concat(licenseKey);
2256
+ }
2257
+ return headers;
2258
+ }
2233
2259
  function sendTrackRequest(licenseKey, body) {
2234
2260
  return _async_to_generator(function() {
2235
- var headers, response;
2261
+ var response;
2236
2262
  return _ts_generator(this, function(_state) {
2237
2263
  switch(_state.label){
2238
2264
  case 0:
2239
- headers = {
2240
- "Content-Type": "application/json"
2241
- };
2242
- if (licenseKey) {
2243
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2244
- }
2245
2265
  return [
2246
2266
  4,
2247
2267
  fetch(TRACK_URL, {
2248
2268
  method: "POST",
2249
- headers: headers,
2269
+ headers: buildHeaders(licenseKey),
2250
2270
  body: JSON.stringify(body)
2251
2271
  })
2252
2272
  ];
@@ -2268,14 +2288,86 @@ function sendTrackRequest(licenseKey, body) {
2268
2288
  });
2269
2289
  })();
2270
2290
  }
2271
- function sendInitialTracking(licenseKey) {
2291
+ function postJson(url, licenseKey, body) {
2272
2292
  return _async_to_generator(function() {
2273
- var clientInfo, browserId, trackingData, headers, response, error;
2293
+ var response;
2294
+ return _ts_generator(this, function(_state) {
2295
+ switch(_state.label){
2296
+ case 0:
2297
+ return [
2298
+ 4,
2299
+ fetch(url, {
2300
+ method: "POST",
2301
+ headers: buildHeaders(licenseKey),
2302
+ body: JSON.stringify(body)
2303
+ })
2304
+ ];
2305
+ case 1:
2306
+ response = _state.sent();
2307
+ if (!response.ok) {
2308
+ throw new Error("HTTP error! status: ".concat(response.status));
2309
+ }
2310
+ return [
2311
+ 4,
2312
+ response.json()
2313
+ ];
2314
+ case 2:
2315
+ _state.sent();
2316
+ return [
2317
+ 2
2318
+ ];
2319
+ }
2320
+ });
2321
+ })();
2322
+ }
2323
+ function buildPlayerMetricEvent(_0) {
2324
+ return _async_to_generator(function(licenseKey) {
2325
+ var context, flags, _flags_captureAt, clientInfo, browserId, captureAt;
2326
+ var _arguments = arguments;
2274
2327
  return _ts_generator(this, function(_state) {
2275
2328
  switch(_state.label){
2276
2329
  case 0:
2330
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, flags = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2331
+ clientInfo = getClientInfo();
2332
+ return [
2333
+ 4,
2334
+ getBrowserID(clientInfo)
2335
+ ];
2336
+ case 1:
2337
+ browserId = _state.sent();
2338
+ captureAt = (_flags_captureAt = flags.captureAt) !== null && _flags_captureAt !== void 0 ? _flags_captureAt : /* @__PURE__ */ new Date().toISOString();
2339
+ return [
2340
+ 2,
2341
+ {
2342
+ player_id: browserId,
2343
+ browserId: browserId,
2344
+ device_type: clientInfo.deviceType,
2345
+ deviceType: clientInfo.deviceType,
2346
+ input_stream_type: context.inputStreamType,
2347
+ os: clientInfo.os,
2348
+ ad_loaded: flags.adLoaded,
2349
+ ad_detect: flags.adDetect,
2350
+ license_key: licenseKey,
2351
+ capture_at: captureAt,
2352
+ timestamp: captureAt
2353
+ }
2354
+ ];
2355
+ }
2356
+ });
2357
+ }).apply(this, arguments);
2358
+ }
2359
+ function sendInitialTracking(_0) {
2360
+ return _async_to_generator(function(licenseKey) {
2361
+ var context, clientInfo, browserId, trackingData, error;
2362
+ var _arguments = arguments;
2363
+ return _ts_generator(this, function(_state) {
2364
+ switch(_state.label){
2365
+ case 0:
2366
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
2367
+ _state.label = 1;
2368
+ case 1:
2277
2369
  _state.trys.push([
2278
- 0,
2370
+ 1,
2279
2371
  4,
2280
2372
  ,
2281
2373
  5
@@ -2285,34 +2377,29 @@ function sendInitialTracking(licenseKey) {
2285
2377
  4,
2286
2378
  getBrowserID(clientInfo)
2287
2379
  ];
2288
- case 1:
2380
+ case 2:
2289
2381
  browserId = _state.sent();
2290
2382
  trackingData = _object_spread({
2291
2383
  browserId: browserId
2292
2384
  }, clientInfo);
2293
- headers = {
2294
- "Content-Type": "application/json"
2295
- };
2296
- if (licenseKey) {
2297
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2298
- }
2299
2385
  return [
2300
2386
  4,
2301
- fetch(TRACK_URL, {
2302
- method: "POST",
2303
- headers: headers,
2304
- body: JSON.stringify(trackingData)
2387
+ sendTrackRequest(licenseKey, {
2388
+ events: [
2389
+ {
2390
+ player_id: browserId,
2391
+ device_type: clientInfo.deviceType,
2392
+ input_stream_type: context.inputStreamType,
2393
+ os: clientInfo.os,
2394
+ ad_loaded: false,
2395
+ ad_detect: false,
2396
+ license_key: licenseKey,
2397
+ capture_at: /* @__PURE__ */ new Date().toISOString()
2398
+ }
2399
+ ],
2400
+ trackingData: trackingData
2305
2401
  })
2306
2402
  ];
2307
- case 2:
2308
- response = _state.sent();
2309
- if (!response.ok) {
2310
- throw new Error("HTTP error! status: ".concat(response.status));
2311
- }
2312
- return [
2313
- 4,
2314
- response.json()
2315
- ];
2316
2403
  case 3:
2317
2404
  _state.sent();
2318
2405
  return [
@@ -2332,36 +2419,30 @@ function sendInitialTracking(licenseKey) {
2332
2419
  ];
2333
2420
  }
2334
2421
  });
2335
- })();
2422
+ }).apply(this, arguments);
2336
2423
  }
2337
- function sendAdDetectTracking(licenseKey, adDetectInfo) {
2338
- return _async_to_generator(function() {
2339
- var clientInfo, browserId, trackingData, error;
2424
+ function sendAdDetectTracking(_0, _1) {
2425
+ return _async_to_generator(function(licenseKey, adDetectInfo) {
2426
+ var context, error;
2427
+ var _arguments = arguments;
2340
2428
  return _ts_generator(this, function(_state) {
2341
2429
  switch(_state.label){
2342
2430
  case 0:
2431
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2432
+ _state.label = 1;
2433
+ case 1:
2343
2434
  _state.trys.push([
2344
- 0,
2435
+ 1,
2345
2436
  3,
2346
2437
  ,
2347
2438
  4
2348
2439
  ]);
2349
- clientInfo = getClientInfo();
2350
- return [
2351
- 4,
2352
- getBrowserID(clientInfo)
2353
- ];
2354
- case 1:
2355
- browserId = _state.sent();
2356
- trackingData = _object_spread({
2357
- browserId: browserId
2358
- }, clientInfo);
2359
2440
  return [
2360
2441
  4,
2361
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2362
- licenseKey: licenseKey,
2363
- adDetectInfo: adDetectInfo
2364
- }))
2442
+ sendHeartbeat(licenseKey, context, {
2443
+ adDetect: true,
2444
+ captureAt: adDetectInfo.timestamp
2445
+ })
2365
2446
  ];
2366
2447
  case 2:
2367
2448
  _state.sent();
@@ -2382,36 +2463,30 @@ function sendAdDetectTracking(licenseKey, adDetectInfo) {
2382
2463
  ];
2383
2464
  }
2384
2465
  });
2385
- })();
2466
+ }).apply(this, arguments);
2386
2467
  }
2387
- function sendAdLoadedTracking(licenseKey, adLoadedInfo) {
2388
- return _async_to_generator(function() {
2389
- var clientInfo, browserId, trackingData, error;
2468
+ function sendAdLoadedTracking(_0, _1) {
2469
+ return _async_to_generator(function(licenseKey, adLoadedInfo) {
2470
+ var context, error;
2471
+ var _arguments = arguments;
2390
2472
  return _ts_generator(this, function(_state) {
2391
2473
  switch(_state.label){
2392
2474
  case 0:
2475
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2476
+ _state.label = 1;
2477
+ case 1:
2393
2478
  _state.trys.push([
2394
- 0,
2479
+ 1,
2395
2480
  3,
2396
2481
  ,
2397
2482
  4
2398
2483
  ]);
2399
- clientInfo = getClientInfo();
2400
- return [
2401
- 4,
2402
- getBrowserID(clientInfo)
2403
- ];
2404
- case 1:
2405
- browserId = _state.sent();
2406
- trackingData = _object_spread({
2407
- browserId: browserId
2408
- }, clientInfo);
2409
2484
  return [
2410
2485
  4,
2411
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2412
- licenseKey: licenseKey,
2413
- adLoadedInfo: adLoadedInfo
2414
- }))
2486
+ sendHeartbeat(licenseKey, context, {
2487
+ adLoaded: true,
2488
+ captureAt: adLoadedInfo.timestamp
2489
+ })
2415
2490
  ];
2416
2491
  case 2:
2417
2492
  _state.sent();
@@ -2432,103 +2507,95 @@ function sendAdLoadedTracking(licenseKey, adLoadedInfo) {
2432
2507
  ];
2433
2508
  }
2434
2509
  });
2435
- })();
2510
+ }).apply(this, arguments);
2436
2511
  }
2437
- function sendAdImpressionTracking(licenseKey, adImpressionInfo) {
2438
- return _async_to_generator(function() {
2439
- var clientInfo, browserId, trackingData, error;
2512
+ function sendAdImpressionTracking(_0, _1) {
2513
+ return _async_to_generator(function(licenseKey, adImpressionInfo) {
2514
+ var context, metricEvent, error;
2515
+ var _arguments = arguments;
2440
2516
  return _ts_generator(this, function(_state) {
2441
2517
  switch(_state.label){
2442
2518
  case 0:
2519
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2520
+ _state.label = 1;
2521
+ case 1:
2443
2522
  _state.trys.push([
2444
- 0,
2445
- 3,
2523
+ 1,
2524
+ 4,
2446
2525
  ,
2447
- 4
2526
+ 5
2448
2527
  ]);
2449
- clientInfo = getClientInfo();
2450
2528
  return [
2451
2529
  4,
2452
- getBrowserID(clientInfo)
2530
+ buildPlayerMetricEvent(licenseKey, context, {
2531
+ captureAt: adImpressionInfo.timestamp
2532
+ })
2453
2533
  ];
2454
- case 1:
2455
- browserId = _state.sent();
2456
- trackingData = _object_spread({
2457
- browserId: browserId
2458
- }, clientInfo);
2534
+ case 2:
2535
+ metricEvent = _state.sent();
2459
2536
  return [
2460
2537
  4,
2461
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2462
- licenseKey: licenseKey,
2463
- adImpressionInfo: adImpressionInfo
2464
- }))
2538
+ Promise.all([
2539
+ postJson(HEARTBEAT_URL, licenseKey, metricEvent),
2540
+ postJson(IMPRESSIONS_URL, licenseKey, {
2541
+ events: [
2542
+ {
2543
+ player_id: metricEvent.player_id,
2544
+ ad_played_count: 1,
2545
+ ad_url: adImpressionInfo.adUrl,
2546
+ license_key: licenseKey,
2547
+ capture_at: adImpressionInfo.timestamp
2548
+ }
2549
+ ]
2550
+ })
2551
+ ])
2465
2552
  ];
2466
- case 2:
2553
+ case 3:
2467
2554
  _state.sent();
2468
2555
  return [
2469
2556
  3,
2470
- 4
2557
+ 5
2471
2558
  ];
2472
- case 3:
2559
+ case 4:
2473
2560
  error = _state.sent();
2474
2561
  console.error("[StormcloudVideoPlayer] Error sending ad impression tracking:", error);
2475
2562
  return [
2476
2563
  3,
2477
- 4
2564
+ 5
2478
2565
  ];
2479
- case 4:
2566
+ case 5:
2480
2567
  return [
2481
2568
  2
2482
2569
  ];
2483
2570
  }
2484
2571
  });
2485
- })();
2572
+ }).apply(this, arguments);
2486
2573
  }
2487
- function sendHeartbeat(licenseKey) {
2488
- return _async_to_generator(function() {
2489
- var clientInfo, browserId, heartbeatData, headers, response, error;
2574
+ function sendHeartbeat(_0) {
2575
+ return _async_to_generator(function(licenseKey) {
2576
+ var context, flags, heartbeatData, error;
2577
+ var _arguments = arguments;
2490
2578
  return _ts_generator(this, function(_state) {
2491
2579
  switch(_state.label){
2492
2580
  case 0:
2581
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, flags = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2582
+ _state.label = 1;
2583
+ case 1:
2493
2584
  _state.trys.push([
2494
- 0,
2585
+ 1,
2495
2586
  4,
2496
2587
  ,
2497
2588
  5
2498
2589
  ]);
2499
- clientInfo = getClientInfo();
2500
- return [
2501
- 4,
2502
- getBrowserID(clientInfo)
2503
- ];
2504
- case 1:
2505
- browserId = _state.sent();
2506
- heartbeatData = {
2507
- browserId: browserId,
2508
- timestamp: /* @__PURE__ */ new Date().toISOString()
2509
- };
2510
- headers = {
2511
- "Content-Type": "application/json"
2512
- };
2513
- if (licenseKey) {
2514
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2515
- }
2516
2590
  return [
2517
2591
  4,
2518
- fetch("https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/heartbeat", {
2519
- method: "POST",
2520
- headers: headers,
2521
- body: JSON.stringify(heartbeatData)
2522
- })
2592
+ buildPlayerMetricEvent(licenseKey, context, flags)
2523
2593
  ];
2524
2594
  case 2:
2525
- response = _state.sent();
2526
- if (!response.ok) {
2527
- throw new Error("HTTP error! status: ".concat(response.status));
2528
- }
2595
+ heartbeatData = _state.sent();
2529
2596
  return [
2530
2597
  4,
2531
- response.json()
2598
+ postJson(HEARTBEAT_URL, licenseKey, heartbeatData)
2532
2599
  ];
2533
2600
  case 3:
2534
2601
  _state.sent();
@@ -2549,7 +2616,7 @@ function sendHeartbeat(licenseKey) {
2549
2616
  ];
2550
2617
  }
2551
2618
  });
2552
- })();
2619
+ }).apply(this, arguments);
2553
2620
  }
2554
2621
  // src/utils/polyfills.ts
2555
2622
  function polyfillURLSearchParams() {
@@ -3564,17 +3631,67 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3564
3631
  return "vast";
3565
3632
  }
3566
3633
  },
3634
+ {
3635
+ key: "getInputStreamType",
3636
+ value: function getInputStreamType() {
3637
+ var src = this.config.src.toLowerCase();
3638
+ if (src.includes(".m3u8")) return "hls";
3639
+ if (src.includes(".mpd")) return "dash";
3640
+ if (src.includes(".mp4")) return "mp4";
3641
+ return this.isLiveStream ? "live" : "vod";
3642
+ }
3643
+ },
3644
+ {
3645
+ key: "getAnalyticsContext",
3646
+ value: function getAnalyticsContext() {
3647
+ return {
3648
+ inputStreamType: this.getInputStreamType()
3649
+ };
3650
+ }
3651
+ },
3652
+ {
3653
+ key: "getAdUrlFromBids",
3654
+ value: function getAdUrlFromBids(bids) {
3655
+ var _bids_;
3656
+ return bids === null || bids === void 0 ? void 0 : (_bids_ = bids[0]) === null || _bids_ === void 0 ? void 0 : _bids_.vastUrl;
3657
+ }
3658
+ },
3659
+ {
3660
+ key: "trackAdLoaded",
3661
+ value: function trackAdLoaded(bids) {
3662
+ if (!this.config.licenseKey) return;
3663
+ var adUrl = this.getAdUrlFromBids(bids);
3664
+ if (adUrl) {
3665
+ this.lastServedAdUrl = adUrl;
3666
+ }
3667
+ sendAdLoadedTracking(this.config.licenseKey, _object_spread_props(_object_spread({
3668
+ source: this.getAdSource()
3669
+ }, adUrl ? {
3670
+ vastUrl: adUrl
3671
+ } : {}), {
3672
+ timestamp: /* @__PURE__ */ new Date().toISOString()
3673
+ }), this.getAnalyticsContext());
3674
+ }
3675
+ },
3567
3676
  {
3568
3677
  key: "attachAdLayerEventListeners",
3569
3678
  value: function attachAdLayerEventListeners() {
3570
3679
  var _this = this;
3571
- this.adLayer.on("ad_impression", function() {
3680
+ this.adLayer.on("ad_impression", function(payload) {
3572
3681
  if (_this.config.licenseKey) {
3573
- sendAdImpressionTracking(_this.config.licenseKey, {
3682
+ var _ref;
3683
+ var adUrl = (_ref = payload === null || payload === void 0 ? void 0 : payload.adUrl) !== null && _ref !== void 0 ? _ref : _this.lastServedAdUrl;
3684
+ if (adUrl) {
3685
+ _this.lastServedAdUrl = adUrl;
3686
+ }
3687
+ sendAdImpressionTracking(_this.config.licenseKey, _object_spread_props(_object_spread({
3574
3688
  source: _this.getAdSource(),
3575
- adIndex: _this.currentAdIndex,
3689
+ adIndex: _this.currentAdIndex
3690
+ }, adUrl ? {
3691
+ adUrl: adUrl
3692
+ } : {}), {
3576
3693
  timestamp: /* @__PURE__ */ new Date().toISOString()
3577
- });
3694
+ }), _this.getAnalyticsContext());
3578
3695
  }
3579
3696
  });
3580
3697
  this.adLayer.on("ad_error", function(errorPayload) {
@@ -3668,6 +3785,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3668
3785
  _this.isInAdTransition = false;
3669
3786
  if (!_this.inAdBreak) return;
3670
3787
  _this.currentAdIndex++;
3788
+ _this.trackAdLoaded();
3671
3789
  _this.adLayer.playPreloaded(token).catch(function(err) {
3672
3790
  if (_this.config.debugAdTiming) console.warn("[StormcloudVideoPlayer] playPreloaded failed:", err);
3673
3791
  _this.handleAdFailure();
@@ -3697,6 +3815,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3697
3815
  var freshBids = (_this_pendingNextAdBids = _this.pendingNextAdBids) !== null && _this_pendingNextAdBids !== void 0 ? _this_pendingNextAdBids : bids;
3698
3816
  _this.pendingNextAdBids = null;
3699
3817
  _this.currentAdIndex++;
3818
+ _this.trackAdLoaded(freshBids);
3700
3819
  _this.adLayer.playAd(freshBids).catch(function(err) {
3701
3820
  if (_this.config.debugAdTiming) console.warn("[StormcloudVideoPlayer] playAd(pending) failed:", err);
3702
3821
  _this.handleAdFailure();
@@ -4076,7 +4195,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4076
4195
  }, ((_this_pendingAdBreak1 = this.pendingAdBreak) === null || _this_pendingAdBreak1 === void 0 ? void 0 : _this_pendingAdBreak1.detectedAtFragmentSn) != null && {
4077
4196
  detectedAtFragmentSn: this.pendingAdBreak.detectedAtFragmentSn
4078
4197
  });
4079
- sendAdDetectTracking(this.config.licenseKey, adDetectInfo);
4198
+ sendAdDetectTracking(this.config.licenseKey, adDetectInfo, this.getAnalyticsContext());
4080
4199
  }
4081
4200
  var isManifestMarker = this.isManifestBasedMarker(marker);
4082
4201
  var forceImmediate = (_this_config_immediateManifestAds = this.config.immediateManifestAds) !== null && _this_config_immediateManifestAds !== void 0 ? _this_config_immediateManifestAds : true;
@@ -4145,6 +4264,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4145
4264
  var bids = this.pendingNextAdBids;
4146
4265
  this.pendingNextAdBids = null;
4147
4266
  this.currentAdIndex++;
4267
+ this.trackAdLoaded(bids);
4148
4268
  this.adLayer.playAd(bids).catch(function() {
4149
4269
  return _this.handleAdFailure();
4150
4270
  });
@@ -4399,7 +4519,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4399
4519
  key: "initializeTracking",
4400
4520
  value: function initializeTracking() {
4401
4521
  var _this = this;
4402
- sendInitialTracking(this.config.licenseKey).then(function() {
4522
+ sendInitialTracking(this.config.licenseKey, this.getAnalyticsContext()).then(function() {
4403
4523
  _this.heartbeatInterval = window.setInterval(function() {
4404
4524
  _this.sendHeartbeatIfNeeded();
4405
4525
  }, 5e3);
@@ -4420,7 +4540,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4420
4540
  var now = Date.now();
4421
4541
  if (!this.lastHeartbeatTime || now - this.lastHeartbeatTime > 3e4) {
4422
4542
  this.lastHeartbeatTime = now;
4423
- sendHeartbeat(this.config.licenseKey).catch(function(error) {
4543
+ sendHeartbeat(this.config.licenseKey, this.getAnalyticsContext()).catch(function(error) {
4424
4544
  if (_this.config.debugAdTiming) {
4425
4545
  console.warn("[StormcloudVideoPlayer] Failed to send heartbeat:", error);
4426
4546
  }
@@ -4813,12 +4933,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4813
4933
  10
4814
4934
  ];
4815
4935
  _this.currentAdIndex++;
4816
- if (_this.config.licenseKey) {
4817
- sendAdLoadedTracking(_this.config.licenseKey, {
4818
- source: _this.getAdSource(),
4819
- timestamp: /* @__PURE__ */ new Date().toISOString()
4820
- });
4821
- }
4936
+ _this.trackAdLoaded(bids1);
4822
4937
  return [
4823
4938
  4,
4824
4939
  _this.adLayer.playAd(bids1)
@@ -4923,12 +5038,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4923
5038
  ];
4924
5039
  case 18:
4925
5040
  _this.currentAdIndex++;
4926
- if (_this.config.licenseKey) {
4927
- sendAdLoadedTracking(_this.config.licenseKey, {
4928
- source: _this.getAdSource(),
4929
- timestamp: /* @__PURE__ */ new Date().toISOString()
4930
- });
4931
- }
5041
+ _this.trackAdLoaded(bids2);
4932
5042
  return [
4933
5043
  4,
4934
5044
  _this.adLayer.playAd(bids2)
@@ -5087,12 +5197,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5087
5197
  6
5088
5198
  ];
5089
5199
  this.currentAdIndex++;
5090
- if (this.config.licenseKey) {
5091
- sendAdLoadedTracking(this.config.licenseKey, {
5092
- source: this.getAdSource(),
5093
- timestamp: /* @__PURE__ */ new Date().toISOString()
5094
- });
5095
- }
5200
+ this.trackAdLoaded();
5096
5201
  _state.label = 1;
5097
5202
  case 1:
5098
5203
  _state.trys.push([
@@ -5286,12 +5391,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5286
5391
  5
5287
5392
  ];
5288
5393
  case 3:
5289
- if (this.config.licenseKey) {
5290
- sendAdLoadedTracking(this.config.licenseKey, {
5291
- source: this.getAdSource(),
5292
- timestamp: /* @__PURE__ */ new Date().toISOString()
5293
- });
5294
- }
5394
+ this.trackAdLoaded(bids);
5295
5395
  return [
5296
5396
  4,
5297
5397
  this.adLayer.playAd(bids)
@@ -5437,6 +5537,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5437
5537
  ,
5438
5538
  7
5439
5539
  ]);
5540
+ this.trackAdLoaded(bids);
5440
5541
  return [
5441
5542
  4,
5442
5543
  this.adLayer.playAd(bids)