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.
@@ -989,6 +989,7 @@ function createVastAdLayer(contentVideo, options) {
989
989
  var adHls;
990
990
  var adContainerEl;
991
991
  var currentAd;
992
+ var currentMediaFile;
992
993
  var sessionId;
993
994
  var destroyed = false;
994
995
  var tornDown = false;
@@ -1235,7 +1236,12 @@ function createVastAdLayer(contentVideo, options) {
1235
1236
  adContainerEl.style.display = "none";
1236
1237
  adContainerEl.style.pointerEvents = "none";
1237
1238
  }
1238
- emit("ad_impression");
1239
+ emit("ad_impression", {
1240
+ adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
1241
+ adTitle: currentAd === null || currentAd === void 0 ? void 0 : currentAd.title,
1242
+ adUrl: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.url,
1243
+ mediaType: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.type
1244
+ });
1239
1245
  emit("content_resume");
1240
1246
  }
1241
1247
  function handleAdError() {
@@ -1257,6 +1263,7 @@ function createVastAdLayer(contentVideo, options) {
1257
1263
  adHls.destroy();
1258
1264
  adHls = void 0;
1259
1265
  }
1266
+ currentMediaFile = void 0;
1260
1267
  if (adVideoElement) {
1261
1268
  if (singleElementMode && adVideoElement === contentVideo) {
1262
1269
  contentVideo.pause();
@@ -1421,6 +1428,7 @@ function createVastAdLayer(contentVideo, options) {
1421
1428
  adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
1422
1429
  adVideoElement.muted = false;
1423
1430
  mediaFile2 = selectBestMediaFile(ad.mediaFiles);
1431
+ currentMediaFile = mediaFile2;
1424
1432
  if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
1425
1433
  startPlayback(mediaFile2);
1426
1434
  return [
@@ -1467,6 +1475,7 @@ function createVastAdLayer(contentVideo, options) {
1467
1475
  }
1468
1476
  emit("content_pause");
1469
1477
  mediaFile = selectBestMediaFile(ad.mediaFiles);
1478
+ currentMediaFile = mediaFile;
1470
1479
  if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile.url));
1471
1480
  startPlayback(mediaFile);
1472
1481
  return [
@@ -1632,6 +1641,7 @@ function createVastAdLayer(contentVideo, options) {
1632
1641
  ];
1633
1642
  mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1634
1643
  teardownCurrentPlayback();
1644
+ currentMediaFile = slot.mediaFile;
1635
1645
  adVideoElement = contentVideo;
1636
1646
  adHls = void 0;
1637
1647
  adPlaying = true;
@@ -1666,6 +1676,7 @@ function createVastAdLayer(contentVideo, options) {
1666
1676
  case 2:
1667
1677
  if (smartTVMode && !slot.videoEl) {
1668
1678
  teardownCurrentPlayback();
1679
+ currentMediaFile = slot.mediaFile;
1669
1680
  if (adVideoElement) {
1670
1681
  adVideoElement.remove();
1671
1682
  adVideoElement = void 0;
@@ -1697,6 +1708,7 @@ function createVastAdLayer(contentVideo, options) {
1697
1708
  ];
1698
1709
  }
1699
1710
  teardownCurrentPlayback();
1711
+ currentMediaFile = slot.mediaFile;
1700
1712
  if (adVideoElement && adVideoElement !== slot.videoEl) {
1701
1713
  adVideoElement.remove();
1702
1714
  }
@@ -1828,6 +1840,7 @@ function createVastAdLayer(contentVideo, options) {
1828
1840
  }
1829
1841
  }
1830
1842
  currentAd = void 0;
1843
+ currentMediaFile = void 0;
1831
1844
  tornDown = false;
1832
1845
  return [
1833
1846
  2
@@ -1880,6 +1893,7 @@ function createVastAdLayer(contentVideo, options) {
1880
1893
  }
1881
1894
  adContainerEl = void 0;
1882
1895
  currentAd = void 0;
1896
+ currentMediaFile = void 0;
1883
1897
  listeners.clear();
1884
1898
  },
1885
1899
  isAdPlaying: function isAdPlaying() {
@@ -2193,24 +2207,30 @@ function getBrowserID(clientInfo) {
2193
2207
  });
2194
2208
  })();
2195
2209
  }
2196
- var TRACK_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track";
2210
+ var PLAYER_TRACKING_BASE_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking";
2211
+ var TRACK_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/metrics/ingest");
2212
+ var HEARTBEAT_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/heartbeat");
2213
+ var IMPRESSIONS_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/impressions/ingest");
2214
+ function buildHeaders(licenseKey) {
2215
+ var headers = {
2216
+ "Content-Type": "application/json"
2217
+ };
2218
+ if (licenseKey) {
2219
+ headers["Authorization"] = "Bearer ".concat(licenseKey);
2220
+ }
2221
+ return headers;
2222
+ }
2197
2223
  function sendTrackRequest(licenseKey, body) {
2198
2224
  return _async_to_generator(function() {
2199
- var headers, response;
2225
+ var response;
2200
2226
  return _ts_generator(this, function(_state) {
2201
2227
  switch(_state.label){
2202
2228
  case 0:
2203
- headers = {
2204
- "Content-Type": "application/json"
2205
- };
2206
- if (licenseKey) {
2207
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2208
- }
2209
2229
  return [
2210
2230
  4,
2211
2231
  fetch(TRACK_URL, {
2212
2232
  method: "POST",
2213
- headers: headers,
2233
+ headers: buildHeaders(licenseKey),
2214
2234
  body: JSON.stringify(body)
2215
2235
  })
2216
2236
  ];
@@ -2232,14 +2252,86 @@ function sendTrackRequest(licenseKey, body) {
2232
2252
  });
2233
2253
  })();
2234
2254
  }
2235
- function sendInitialTracking(licenseKey) {
2255
+ function postJson(url, licenseKey, body) {
2236
2256
  return _async_to_generator(function() {
2237
- var clientInfo, browserId, trackingData, headers, response, error;
2257
+ var response;
2258
+ return _ts_generator(this, function(_state) {
2259
+ switch(_state.label){
2260
+ case 0:
2261
+ return [
2262
+ 4,
2263
+ fetch(url, {
2264
+ method: "POST",
2265
+ headers: buildHeaders(licenseKey),
2266
+ body: JSON.stringify(body)
2267
+ })
2268
+ ];
2269
+ case 1:
2270
+ response = _state.sent();
2271
+ if (!response.ok) {
2272
+ throw new Error("HTTP error! status: ".concat(response.status));
2273
+ }
2274
+ return [
2275
+ 4,
2276
+ response.json()
2277
+ ];
2278
+ case 2:
2279
+ _state.sent();
2280
+ return [
2281
+ 2
2282
+ ];
2283
+ }
2284
+ });
2285
+ })();
2286
+ }
2287
+ function buildPlayerMetricEvent(_0) {
2288
+ return _async_to_generator(function(licenseKey) {
2289
+ var context, flags, _flags_captureAt, clientInfo, browserId, captureAt;
2290
+ var _arguments = arguments;
2238
2291
  return _ts_generator(this, function(_state) {
2239
2292
  switch(_state.label){
2240
2293
  case 0:
2294
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, flags = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2295
+ clientInfo = getClientInfo();
2296
+ return [
2297
+ 4,
2298
+ getBrowserID(clientInfo)
2299
+ ];
2300
+ case 1:
2301
+ browserId = _state.sent();
2302
+ captureAt = (_flags_captureAt = flags.captureAt) !== null && _flags_captureAt !== void 0 ? _flags_captureAt : /* @__PURE__ */ new Date().toISOString();
2303
+ return [
2304
+ 2,
2305
+ {
2306
+ player_id: browserId,
2307
+ browserId: browserId,
2308
+ device_type: clientInfo.deviceType,
2309
+ deviceType: clientInfo.deviceType,
2310
+ input_stream_type: context.inputStreamType,
2311
+ os: clientInfo.os,
2312
+ ad_loaded: flags.adLoaded,
2313
+ ad_detect: flags.adDetect,
2314
+ license_key: licenseKey,
2315
+ capture_at: captureAt,
2316
+ timestamp: captureAt
2317
+ }
2318
+ ];
2319
+ }
2320
+ });
2321
+ }).apply(this, arguments);
2322
+ }
2323
+ function sendInitialTracking(_0) {
2324
+ return _async_to_generator(function(licenseKey) {
2325
+ var context, clientInfo, browserId, trackingData, error;
2326
+ var _arguments = arguments;
2327
+ return _ts_generator(this, function(_state) {
2328
+ switch(_state.label){
2329
+ case 0:
2330
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
2331
+ _state.label = 1;
2332
+ case 1:
2241
2333
  _state.trys.push([
2242
- 0,
2334
+ 1,
2243
2335
  4,
2244
2336
  ,
2245
2337
  5
@@ -2249,34 +2341,29 @@ function sendInitialTracking(licenseKey) {
2249
2341
  4,
2250
2342
  getBrowserID(clientInfo)
2251
2343
  ];
2252
- case 1:
2344
+ case 2:
2253
2345
  browserId = _state.sent();
2254
2346
  trackingData = _object_spread({
2255
2347
  browserId: browserId
2256
2348
  }, clientInfo);
2257
- headers = {
2258
- "Content-Type": "application/json"
2259
- };
2260
- if (licenseKey) {
2261
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2262
- }
2263
2349
  return [
2264
2350
  4,
2265
- fetch(TRACK_URL, {
2266
- method: "POST",
2267
- headers: headers,
2268
- body: JSON.stringify(trackingData)
2351
+ sendTrackRequest(licenseKey, {
2352
+ events: [
2353
+ {
2354
+ player_id: browserId,
2355
+ device_type: clientInfo.deviceType,
2356
+ input_stream_type: context.inputStreamType,
2357
+ os: clientInfo.os,
2358
+ ad_loaded: false,
2359
+ ad_detect: false,
2360
+ license_key: licenseKey,
2361
+ capture_at: /* @__PURE__ */ new Date().toISOString()
2362
+ }
2363
+ ],
2364
+ trackingData: trackingData
2269
2365
  })
2270
2366
  ];
2271
- case 2:
2272
- response = _state.sent();
2273
- if (!response.ok) {
2274
- throw new Error("HTTP error! status: ".concat(response.status));
2275
- }
2276
- return [
2277
- 4,
2278
- response.json()
2279
- ];
2280
2367
  case 3:
2281
2368
  _state.sent();
2282
2369
  return [
@@ -2296,36 +2383,30 @@ function sendInitialTracking(licenseKey) {
2296
2383
  ];
2297
2384
  }
2298
2385
  });
2299
- })();
2386
+ }).apply(this, arguments);
2300
2387
  }
2301
- function sendAdDetectTracking(licenseKey, adDetectInfo) {
2302
- return _async_to_generator(function() {
2303
- var clientInfo, browserId, trackingData, error;
2388
+ function sendAdDetectTracking(_0, _1) {
2389
+ return _async_to_generator(function(licenseKey, adDetectInfo) {
2390
+ var context, error;
2391
+ var _arguments = arguments;
2304
2392
  return _ts_generator(this, function(_state) {
2305
2393
  switch(_state.label){
2306
2394
  case 0:
2395
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2396
+ _state.label = 1;
2397
+ case 1:
2307
2398
  _state.trys.push([
2308
- 0,
2399
+ 1,
2309
2400
  3,
2310
2401
  ,
2311
2402
  4
2312
2403
  ]);
2313
- clientInfo = getClientInfo();
2314
- return [
2315
- 4,
2316
- getBrowserID(clientInfo)
2317
- ];
2318
- case 1:
2319
- browserId = _state.sent();
2320
- trackingData = _object_spread({
2321
- browserId: browserId
2322
- }, clientInfo);
2323
2404
  return [
2324
2405
  4,
2325
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2326
- licenseKey: licenseKey,
2327
- adDetectInfo: adDetectInfo
2328
- }))
2406
+ sendHeartbeat(licenseKey, context, {
2407
+ adDetect: true,
2408
+ captureAt: adDetectInfo.timestamp
2409
+ })
2329
2410
  ];
2330
2411
  case 2:
2331
2412
  _state.sent();
@@ -2346,36 +2427,30 @@ function sendAdDetectTracking(licenseKey, adDetectInfo) {
2346
2427
  ];
2347
2428
  }
2348
2429
  });
2349
- })();
2430
+ }).apply(this, arguments);
2350
2431
  }
2351
- function sendAdLoadedTracking(licenseKey, adLoadedInfo) {
2352
- return _async_to_generator(function() {
2353
- var clientInfo, browserId, trackingData, error;
2432
+ function sendAdLoadedTracking(_0, _1) {
2433
+ return _async_to_generator(function(licenseKey, adLoadedInfo) {
2434
+ var context, error;
2435
+ var _arguments = arguments;
2354
2436
  return _ts_generator(this, function(_state) {
2355
2437
  switch(_state.label){
2356
2438
  case 0:
2439
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2440
+ _state.label = 1;
2441
+ case 1:
2357
2442
  _state.trys.push([
2358
- 0,
2443
+ 1,
2359
2444
  3,
2360
2445
  ,
2361
2446
  4
2362
2447
  ]);
2363
- clientInfo = getClientInfo();
2364
- return [
2365
- 4,
2366
- getBrowserID(clientInfo)
2367
- ];
2368
- case 1:
2369
- browserId = _state.sent();
2370
- trackingData = _object_spread({
2371
- browserId: browserId
2372
- }, clientInfo);
2373
2448
  return [
2374
2449
  4,
2375
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2376
- licenseKey: licenseKey,
2377
- adLoadedInfo: adLoadedInfo
2378
- }))
2450
+ sendHeartbeat(licenseKey, context, {
2451
+ adLoaded: true,
2452
+ captureAt: adLoadedInfo.timestamp
2453
+ })
2379
2454
  ];
2380
2455
  case 2:
2381
2456
  _state.sent();
@@ -2396,103 +2471,95 @@ function sendAdLoadedTracking(licenseKey, adLoadedInfo) {
2396
2471
  ];
2397
2472
  }
2398
2473
  });
2399
- })();
2474
+ }).apply(this, arguments);
2400
2475
  }
2401
- function sendAdImpressionTracking(licenseKey, adImpressionInfo) {
2402
- return _async_to_generator(function() {
2403
- var clientInfo, browserId, trackingData, error;
2476
+ function sendAdImpressionTracking(_0, _1) {
2477
+ return _async_to_generator(function(licenseKey, adImpressionInfo) {
2478
+ var context, metricEvent, error;
2479
+ var _arguments = arguments;
2404
2480
  return _ts_generator(this, function(_state) {
2405
2481
  switch(_state.label){
2406
2482
  case 0:
2483
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2484
+ _state.label = 1;
2485
+ case 1:
2407
2486
  _state.trys.push([
2408
- 0,
2409
- 3,
2487
+ 1,
2488
+ 4,
2410
2489
  ,
2411
- 4
2490
+ 5
2412
2491
  ]);
2413
- clientInfo = getClientInfo();
2414
2492
  return [
2415
2493
  4,
2416
- getBrowserID(clientInfo)
2494
+ buildPlayerMetricEvent(licenseKey, context, {
2495
+ captureAt: adImpressionInfo.timestamp
2496
+ })
2417
2497
  ];
2418
- case 1:
2419
- browserId = _state.sent();
2420
- trackingData = _object_spread({
2421
- browserId: browserId
2422
- }, clientInfo);
2498
+ case 2:
2499
+ metricEvent = _state.sent();
2423
2500
  return [
2424
2501
  4,
2425
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2426
- licenseKey: licenseKey,
2427
- adImpressionInfo: adImpressionInfo
2428
- }))
2502
+ Promise.all([
2503
+ postJson(HEARTBEAT_URL, licenseKey, metricEvent),
2504
+ postJson(IMPRESSIONS_URL, licenseKey, {
2505
+ events: [
2506
+ {
2507
+ player_id: metricEvent.player_id,
2508
+ ad_played_count: 1,
2509
+ ad_url: adImpressionInfo.adUrl,
2510
+ license_key: licenseKey,
2511
+ capture_at: adImpressionInfo.timestamp
2512
+ }
2513
+ ]
2514
+ })
2515
+ ])
2429
2516
  ];
2430
- case 2:
2517
+ case 3:
2431
2518
  _state.sent();
2432
2519
  return [
2433
2520
  3,
2434
- 4
2521
+ 5
2435
2522
  ];
2436
- case 3:
2523
+ case 4:
2437
2524
  error = _state.sent();
2438
2525
  console.error("[StormcloudVideoPlayer] Error sending ad impression tracking:", error);
2439
2526
  return [
2440
2527
  3,
2441
- 4
2528
+ 5
2442
2529
  ];
2443
- case 4:
2530
+ case 5:
2444
2531
  return [
2445
2532
  2
2446
2533
  ];
2447
2534
  }
2448
2535
  });
2449
- })();
2536
+ }).apply(this, arguments);
2450
2537
  }
2451
- function sendHeartbeat(licenseKey) {
2452
- return _async_to_generator(function() {
2453
- var clientInfo, browserId, heartbeatData, headers, response, error;
2538
+ function sendHeartbeat(_0) {
2539
+ return _async_to_generator(function(licenseKey) {
2540
+ var context, flags, heartbeatData, error;
2541
+ var _arguments = arguments;
2454
2542
  return _ts_generator(this, function(_state) {
2455
2543
  switch(_state.label){
2456
2544
  case 0:
2545
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, flags = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2546
+ _state.label = 1;
2547
+ case 1:
2457
2548
  _state.trys.push([
2458
- 0,
2549
+ 1,
2459
2550
  4,
2460
2551
  ,
2461
2552
  5
2462
2553
  ]);
2463
- clientInfo = getClientInfo();
2464
- return [
2465
- 4,
2466
- getBrowserID(clientInfo)
2467
- ];
2468
- case 1:
2469
- browserId = _state.sent();
2470
- heartbeatData = {
2471
- browserId: browserId,
2472
- timestamp: /* @__PURE__ */ new Date().toISOString()
2473
- };
2474
- headers = {
2475
- "Content-Type": "application/json"
2476
- };
2477
- if (licenseKey) {
2478
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2479
- }
2480
2554
  return [
2481
2555
  4,
2482
- fetch("https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/heartbeat", {
2483
- method: "POST",
2484
- headers: headers,
2485
- body: JSON.stringify(heartbeatData)
2486
- })
2556
+ buildPlayerMetricEvent(licenseKey, context, flags)
2487
2557
  ];
2488
2558
  case 2:
2489
- response = _state.sent();
2490
- if (!response.ok) {
2491
- throw new Error("HTTP error! status: ".concat(response.status));
2492
- }
2559
+ heartbeatData = _state.sent();
2493
2560
  return [
2494
2561
  4,
2495
- response.json()
2562
+ postJson(HEARTBEAT_URL, licenseKey, heartbeatData)
2496
2563
  ];
2497
2564
  case 3:
2498
2565
  _state.sent();
@@ -2513,7 +2580,7 @@ function sendHeartbeat(licenseKey) {
2513
2580
  ];
2514
2581
  }
2515
2582
  });
2516
- })();
2583
+ }).apply(this, arguments);
2517
2584
  }
2518
2585
  // src/utils/polyfills.ts
2519
2586
  function polyfillURLSearchParams() {
@@ -3528,17 +3595,67 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3528
3595
  return "vast";
3529
3596
  }
3530
3597
  },
3598
+ {
3599
+ key: "getInputStreamType",
3600
+ value: function getInputStreamType() {
3601
+ var src = this.config.src.toLowerCase();
3602
+ if (src.includes(".m3u8")) return "hls";
3603
+ if (src.includes(".mpd")) return "dash";
3604
+ if (src.includes(".mp4")) return "mp4";
3605
+ return this.isLiveStream ? "live" : "vod";
3606
+ }
3607
+ },
3608
+ {
3609
+ key: "getAnalyticsContext",
3610
+ value: function getAnalyticsContext() {
3611
+ return {
3612
+ inputStreamType: this.getInputStreamType()
3613
+ };
3614
+ }
3615
+ },
3616
+ {
3617
+ key: "getAdUrlFromBids",
3618
+ value: function getAdUrlFromBids(bids) {
3619
+ var _bids_;
3620
+ return bids === null || bids === void 0 ? void 0 : (_bids_ = bids[0]) === null || _bids_ === void 0 ? void 0 : _bids_.vastUrl;
3621
+ }
3622
+ },
3623
+ {
3624
+ key: "trackAdLoaded",
3625
+ value: function trackAdLoaded(bids) {
3626
+ if (!this.config.licenseKey) return;
3627
+ var adUrl = this.getAdUrlFromBids(bids);
3628
+ if (adUrl) {
3629
+ this.lastServedAdUrl = adUrl;
3630
+ }
3631
+ sendAdLoadedTracking(this.config.licenseKey, _object_spread_props(_object_spread({
3632
+ source: this.getAdSource()
3633
+ }, adUrl ? {
3634
+ vastUrl: adUrl
3635
+ } : {}), {
3636
+ timestamp: /* @__PURE__ */ new Date().toISOString()
3637
+ }), this.getAnalyticsContext());
3638
+ }
3639
+ },
3531
3640
  {
3532
3641
  key: "attachAdLayerEventListeners",
3533
3642
  value: function attachAdLayerEventListeners() {
3534
3643
  var _this = this;
3535
- this.adLayer.on("ad_impression", function() {
3644
+ this.adLayer.on("ad_impression", function(payload) {
3536
3645
  if (_this.config.licenseKey) {
3537
- sendAdImpressionTracking(_this.config.licenseKey, {
3646
+ var _ref;
3647
+ var adUrl = (_ref = payload === null || payload === void 0 ? void 0 : payload.adUrl) !== null && _ref !== void 0 ? _ref : _this.lastServedAdUrl;
3648
+ if (adUrl) {
3649
+ _this.lastServedAdUrl = adUrl;
3650
+ }
3651
+ sendAdImpressionTracking(_this.config.licenseKey, _object_spread_props(_object_spread({
3538
3652
  source: _this.getAdSource(),
3539
- adIndex: _this.currentAdIndex,
3653
+ adIndex: _this.currentAdIndex
3654
+ }, adUrl ? {
3655
+ adUrl: adUrl
3656
+ } : {}), {
3540
3657
  timestamp: /* @__PURE__ */ new Date().toISOString()
3541
- });
3658
+ }), _this.getAnalyticsContext());
3542
3659
  }
3543
3660
  });
3544
3661
  this.adLayer.on("ad_error", function(errorPayload) {
@@ -3632,6 +3749,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3632
3749
  _this.isInAdTransition = false;
3633
3750
  if (!_this.inAdBreak) return;
3634
3751
  _this.currentAdIndex++;
3752
+ _this.trackAdLoaded();
3635
3753
  _this.adLayer.playPreloaded(token).catch(function(err) {
3636
3754
  if (_this.config.debugAdTiming) console.warn("[StormcloudVideoPlayer] playPreloaded failed:", err);
3637
3755
  _this.handleAdFailure();
@@ -3661,6 +3779,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3661
3779
  var freshBids = (_this_pendingNextAdBids = _this.pendingNextAdBids) !== null && _this_pendingNextAdBids !== void 0 ? _this_pendingNextAdBids : bids;
3662
3780
  _this.pendingNextAdBids = null;
3663
3781
  _this.currentAdIndex++;
3782
+ _this.trackAdLoaded(freshBids);
3664
3783
  _this.adLayer.playAd(freshBids).catch(function(err) {
3665
3784
  if (_this.config.debugAdTiming) console.warn("[StormcloudVideoPlayer] playAd(pending) failed:", err);
3666
3785
  _this.handleAdFailure();
@@ -4040,7 +4159,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4040
4159
  }, ((_this_pendingAdBreak1 = this.pendingAdBreak) === null || _this_pendingAdBreak1 === void 0 ? void 0 : _this_pendingAdBreak1.detectedAtFragmentSn) != null && {
4041
4160
  detectedAtFragmentSn: this.pendingAdBreak.detectedAtFragmentSn
4042
4161
  });
4043
- sendAdDetectTracking(this.config.licenseKey, adDetectInfo);
4162
+ sendAdDetectTracking(this.config.licenseKey, adDetectInfo, this.getAnalyticsContext());
4044
4163
  }
4045
4164
  var isManifestMarker = this.isManifestBasedMarker(marker);
4046
4165
  var forceImmediate = (_this_config_immediateManifestAds = this.config.immediateManifestAds) !== null && _this_config_immediateManifestAds !== void 0 ? _this_config_immediateManifestAds : true;
@@ -4109,6 +4228,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4109
4228
  var bids = this.pendingNextAdBids;
4110
4229
  this.pendingNextAdBids = null;
4111
4230
  this.currentAdIndex++;
4231
+ this.trackAdLoaded(bids);
4112
4232
  this.adLayer.playAd(bids).catch(function() {
4113
4233
  return _this.handleAdFailure();
4114
4234
  });
@@ -4363,7 +4483,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4363
4483
  key: "initializeTracking",
4364
4484
  value: function initializeTracking() {
4365
4485
  var _this = this;
4366
- sendInitialTracking(this.config.licenseKey).then(function() {
4486
+ sendInitialTracking(this.config.licenseKey, this.getAnalyticsContext()).then(function() {
4367
4487
  _this.heartbeatInterval = window.setInterval(function() {
4368
4488
  _this.sendHeartbeatIfNeeded();
4369
4489
  }, 5e3);
@@ -4384,7 +4504,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4384
4504
  var now = Date.now();
4385
4505
  if (!this.lastHeartbeatTime || now - this.lastHeartbeatTime > 3e4) {
4386
4506
  this.lastHeartbeatTime = now;
4387
- sendHeartbeat(this.config.licenseKey).catch(function(error) {
4507
+ sendHeartbeat(this.config.licenseKey, this.getAnalyticsContext()).catch(function(error) {
4388
4508
  if (_this.config.debugAdTiming) {
4389
4509
  console.warn("[StormcloudVideoPlayer] Failed to send heartbeat:", error);
4390
4510
  }
@@ -4777,12 +4897,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4777
4897
  10
4778
4898
  ];
4779
4899
  _this.currentAdIndex++;
4780
- if (_this.config.licenseKey) {
4781
- sendAdLoadedTracking(_this.config.licenseKey, {
4782
- source: _this.getAdSource(),
4783
- timestamp: /* @__PURE__ */ new Date().toISOString()
4784
- });
4785
- }
4900
+ _this.trackAdLoaded(bids1);
4786
4901
  return [
4787
4902
  4,
4788
4903
  _this.adLayer.playAd(bids1)
@@ -4887,12 +5002,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4887
5002
  ];
4888
5003
  case 18:
4889
5004
  _this.currentAdIndex++;
4890
- if (_this.config.licenseKey) {
4891
- sendAdLoadedTracking(_this.config.licenseKey, {
4892
- source: _this.getAdSource(),
4893
- timestamp: /* @__PURE__ */ new Date().toISOString()
4894
- });
4895
- }
5005
+ _this.trackAdLoaded(bids2);
4896
5006
  return [
4897
5007
  4,
4898
5008
  _this.adLayer.playAd(bids2)
@@ -5051,12 +5161,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5051
5161
  6
5052
5162
  ];
5053
5163
  this.currentAdIndex++;
5054
- if (this.config.licenseKey) {
5055
- sendAdLoadedTracking(this.config.licenseKey, {
5056
- source: this.getAdSource(),
5057
- timestamp: /* @__PURE__ */ new Date().toISOString()
5058
- });
5059
- }
5164
+ this.trackAdLoaded();
5060
5165
  _state.label = 1;
5061
5166
  case 1:
5062
5167
  _state.trys.push([
@@ -5250,12 +5355,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5250
5355
  5
5251
5356
  ];
5252
5357
  case 3:
5253
- if (this.config.licenseKey) {
5254
- sendAdLoadedTracking(this.config.licenseKey, {
5255
- source: this.getAdSource(),
5256
- timestamp: /* @__PURE__ */ new Date().toISOString()
5257
- });
5258
- }
5358
+ this.trackAdLoaded(bids);
5259
5359
  return [
5260
5360
  4,
5261
5361
  this.adLayer.playAd(bids)
@@ -5401,6 +5501,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5401
5501
  ,
5402
5502
  7
5403
5503
  ]);
5504
+ this.trackAdLoaded(bids);
5404
5505
  return [
5405
5506
  4,
5406
5507
  this.adLayer.playAd(bids)