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.
@@ -975,6 +975,7 @@ function createVastAdLayer(contentVideo, options) {
975
975
  var adHls;
976
976
  var adContainerEl;
977
977
  var currentAd;
978
+ var currentMediaFile;
978
979
  var sessionId;
979
980
  var destroyed = false;
980
981
  var tornDown = false;
@@ -1221,7 +1222,12 @@ function createVastAdLayer(contentVideo, options) {
1221
1222
  adContainerEl.style.display = "none";
1222
1223
  adContainerEl.style.pointerEvents = "none";
1223
1224
  }
1224
- emit("ad_impression");
1225
+ emit("ad_impression", {
1226
+ adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
1227
+ adTitle: currentAd === null || currentAd === void 0 ? void 0 : currentAd.title,
1228
+ adUrl: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.url,
1229
+ mediaType: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.type
1230
+ });
1225
1231
  emit("content_resume");
1226
1232
  }
1227
1233
  function handleAdError() {
@@ -1243,6 +1249,7 @@ function createVastAdLayer(contentVideo, options) {
1243
1249
  adHls.destroy();
1244
1250
  adHls = void 0;
1245
1251
  }
1252
+ currentMediaFile = void 0;
1246
1253
  if (adVideoElement) {
1247
1254
  if (singleElementMode && adVideoElement === contentVideo) {
1248
1255
  contentVideo.pause();
@@ -1407,6 +1414,7 @@ function createVastAdLayer(contentVideo, options) {
1407
1414
  adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
1408
1415
  adVideoElement.muted = false;
1409
1416
  mediaFile2 = selectBestMediaFile(ad.mediaFiles);
1417
+ currentMediaFile = mediaFile2;
1410
1418
  if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
1411
1419
  startPlayback(mediaFile2);
1412
1420
  return [
@@ -1453,6 +1461,7 @@ function createVastAdLayer(contentVideo, options) {
1453
1461
  }
1454
1462
  emit("content_pause");
1455
1463
  mediaFile = selectBestMediaFile(ad.mediaFiles);
1464
+ currentMediaFile = mediaFile;
1456
1465
  if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile.url));
1457
1466
  startPlayback(mediaFile);
1458
1467
  return [
@@ -1618,6 +1627,7 @@ function createVastAdLayer(contentVideo, options) {
1618
1627
  ];
1619
1628
  mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1620
1629
  teardownCurrentPlayback();
1630
+ currentMediaFile = slot.mediaFile;
1621
1631
  adVideoElement = contentVideo;
1622
1632
  adHls = void 0;
1623
1633
  adPlaying = true;
@@ -1652,6 +1662,7 @@ function createVastAdLayer(contentVideo, options) {
1652
1662
  case 2:
1653
1663
  if (smartTVMode && !slot.videoEl) {
1654
1664
  teardownCurrentPlayback();
1665
+ currentMediaFile = slot.mediaFile;
1655
1666
  if (adVideoElement) {
1656
1667
  adVideoElement.remove();
1657
1668
  adVideoElement = void 0;
@@ -1683,6 +1694,7 @@ function createVastAdLayer(contentVideo, options) {
1683
1694
  ];
1684
1695
  }
1685
1696
  teardownCurrentPlayback();
1697
+ currentMediaFile = slot.mediaFile;
1686
1698
  if (adVideoElement && adVideoElement !== slot.videoEl) {
1687
1699
  adVideoElement.remove();
1688
1700
  }
@@ -1814,6 +1826,7 @@ function createVastAdLayer(contentVideo, options) {
1814
1826
  }
1815
1827
  }
1816
1828
  currentAd = void 0;
1829
+ currentMediaFile = void 0;
1817
1830
  tornDown = false;
1818
1831
  return [
1819
1832
  2
@@ -1866,6 +1879,7 @@ function createVastAdLayer(contentVideo, options) {
1866
1879
  }
1867
1880
  adContainerEl = void 0;
1868
1881
  currentAd = void 0;
1882
+ currentMediaFile = void 0;
1869
1883
  listeners.clear();
1870
1884
  },
1871
1885
  isAdPlaying: function isAdPlaying() {
@@ -2179,24 +2193,30 @@ function getBrowserID(clientInfo) {
2179
2193
  });
2180
2194
  })();
2181
2195
  }
2182
- var TRACK_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track";
2196
+ var PLAYER_TRACKING_BASE_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking";
2197
+ var TRACK_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/metrics/ingest");
2198
+ var HEARTBEAT_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/heartbeat");
2199
+ var IMPRESSIONS_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/impressions/ingest");
2200
+ function buildHeaders(licenseKey) {
2201
+ var headers = {
2202
+ "Content-Type": "application/json"
2203
+ };
2204
+ if (licenseKey) {
2205
+ headers["Authorization"] = "Bearer ".concat(licenseKey);
2206
+ }
2207
+ return headers;
2208
+ }
2183
2209
  function sendTrackRequest(licenseKey, body) {
2184
2210
  return _async_to_generator(function() {
2185
- var headers, response;
2211
+ var response;
2186
2212
  return _ts_generator(this, function(_state) {
2187
2213
  switch(_state.label){
2188
2214
  case 0:
2189
- headers = {
2190
- "Content-Type": "application/json"
2191
- };
2192
- if (licenseKey) {
2193
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2194
- }
2195
2215
  return [
2196
2216
  4,
2197
2217
  fetch(TRACK_URL, {
2198
2218
  method: "POST",
2199
- headers: headers,
2219
+ headers: buildHeaders(licenseKey),
2200
2220
  body: JSON.stringify(body)
2201
2221
  })
2202
2222
  ];
@@ -2218,14 +2238,86 @@ function sendTrackRequest(licenseKey, body) {
2218
2238
  });
2219
2239
  })();
2220
2240
  }
2221
- function sendInitialTracking(licenseKey) {
2241
+ function postJson(url, licenseKey, body) {
2222
2242
  return _async_to_generator(function() {
2223
- var clientInfo, browserId, trackingData, headers, response, error;
2243
+ var response;
2244
+ return _ts_generator(this, function(_state) {
2245
+ switch(_state.label){
2246
+ case 0:
2247
+ return [
2248
+ 4,
2249
+ fetch(url, {
2250
+ method: "POST",
2251
+ headers: buildHeaders(licenseKey),
2252
+ body: JSON.stringify(body)
2253
+ })
2254
+ ];
2255
+ case 1:
2256
+ response = _state.sent();
2257
+ if (!response.ok) {
2258
+ throw new Error("HTTP error! status: ".concat(response.status));
2259
+ }
2260
+ return [
2261
+ 4,
2262
+ response.json()
2263
+ ];
2264
+ case 2:
2265
+ _state.sent();
2266
+ return [
2267
+ 2
2268
+ ];
2269
+ }
2270
+ });
2271
+ })();
2272
+ }
2273
+ function buildPlayerMetricEvent(_0) {
2274
+ return _async_to_generator(function(licenseKey) {
2275
+ var context, flags, _flags_captureAt, clientInfo, browserId, captureAt;
2276
+ var _arguments = arguments;
2277
+ return _ts_generator(this, function(_state) {
2278
+ switch(_state.label){
2279
+ case 0:
2280
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, flags = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2281
+ clientInfo = getClientInfo();
2282
+ return [
2283
+ 4,
2284
+ getBrowserID(clientInfo)
2285
+ ];
2286
+ case 1:
2287
+ browserId = _state.sent();
2288
+ captureAt = (_flags_captureAt = flags.captureAt) !== null && _flags_captureAt !== void 0 ? _flags_captureAt : /* @__PURE__ */ new Date().toISOString();
2289
+ return [
2290
+ 2,
2291
+ {
2292
+ player_id: browserId,
2293
+ browserId: browserId,
2294
+ device_type: clientInfo.deviceType,
2295
+ deviceType: clientInfo.deviceType,
2296
+ input_stream_type: context.inputStreamType,
2297
+ os: clientInfo.os,
2298
+ ad_loaded: flags.adLoaded,
2299
+ ad_detect: flags.adDetect,
2300
+ license_key: licenseKey,
2301
+ capture_at: captureAt,
2302
+ timestamp: captureAt
2303
+ }
2304
+ ];
2305
+ }
2306
+ });
2307
+ }).apply(this, arguments);
2308
+ }
2309
+ function sendInitialTracking(_0) {
2310
+ return _async_to_generator(function(licenseKey) {
2311
+ var context, clientInfo, browserId, trackingData, error;
2312
+ var _arguments = arguments;
2224
2313
  return _ts_generator(this, function(_state) {
2225
2314
  switch(_state.label){
2226
2315
  case 0:
2316
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
2317
+ _state.label = 1;
2318
+ case 1:
2227
2319
  _state.trys.push([
2228
- 0,
2320
+ 1,
2229
2321
  4,
2230
2322
  ,
2231
2323
  5
@@ -2235,34 +2327,29 @@ function sendInitialTracking(licenseKey) {
2235
2327
  4,
2236
2328
  getBrowserID(clientInfo)
2237
2329
  ];
2238
- case 1:
2330
+ case 2:
2239
2331
  browserId = _state.sent();
2240
2332
  trackingData = _object_spread({
2241
2333
  browserId: browserId
2242
2334
  }, clientInfo);
2243
- headers = {
2244
- "Content-Type": "application/json"
2245
- };
2246
- if (licenseKey) {
2247
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2248
- }
2249
2335
  return [
2250
2336
  4,
2251
- fetch(TRACK_URL, {
2252
- method: "POST",
2253
- headers: headers,
2254
- body: JSON.stringify(trackingData)
2337
+ sendTrackRequest(licenseKey, {
2338
+ events: [
2339
+ {
2340
+ player_id: browserId,
2341
+ device_type: clientInfo.deviceType,
2342
+ input_stream_type: context.inputStreamType,
2343
+ os: clientInfo.os,
2344
+ ad_loaded: false,
2345
+ ad_detect: false,
2346
+ license_key: licenseKey,
2347
+ capture_at: /* @__PURE__ */ new Date().toISOString()
2348
+ }
2349
+ ],
2350
+ trackingData: trackingData
2255
2351
  })
2256
2352
  ];
2257
- case 2:
2258
- response = _state.sent();
2259
- if (!response.ok) {
2260
- throw new Error("HTTP error! status: ".concat(response.status));
2261
- }
2262
- return [
2263
- 4,
2264
- response.json()
2265
- ];
2266
2353
  case 3:
2267
2354
  _state.sent();
2268
2355
  return [
@@ -2282,36 +2369,30 @@ function sendInitialTracking(licenseKey) {
2282
2369
  ];
2283
2370
  }
2284
2371
  });
2285
- })();
2372
+ }).apply(this, arguments);
2286
2373
  }
2287
- function sendAdDetectTracking(licenseKey, adDetectInfo) {
2288
- return _async_to_generator(function() {
2289
- var clientInfo, browserId, trackingData, error;
2374
+ function sendAdDetectTracking(_0, _1) {
2375
+ return _async_to_generator(function(licenseKey, adDetectInfo) {
2376
+ var context, error;
2377
+ var _arguments = arguments;
2290
2378
  return _ts_generator(this, function(_state) {
2291
2379
  switch(_state.label){
2292
2380
  case 0:
2381
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2382
+ _state.label = 1;
2383
+ case 1:
2293
2384
  _state.trys.push([
2294
- 0,
2385
+ 1,
2295
2386
  3,
2296
2387
  ,
2297
2388
  4
2298
2389
  ]);
2299
- clientInfo = getClientInfo();
2300
2390
  return [
2301
2391
  4,
2302
- getBrowserID(clientInfo)
2303
- ];
2304
- case 1:
2305
- browserId = _state.sent();
2306
- trackingData = _object_spread({
2307
- browserId: browserId
2308
- }, clientInfo);
2309
- return [
2310
- 4,
2311
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2312
- licenseKey: licenseKey,
2313
- adDetectInfo: adDetectInfo
2314
- }))
2392
+ sendHeartbeat(licenseKey, context, {
2393
+ adDetect: true,
2394
+ captureAt: adDetectInfo.timestamp
2395
+ })
2315
2396
  ];
2316
2397
  case 2:
2317
2398
  _state.sent();
@@ -2332,36 +2413,30 @@ function sendAdDetectTracking(licenseKey, adDetectInfo) {
2332
2413
  ];
2333
2414
  }
2334
2415
  });
2335
- })();
2416
+ }).apply(this, arguments);
2336
2417
  }
2337
- function sendAdLoadedTracking(licenseKey, adLoadedInfo) {
2338
- return _async_to_generator(function() {
2339
- var clientInfo, browserId, trackingData, error;
2418
+ function sendAdLoadedTracking(_0, _1) {
2419
+ return _async_to_generator(function(licenseKey, adLoadedInfo) {
2420
+ var context, error;
2421
+ var _arguments = arguments;
2340
2422
  return _ts_generator(this, function(_state) {
2341
2423
  switch(_state.label){
2342
2424
  case 0:
2425
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2426
+ _state.label = 1;
2427
+ case 1:
2343
2428
  _state.trys.push([
2344
- 0,
2429
+ 1,
2345
2430
  3,
2346
2431
  ,
2347
2432
  4
2348
2433
  ]);
2349
- clientInfo = getClientInfo();
2350
2434
  return [
2351
2435
  4,
2352
- getBrowserID(clientInfo)
2353
- ];
2354
- case 1:
2355
- browserId = _state.sent();
2356
- trackingData = _object_spread({
2357
- browserId: browserId
2358
- }, clientInfo);
2359
- return [
2360
- 4,
2361
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2362
- licenseKey: licenseKey,
2363
- adLoadedInfo: adLoadedInfo
2364
- }))
2436
+ sendHeartbeat(licenseKey, context, {
2437
+ adLoaded: true,
2438
+ captureAt: adLoadedInfo.timestamp
2439
+ })
2365
2440
  ];
2366
2441
  case 2:
2367
2442
  _state.sent();
@@ -2382,103 +2457,95 @@ function sendAdLoadedTracking(licenseKey, adLoadedInfo) {
2382
2457
  ];
2383
2458
  }
2384
2459
  });
2385
- })();
2460
+ }).apply(this, arguments);
2386
2461
  }
2387
- function sendAdImpressionTracking(licenseKey, adImpressionInfo) {
2388
- return _async_to_generator(function() {
2389
- var clientInfo, browserId, trackingData, error;
2462
+ function sendAdImpressionTracking(_0, _1) {
2463
+ return _async_to_generator(function(licenseKey, adImpressionInfo) {
2464
+ var context, metricEvent, error;
2465
+ var _arguments = arguments;
2390
2466
  return _ts_generator(this, function(_state) {
2391
2467
  switch(_state.label){
2392
2468
  case 0:
2469
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2470
+ _state.label = 1;
2471
+ case 1:
2393
2472
  _state.trys.push([
2394
- 0,
2395
- 3,
2473
+ 1,
2474
+ 4,
2396
2475
  ,
2397
- 4
2476
+ 5
2398
2477
  ]);
2399
- clientInfo = getClientInfo();
2400
2478
  return [
2401
2479
  4,
2402
- getBrowserID(clientInfo)
2480
+ buildPlayerMetricEvent(licenseKey, context, {
2481
+ captureAt: adImpressionInfo.timestamp
2482
+ })
2403
2483
  ];
2404
- case 1:
2405
- browserId = _state.sent();
2406
- trackingData = _object_spread({
2407
- browserId: browserId
2408
- }, clientInfo);
2484
+ case 2:
2485
+ metricEvent = _state.sent();
2409
2486
  return [
2410
2487
  4,
2411
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2412
- licenseKey: licenseKey,
2413
- adImpressionInfo: adImpressionInfo
2414
- }))
2488
+ Promise.all([
2489
+ postJson(HEARTBEAT_URL, licenseKey, metricEvent),
2490
+ postJson(IMPRESSIONS_URL, licenseKey, {
2491
+ events: [
2492
+ {
2493
+ player_id: metricEvent.player_id,
2494
+ ad_played_count: 1,
2495
+ ad_url: adImpressionInfo.adUrl,
2496
+ license_key: licenseKey,
2497
+ capture_at: adImpressionInfo.timestamp
2498
+ }
2499
+ ]
2500
+ })
2501
+ ])
2415
2502
  ];
2416
- case 2:
2503
+ case 3:
2417
2504
  _state.sent();
2418
2505
  return [
2419
2506
  3,
2420
- 4
2507
+ 5
2421
2508
  ];
2422
- case 3:
2509
+ case 4:
2423
2510
  error = _state.sent();
2424
2511
  console.error("[StormcloudVideoPlayer] Error sending ad impression tracking:", error);
2425
2512
  return [
2426
2513
  3,
2427
- 4
2514
+ 5
2428
2515
  ];
2429
- case 4:
2516
+ case 5:
2430
2517
  return [
2431
2518
  2
2432
2519
  ];
2433
2520
  }
2434
2521
  });
2435
- })();
2522
+ }).apply(this, arguments);
2436
2523
  }
2437
- function sendHeartbeat(licenseKey) {
2438
- return _async_to_generator(function() {
2439
- var clientInfo, browserId, heartbeatData, headers, response, error;
2524
+ function sendHeartbeat(_0) {
2525
+ return _async_to_generator(function(licenseKey) {
2526
+ var context, flags, heartbeatData, error;
2527
+ var _arguments = arguments;
2440
2528
  return _ts_generator(this, function(_state) {
2441
2529
  switch(_state.label){
2442
2530
  case 0:
2531
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, flags = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2532
+ _state.label = 1;
2533
+ case 1:
2443
2534
  _state.trys.push([
2444
- 0,
2535
+ 1,
2445
2536
  4,
2446
2537
  ,
2447
2538
  5
2448
2539
  ]);
2449
- clientInfo = getClientInfo();
2450
- return [
2451
- 4,
2452
- getBrowserID(clientInfo)
2453
- ];
2454
- case 1:
2455
- browserId = _state.sent();
2456
- heartbeatData = {
2457
- browserId: browserId,
2458
- timestamp: /* @__PURE__ */ new Date().toISOString()
2459
- };
2460
- headers = {
2461
- "Content-Type": "application/json"
2462
- };
2463
- if (licenseKey) {
2464
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2465
- }
2466
2540
  return [
2467
2541
  4,
2468
- fetch("https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/heartbeat", {
2469
- method: "POST",
2470
- headers: headers,
2471
- body: JSON.stringify(heartbeatData)
2472
- })
2542
+ buildPlayerMetricEvent(licenseKey, context, flags)
2473
2543
  ];
2474
2544
  case 2:
2475
- response = _state.sent();
2476
- if (!response.ok) {
2477
- throw new Error("HTTP error! status: ".concat(response.status));
2478
- }
2545
+ heartbeatData = _state.sent();
2479
2546
  return [
2480
2547
  4,
2481
- response.json()
2548
+ postJson(HEARTBEAT_URL, licenseKey, heartbeatData)
2482
2549
  ];
2483
2550
  case 3:
2484
2551
  _state.sent();
@@ -2499,7 +2566,7 @@ function sendHeartbeat(licenseKey) {
2499
2566
  ];
2500
2567
  }
2501
2568
  });
2502
- })();
2569
+ }).apply(this, arguments);
2503
2570
  }
2504
2571
  // src/utils/polyfills.ts
2505
2572
  function polyfillURLSearchParams() {
@@ -3514,17 +3581,67 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3514
3581
  return "vast";
3515
3582
  }
3516
3583
  },
3584
+ {
3585
+ key: "getInputStreamType",
3586
+ value: function getInputStreamType() {
3587
+ var src = this.config.src.toLowerCase();
3588
+ if (src.includes(".m3u8")) return "hls";
3589
+ if (src.includes(".mpd")) return "dash";
3590
+ if (src.includes(".mp4")) return "mp4";
3591
+ return this.isLiveStream ? "live" : "vod";
3592
+ }
3593
+ },
3594
+ {
3595
+ key: "getAnalyticsContext",
3596
+ value: function getAnalyticsContext() {
3597
+ return {
3598
+ inputStreamType: this.getInputStreamType()
3599
+ };
3600
+ }
3601
+ },
3602
+ {
3603
+ key: "getAdUrlFromBids",
3604
+ value: function getAdUrlFromBids(bids) {
3605
+ var _bids_;
3606
+ return bids === null || bids === void 0 ? void 0 : (_bids_ = bids[0]) === null || _bids_ === void 0 ? void 0 : _bids_.vastUrl;
3607
+ }
3608
+ },
3609
+ {
3610
+ key: "trackAdLoaded",
3611
+ value: function trackAdLoaded(bids) {
3612
+ if (!this.config.licenseKey) return;
3613
+ var adUrl = this.getAdUrlFromBids(bids);
3614
+ if (adUrl) {
3615
+ this.lastServedAdUrl = adUrl;
3616
+ }
3617
+ sendAdLoadedTracking(this.config.licenseKey, _object_spread_props(_object_spread({
3618
+ source: this.getAdSource()
3619
+ }, adUrl ? {
3620
+ vastUrl: adUrl
3621
+ } : {}), {
3622
+ timestamp: /* @__PURE__ */ new Date().toISOString()
3623
+ }), this.getAnalyticsContext());
3624
+ }
3625
+ },
3517
3626
  {
3518
3627
  key: "attachAdLayerEventListeners",
3519
3628
  value: function attachAdLayerEventListeners() {
3520
3629
  var _this = this;
3521
- this.adLayer.on("ad_impression", function() {
3630
+ this.adLayer.on("ad_impression", function(payload) {
3522
3631
  if (_this.config.licenseKey) {
3523
- sendAdImpressionTracking(_this.config.licenseKey, {
3632
+ var _ref;
3633
+ var adUrl = (_ref = payload === null || payload === void 0 ? void 0 : payload.adUrl) !== null && _ref !== void 0 ? _ref : _this.lastServedAdUrl;
3634
+ if (adUrl) {
3635
+ _this.lastServedAdUrl = adUrl;
3636
+ }
3637
+ sendAdImpressionTracking(_this.config.licenseKey, _object_spread_props(_object_spread({
3524
3638
  source: _this.getAdSource(),
3525
- adIndex: _this.currentAdIndex,
3639
+ adIndex: _this.currentAdIndex
3640
+ }, adUrl ? {
3641
+ adUrl: adUrl
3642
+ } : {}), {
3526
3643
  timestamp: /* @__PURE__ */ new Date().toISOString()
3527
- });
3644
+ }), _this.getAnalyticsContext());
3528
3645
  }
3529
3646
  });
3530
3647
  this.adLayer.on("ad_error", function(errorPayload) {
@@ -3618,6 +3735,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3618
3735
  _this.isInAdTransition = false;
3619
3736
  if (!_this.inAdBreak) return;
3620
3737
  _this.currentAdIndex++;
3738
+ _this.trackAdLoaded();
3621
3739
  _this.adLayer.playPreloaded(token).catch(function(err) {
3622
3740
  if (_this.config.debugAdTiming) console.warn("[StormcloudVideoPlayer] playPreloaded failed:", err);
3623
3741
  _this.handleAdFailure();
@@ -3647,6 +3765,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3647
3765
  var freshBids = (_this_pendingNextAdBids = _this.pendingNextAdBids) !== null && _this_pendingNextAdBids !== void 0 ? _this_pendingNextAdBids : bids;
3648
3766
  _this.pendingNextAdBids = null;
3649
3767
  _this.currentAdIndex++;
3768
+ _this.trackAdLoaded(freshBids);
3650
3769
  _this.adLayer.playAd(freshBids).catch(function(err) {
3651
3770
  if (_this.config.debugAdTiming) console.warn("[StormcloudVideoPlayer] playAd(pending) failed:", err);
3652
3771
  _this.handleAdFailure();
@@ -4026,7 +4145,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4026
4145
  }, ((_this_pendingAdBreak1 = this.pendingAdBreak) === null || _this_pendingAdBreak1 === void 0 ? void 0 : _this_pendingAdBreak1.detectedAtFragmentSn) != null && {
4027
4146
  detectedAtFragmentSn: this.pendingAdBreak.detectedAtFragmentSn
4028
4147
  });
4029
- sendAdDetectTracking(this.config.licenseKey, adDetectInfo);
4148
+ sendAdDetectTracking(this.config.licenseKey, adDetectInfo, this.getAnalyticsContext());
4030
4149
  }
4031
4150
  var isManifestMarker = this.isManifestBasedMarker(marker);
4032
4151
  var forceImmediate = (_this_config_immediateManifestAds = this.config.immediateManifestAds) !== null && _this_config_immediateManifestAds !== void 0 ? _this_config_immediateManifestAds : true;
@@ -4095,6 +4214,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4095
4214
  var bids = this.pendingNextAdBids;
4096
4215
  this.pendingNextAdBids = null;
4097
4216
  this.currentAdIndex++;
4217
+ this.trackAdLoaded(bids);
4098
4218
  this.adLayer.playAd(bids).catch(function() {
4099
4219
  return _this.handleAdFailure();
4100
4220
  });
@@ -4349,7 +4469,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4349
4469
  key: "initializeTracking",
4350
4470
  value: function initializeTracking() {
4351
4471
  var _this = this;
4352
- sendInitialTracking(this.config.licenseKey).then(function() {
4472
+ sendInitialTracking(this.config.licenseKey, this.getAnalyticsContext()).then(function() {
4353
4473
  _this.heartbeatInterval = window.setInterval(function() {
4354
4474
  _this.sendHeartbeatIfNeeded();
4355
4475
  }, 5e3);
@@ -4370,7 +4490,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4370
4490
  var now = Date.now();
4371
4491
  if (!this.lastHeartbeatTime || now - this.lastHeartbeatTime > 3e4) {
4372
4492
  this.lastHeartbeatTime = now;
4373
- sendHeartbeat(this.config.licenseKey).catch(function(error) {
4493
+ sendHeartbeat(this.config.licenseKey, this.getAnalyticsContext()).catch(function(error) {
4374
4494
  if (_this.config.debugAdTiming) {
4375
4495
  console.warn("[StormcloudVideoPlayer] Failed to send heartbeat:", error);
4376
4496
  }
@@ -4763,12 +4883,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4763
4883
  10
4764
4884
  ];
4765
4885
  _this.currentAdIndex++;
4766
- if (_this.config.licenseKey) {
4767
- sendAdLoadedTracking(_this.config.licenseKey, {
4768
- source: _this.getAdSource(),
4769
- timestamp: /* @__PURE__ */ new Date().toISOString()
4770
- });
4771
- }
4886
+ _this.trackAdLoaded(bids1);
4772
4887
  return [
4773
4888
  4,
4774
4889
  _this.adLayer.playAd(bids1)
@@ -4873,12 +4988,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4873
4988
  ];
4874
4989
  case 18:
4875
4990
  _this.currentAdIndex++;
4876
- if (_this.config.licenseKey) {
4877
- sendAdLoadedTracking(_this.config.licenseKey, {
4878
- source: _this.getAdSource(),
4879
- timestamp: /* @__PURE__ */ new Date().toISOString()
4880
- });
4881
- }
4991
+ _this.trackAdLoaded(bids2);
4882
4992
  return [
4883
4993
  4,
4884
4994
  _this.adLayer.playAd(bids2)
@@ -5037,12 +5147,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5037
5147
  6
5038
5148
  ];
5039
5149
  this.currentAdIndex++;
5040
- if (this.config.licenseKey) {
5041
- sendAdLoadedTracking(this.config.licenseKey, {
5042
- source: this.getAdSource(),
5043
- timestamp: /* @__PURE__ */ new Date().toISOString()
5044
- });
5045
- }
5150
+ this.trackAdLoaded();
5046
5151
  _state.label = 1;
5047
5152
  case 1:
5048
5153
  _state.trys.push([
@@ -5236,12 +5341,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5236
5341
  5
5237
5342
  ];
5238
5343
  case 3:
5239
- if (this.config.licenseKey) {
5240
- sendAdLoadedTracking(this.config.licenseKey, {
5241
- source: this.getAdSource(),
5242
- timestamp: /* @__PURE__ */ new Date().toISOString()
5243
- });
5244
- }
5344
+ this.trackAdLoaded(bids);
5245
5345
  return [
5246
5346
  4,
5247
5347
  this.adLayer.playAd(bids)
@@ -5387,6 +5487,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5387
5487
  ,
5388
5488
  7
5389
5489
  ]);
5490
+ this.trackAdLoaded(bids);
5390
5491
  return [
5391
5492
  4,
5392
5493
  this.adLayer.playAd(bids)