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.js CHANGED
@@ -959,6 +959,7 @@ function createVastAdLayer(contentVideo, options) {
959
959
  var adHls;
960
960
  var adContainerEl;
961
961
  var currentAd;
962
+ var currentMediaFile;
962
963
  var sessionId;
963
964
  var destroyed = false;
964
965
  var tornDown = false;
@@ -1205,7 +1206,12 @@ function createVastAdLayer(contentVideo, options) {
1205
1206
  adContainerEl.style.display = "none";
1206
1207
  adContainerEl.style.pointerEvents = "none";
1207
1208
  }
1208
- emit("ad_impression");
1209
+ emit("ad_impression", {
1210
+ adId: currentAd === null || currentAd === void 0 ? void 0 : currentAd.id,
1211
+ adTitle: currentAd === null || currentAd === void 0 ? void 0 : currentAd.title,
1212
+ adUrl: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.url,
1213
+ mediaType: currentMediaFile === null || currentMediaFile === void 0 ? void 0 : currentMediaFile.type
1214
+ });
1209
1215
  emit("content_resume");
1210
1216
  }
1211
1217
  function handleAdError() {
@@ -1227,6 +1233,7 @@ function createVastAdLayer(contentVideo, options) {
1227
1233
  adHls.destroy();
1228
1234
  adHls = void 0;
1229
1235
  }
1236
+ currentMediaFile = void 0;
1230
1237
  if (adVideoElement) {
1231
1238
  if (singleElementMode && adVideoElement === contentVideo) {
1232
1239
  contentVideo.pause();
@@ -1391,6 +1398,7 @@ function createVastAdLayer(contentVideo, options) {
1391
1398
  adVideoElement.volume = Math.max(0, Math.min(1, adVolume2));
1392
1399
  adVideoElement.muted = false;
1393
1400
  mediaFile2 = selectBestMediaFile(ad.mediaFiles);
1401
+ currentMediaFile = mediaFile2;
1394
1402
  if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile2.url));
1395
1403
  startPlayback(mediaFile2);
1396
1404
  return [
@@ -1437,6 +1445,7 @@ function createVastAdLayer(contentVideo, options) {
1437
1445
  }
1438
1446
  emit("content_pause");
1439
1447
  mediaFile = selectBestMediaFile(ad.mediaFiles);
1448
+ currentMediaFile = mediaFile;
1440
1449
  if (debug) console.log("".concat(LOG, " Loading ad from: ").concat(mediaFile.url));
1441
1450
  startPlayback(mediaFile);
1442
1451
  return [
@@ -1602,6 +1611,7 @@ function createVastAdLayer(contentVideo, options) {
1602
1611
  ];
1603
1612
  mainHlsInstance === null || mainHlsInstance === void 0 ? void 0 : mainHlsInstance.detachMedia();
1604
1613
  teardownCurrentPlayback();
1614
+ currentMediaFile = slot.mediaFile;
1605
1615
  adVideoElement = contentVideo;
1606
1616
  adHls = void 0;
1607
1617
  adPlaying = true;
@@ -1636,6 +1646,7 @@ function createVastAdLayer(contentVideo, options) {
1636
1646
  case 2:
1637
1647
  if (smartTVMode && !slot.videoEl) {
1638
1648
  teardownCurrentPlayback();
1649
+ currentMediaFile = slot.mediaFile;
1639
1650
  if (adVideoElement) {
1640
1651
  adVideoElement.remove();
1641
1652
  adVideoElement = void 0;
@@ -1667,6 +1678,7 @@ function createVastAdLayer(contentVideo, options) {
1667
1678
  ];
1668
1679
  }
1669
1680
  teardownCurrentPlayback();
1681
+ currentMediaFile = slot.mediaFile;
1670
1682
  if (adVideoElement && adVideoElement !== slot.videoEl) {
1671
1683
  adVideoElement.remove();
1672
1684
  }
@@ -1798,6 +1810,7 @@ function createVastAdLayer(contentVideo, options) {
1798
1810
  }
1799
1811
  }
1800
1812
  currentAd = void 0;
1813
+ currentMediaFile = void 0;
1801
1814
  tornDown = false;
1802
1815
  return [
1803
1816
  2
@@ -1850,6 +1863,7 @@ function createVastAdLayer(contentVideo, options) {
1850
1863
  }
1851
1864
  adContainerEl = void 0;
1852
1865
  currentAd = void 0;
1866
+ currentMediaFile = void 0;
1853
1867
  listeners.clear();
1854
1868
  },
1855
1869
  isAdPlaying: function isAdPlaying() {
@@ -2163,24 +2177,30 @@ function getBrowserID(clientInfo) {
2163
2177
  });
2164
2178
  })();
2165
2179
  }
2166
- var TRACK_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/track";
2180
+ var PLAYER_TRACKING_BASE_URL = "https://adstorm.co/api-adstorm-dev/adstorm/player-tracking";
2181
+ var TRACK_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/metrics/ingest");
2182
+ var HEARTBEAT_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/heartbeat");
2183
+ var IMPRESSIONS_URL = "".concat(PLAYER_TRACKING_BASE_URL, "/impressions/ingest");
2184
+ function buildHeaders(licenseKey) {
2185
+ var headers = {
2186
+ "Content-Type": "application/json"
2187
+ };
2188
+ if (licenseKey) {
2189
+ headers["Authorization"] = "Bearer ".concat(licenseKey);
2190
+ }
2191
+ return headers;
2192
+ }
2167
2193
  function sendTrackRequest(licenseKey, body) {
2168
2194
  return _async_to_generator(function() {
2169
- var headers, response;
2195
+ var response;
2170
2196
  return _ts_generator(this, function(_state) {
2171
2197
  switch(_state.label){
2172
2198
  case 0:
2173
- headers = {
2174
- "Content-Type": "application/json"
2175
- };
2176
- if (licenseKey) {
2177
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2178
- }
2179
2199
  return [
2180
2200
  4,
2181
2201
  fetch(TRACK_URL, {
2182
2202
  method: "POST",
2183
- headers: headers,
2203
+ headers: buildHeaders(licenseKey),
2184
2204
  body: JSON.stringify(body)
2185
2205
  })
2186
2206
  ];
@@ -2202,14 +2222,86 @@ function sendTrackRequest(licenseKey, body) {
2202
2222
  });
2203
2223
  })();
2204
2224
  }
2205
- function sendInitialTracking(licenseKey) {
2225
+ function postJson(url, licenseKey, body) {
2206
2226
  return _async_to_generator(function() {
2207
- var clientInfo, browserId, trackingData, headers, response, error;
2227
+ var response;
2228
+ return _ts_generator(this, function(_state) {
2229
+ switch(_state.label){
2230
+ case 0:
2231
+ return [
2232
+ 4,
2233
+ fetch(url, {
2234
+ method: "POST",
2235
+ headers: buildHeaders(licenseKey),
2236
+ body: JSON.stringify(body)
2237
+ })
2238
+ ];
2239
+ case 1:
2240
+ response = _state.sent();
2241
+ if (!response.ok) {
2242
+ throw new Error("HTTP error! status: ".concat(response.status));
2243
+ }
2244
+ return [
2245
+ 4,
2246
+ response.json()
2247
+ ];
2248
+ case 2:
2249
+ _state.sent();
2250
+ return [
2251
+ 2
2252
+ ];
2253
+ }
2254
+ });
2255
+ })();
2256
+ }
2257
+ function buildPlayerMetricEvent(_0) {
2258
+ return _async_to_generator(function(licenseKey) {
2259
+ var context, flags, _flags_captureAt, clientInfo, browserId, captureAt;
2260
+ var _arguments = arguments;
2208
2261
  return _ts_generator(this, function(_state) {
2209
2262
  switch(_state.label){
2210
2263
  case 0:
2264
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, flags = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2265
+ clientInfo = getClientInfo();
2266
+ return [
2267
+ 4,
2268
+ getBrowserID(clientInfo)
2269
+ ];
2270
+ case 1:
2271
+ browserId = _state.sent();
2272
+ captureAt = (_flags_captureAt = flags.captureAt) !== null && _flags_captureAt !== void 0 ? _flags_captureAt : /* @__PURE__ */ new Date().toISOString();
2273
+ return [
2274
+ 2,
2275
+ {
2276
+ player_id: browserId,
2277
+ browserId: browserId,
2278
+ device_type: clientInfo.deviceType,
2279
+ deviceType: clientInfo.deviceType,
2280
+ input_stream_type: context.inputStreamType,
2281
+ os: clientInfo.os,
2282
+ ad_loaded: flags.adLoaded,
2283
+ ad_detect: flags.adDetect,
2284
+ license_key: licenseKey,
2285
+ capture_at: captureAt,
2286
+ timestamp: captureAt
2287
+ }
2288
+ ];
2289
+ }
2290
+ });
2291
+ }).apply(this, arguments);
2292
+ }
2293
+ function sendInitialTracking(_0) {
2294
+ return _async_to_generator(function(licenseKey) {
2295
+ var context, clientInfo, browserId, trackingData, error;
2296
+ var _arguments = arguments;
2297
+ return _ts_generator(this, function(_state) {
2298
+ switch(_state.label){
2299
+ case 0:
2300
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
2301
+ _state.label = 1;
2302
+ case 1:
2211
2303
  _state.trys.push([
2212
- 0,
2304
+ 1,
2213
2305
  4,
2214
2306
  ,
2215
2307
  5
@@ -2219,34 +2311,29 @@ function sendInitialTracking(licenseKey) {
2219
2311
  4,
2220
2312
  getBrowserID(clientInfo)
2221
2313
  ];
2222
- case 1:
2314
+ case 2:
2223
2315
  browserId = _state.sent();
2224
2316
  trackingData = _object_spread({
2225
2317
  browserId: browserId
2226
2318
  }, clientInfo);
2227
- headers = {
2228
- "Content-Type": "application/json"
2229
- };
2230
- if (licenseKey) {
2231
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2232
- }
2233
2319
  return [
2234
2320
  4,
2235
- fetch(TRACK_URL, {
2236
- method: "POST",
2237
- headers: headers,
2238
- body: JSON.stringify(trackingData)
2321
+ sendTrackRequest(licenseKey, {
2322
+ events: [
2323
+ {
2324
+ player_id: browserId,
2325
+ device_type: clientInfo.deviceType,
2326
+ input_stream_type: context.inputStreamType,
2327
+ os: clientInfo.os,
2328
+ ad_loaded: false,
2329
+ ad_detect: false,
2330
+ license_key: licenseKey,
2331
+ capture_at: /* @__PURE__ */ new Date().toISOString()
2332
+ }
2333
+ ],
2334
+ trackingData: trackingData
2239
2335
  })
2240
2336
  ];
2241
- case 2:
2242
- response = _state.sent();
2243
- if (!response.ok) {
2244
- throw new Error("HTTP error! status: ".concat(response.status));
2245
- }
2246
- return [
2247
- 4,
2248
- response.json()
2249
- ];
2250
2337
  case 3:
2251
2338
  _state.sent();
2252
2339
  return [
@@ -2266,36 +2353,30 @@ function sendInitialTracking(licenseKey) {
2266
2353
  ];
2267
2354
  }
2268
2355
  });
2269
- })();
2356
+ }).apply(this, arguments);
2270
2357
  }
2271
- function sendAdDetectTracking(licenseKey, adDetectInfo) {
2272
- return _async_to_generator(function() {
2273
- var clientInfo, browserId, trackingData, error;
2358
+ function sendAdDetectTracking(_0, _1) {
2359
+ return _async_to_generator(function(licenseKey, adDetectInfo) {
2360
+ var context, error;
2361
+ var _arguments = arguments;
2274
2362
  return _ts_generator(this, function(_state) {
2275
2363
  switch(_state.label){
2276
2364
  case 0:
2365
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2366
+ _state.label = 1;
2367
+ case 1:
2277
2368
  _state.trys.push([
2278
- 0,
2369
+ 1,
2279
2370
  3,
2280
2371
  ,
2281
2372
  4
2282
2373
  ]);
2283
- clientInfo = getClientInfo();
2284
- return [
2285
- 4,
2286
- getBrowserID(clientInfo)
2287
- ];
2288
- case 1:
2289
- browserId = _state.sent();
2290
- trackingData = _object_spread({
2291
- browserId: browserId
2292
- }, clientInfo);
2293
2374
  return [
2294
2375
  4,
2295
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2296
- licenseKey: licenseKey,
2297
- adDetectInfo: adDetectInfo
2298
- }))
2376
+ sendHeartbeat(licenseKey, context, {
2377
+ adDetect: true,
2378
+ captureAt: adDetectInfo.timestamp
2379
+ })
2299
2380
  ];
2300
2381
  case 2:
2301
2382
  _state.sent();
@@ -2316,36 +2397,30 @@ function sendAdDetectTracking(licenseKey, adDetectInfo) {
2316
2397
  ];
2317
2398
  }
2318
2399
  });
2319
- })();
2400
+ }).apply(this, arguments);
2320
2401
  }
2321
- function sendAdLoadedTracking(licenseKey, adLoadedInfo) {
2322
- return _async_to_generator(function() {
2323
- var clientInfo, browserId, trackingData, error;
2402
+ function sendAdLoadedTracking(_0, _1) {
2403
+ return _async_to_generator(function(licenseKey, adLoadedInfo) {
2404
+ var context, error;
2405
+ var _arguments = arguments;
2324
2406
  return _ts_generator(this, function(_state) {
2325
2407
  switch(_state.label){
2326
2408
  case 0:
2409
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2410
+ _state.label = 1;
2411
+ case 1:
2327
2412
  _state.trys.push([
2328
- 0,
2413
+ 1,
2329
2414
  3,
2330
2415
  ,
2331
2416
  4
2332
2417
  ]);
2333
- clientInfo = getClientInfo();
2334
- return [
2335
- 4,
2336
- getBrowserID(clientInfo)
2337
- ];
2338
- case 1:
2339
- browserId = _state.sent();
2340
- trackingData = _object_spread({
2341
- browserId: browserId
2342
- }, clientInfo);
2343
2418
  return [
2344
2419
  4,
2345
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2346
- licenseKey: licenseKey,
2347
- adLoadedInfo: adLoadedInfo
2348
- }))
2420
+ sendHeartbeat(licenseKey, context, {
2421
+ adLoaded: true,
2422
+ captureAt: adLoadedInfo.timestamp
2423
+ })
2349
2424
  ];
2350
2425
  case 2:
2351
2426
  _state.sent();
@@ -2366,103 +2441,95 @@ function sendAdLoadedTracking(licenseKey, adLoadedInfo) {
2366
2441
  ];
2367
2442
  }
2368
2443
  });
2369
- })();
2444
+ }).apply(this, arguments);
2370
2445
  }
2371
- function sendAdImpressionTracking(licenseKey, adImpressionInfo) {
2372
- return _async_to_generator(function() {
2373
- var clientInfo, browserId, trackingData, error;
2446
+ function sendAdImpressionTracking(_0, _1) {
2447
+ return _async_to_generator(function(licenseKey, adImpressionInfo) {
2448
+ var context, metricEvent, error;
2449
+ var _arguments = arguments;
2374
2450
  return _ts_generator(this, function(_state) {
2375
2451
  switch(_state.label){
2376
2452
  case 0:
2453
+ context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2454
+ _state.label = 1;
2455
+ case 1:
2377
2456
  _state.trys.push([
2378
- 0,
2379
- 3,
2457
+ 1,
2458
+ 4,
2380
2459
  ,
2381
- 4
2460
+ 5
2382
2461
  ]);
2383
- clientInfo = getClientInfo();
2384
2462
  return [
2385
2463
  4,
2386
- getBrowserID(clientInfo)
2464
+ buildPlayerMetricEvent(licenseKey, context, {
2465
+ captureAt: adImpressionInfo.timestamp
2466
+ })
2387
2467
  ];
2388
- case 1:
2389
- browserId = _state.sent();
2390
- trackingData = _object_spread({
2391
- browserId: browserId
2392
- }, clientInfo);
2468
+ case 2:
2469
+ metricEvent = _state.sent();
2393
2470
  return [
2394
2471
  4,
2395
- sendTrackRequest(licenseKey, _object_spread_props(_object_spread({}, trackingData), {
2396
- licenseKey: licenseKey,
2397
- adImpressionInfo: adImpressionInfo
2398
- }))
2472
+ Promise.all([
2473
+ postJson(HEARTBEAT_URL, licenseKey, metricEvent),
2474
+ postJson(IMPRESSIONS_URL, licenseKey, {
2475
+ events: [
2476
+ {
2477
+ player_id: metricEvent.player_id,
2478
+ ad_played_count: 1,
2479
+ ad_url: adImpressionInfo.adUrl,
2480
+ license_key: licenseKey,
2481
+ capture_at: adImpressionInfo.timestamp
2482
+ }
2483
+ ]
2484
+ })
2485
+ ])
2399
2486
  ];
2400
- case 2:
2487
+ case 3:
2401
2488
  _state.sent();
2402
2489
  return [
2403
2490
  3,
2404
- 4
2491
+ 5
2405
2492
  ];
2406
- case 3:
2493
+ case 4:
2407
2494
  error = _state.sent();
2408
2495
  console.error("[StormcloudVideoPlayer] Error sending ad impression tracking:", error);
2409
2496
  return [
2410
2497
  3,
2411
- 4
2498
+ 5
2412
2499
  ];
2413
- case 4:
2500
+ case 5:
2414
2501
  return [
2415
2502
  2
2416
2503
  ];
2417
2504
  }
2418
2505
  });
2419
- })();
2506
+ }).apply(this, arguments);
2420
2507
  }
2421
- function sendHeartbeat(licenseKey) {
2422
- return _async_to_generator(function() {
2423
- var clientInfo, browserId, heartbeatData, headers, response, error;
2508
+ function sendHeartbeat(_0) {
2509
+ return _async_to_generator(function(licenseKey) {
2510
+ var context, flags, heartbeatData, error;
2511
+ var _arguments = arguments;
2424
2512
  return _ts_generator(this, function(_state) {
2425
2513
  switch(_state.label){
2426
2514
  case 0:
2515
+ context = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, flags = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
2516
+ _state.label = 1;
2517
+ case 1:
2427
2518
  _state.trys.push([
2428
- 0,
2519
+ 1,
2429
2520
  4,
2430
2521
  ,
2431
2522
  5
2432
2523
  ]);
2433
- clientInfo = getClientInfo();
2434
2524
  return [
2435
2525
  4,
2436
- getBrowserID(clientInfo)
2437
- ];
2438
- case 1:
2439
- browserId = _state.sent();
2440
- heartbeatData = {
2441
- browserId: browserId,
2442
- timestamp: /* @__PURE__ */ new Date().toISOString()
2443
- };
2444
- headers = {
2445
- "Content-Type": "application/json"
2446
- };
2447
- if (licenseKey) {
2448
- headers["Authorization"] = "Bearer ".concat(licenseKey);
2449
- }
2450
- return [
2451
- 4,
2452
- fetch("https://adstorm.co/api-adstorm-dev/adstorm/player-tracking/heartbeat", {
2453
- method: "POST",
2454
- headers: headers,
2455
- body: JSON.stringify(heartbeatData)
2456
- })
2526
+ buildPlayerMetricEvent(licenseKey, context, flags)
2457
2527
  ];
2458
2528
  case 2:
2459
- response = _state.sent();
2460
- if (!response.ok) {
2461
- throw new Error("HTTP error! status: ".concat(response.status));
2462
- }
2529
+ heartbeatData = _state.sent();
2463
2530
  return [
2464
2531
  4,
2465
- response.json()
2532
+ postJson(HEARTBEAT_URL, licenseKey, heartbeatData)
2466
2533
  ];
2467
2534
  case 3:
2468
2535
  _state.sent();
@@ -2483,7 +2550,7 @@ function sendHeartbeat(licenseKey) {
2483
2550
  ];
2484
2551
  }
2485
2552
  });
2486
- })();
2553
+ }).apply(this, arguments);
2487
2554
  }
2488
2555
  // src/utils/polyfills.ts
2489
2556
  function polyfillURLSearchParams() {
@@ -3526,17 +3593,67 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3526
3593
  return "vast";
3527
3594
  }
3528
3595
  },
3596
+ {
3597
+ key: "getInputStreamType",
3598
+ value: function getInputStreamType() {
3599
+ var src = this.config.src.toLowerCase();
3600
+ if (src.includes(".m3u8")) return "hls";
3601
+ if (src.includes(".mpd")) return "dash";
3602
+ if (src.includes(".mp4")) return "mp4";
3603
+ return this.isLiveStream ? "live" : "vod";
3604
+ }
3605
+ },
3606
+ {
3607
+ key: "getAnalyticsContext",
3608
+ value: function getAnalyticsContext() {
3609
+ return {
3610
+ inputStreamType: this.getInputStreamType()
3611
+ };
3612
+ }
3613
+ },
3614
+ {
3615
+ key: "getAdUrlFromBids",
3616
+ value: function getAdUrlFromBids(bids) {
3617
+ var _bids_;
3618
+ return bids === null || bids === void 0 ? void 0 : (_bids_ = bids[0]) === null || _bids_ === void 0 ? void 0 : _bids_.vastUrl;
3619
+ }
3620
+ },
3621
+ {
3622
+ key: "trackAdLoaded",
3623
+ value: function trackAdLoaded(bids) {
3624
+ if (!this.config.licenseKey) return;
3625
+ var adUrl = this.getAdUrlFromBids(bids);
3626
+ if (adUrl) {
3627
+ this.lastServedAdUrl = adUrl;
3628
+ }
3629
+ sendAdLoadedTracking(this.config.licenseKey, _object_spread_props(_object_spread({
3630
+ source: this.getAdSource()
3631
+ }, adUrl ? {
3632
+ vastUrl: adUrl
3633
+ } : {}), {
3634
+ timestamp: /* @__PURE__ */ new Date().toISOString()
3635
+ }), this.getAnalyticsContext());
3636
+ }
3637
+ },
3529
3638
  {
3530
3639
  key: "attachAdLayerEventListeners",
3531
3640
  value: function attachAdLayerEventListeners() {
3532
3641
  var _this = this;
3533
- this.adLayer.on("ad_impression", function() {
3642
+ this.adLayer.on("ad_impression", function(payload) {
3534
3643
  if (_this.config.licenseKey) {
3535
- sendAdImpressionTracking(_this.config.licenseKey, {
3644
+ var _ref;
3645
+ var adUrl = (_ref = payload === null || payload === void 0 ? void 0 : payload.adUrl) !== null && _ref !== void 0 ? _ref : _this.lastServedAdUrl;
3646
+ if (adUrl) {
3647
+ _this.lastServedAdUrl = adUrl;
3648
+ }
3649
+ sendAdImpressionTracking(_this.config.licenseKey, _object_spread_props(_object_spread({
3536
3650
  source: _this.getAdSource(),
3537
- adIndex: _this.currentAdIndex,
3651
+ adIndex: _this.currentAdIndex
3652
+ }, adUrl ? {
3653
+ adUrl: adUrl
3654
+ } : {}), {
3538
3655
  timestamp: /* @__PURE__ */ new Date().toISOString()
3539
- });
3656
+ }), _this.getAnalyticsContext());
3540
3657
  }
3541
3658
  });
3542
3659
  this.adLayer.on("ad_error", function(errorPayload) {
@@ -3630,6 +3747,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3630
3747
  _this.isInAdTransition = false;
3631
3748
  if (!_this.inAdBreak) return;
3632
3749
  _this.currentAdIndex++;
3750
+ _this.trackAdLoaded();
3633
3751
  _this.adLayer.playPreloaded(token).catch(function(err) {
3634
3752
  if (_this.config.debugAdTiming) console.warn("[StormcloudVideoPlayer] playPreloaded failed:", err);
3635
3753
  _this.handleAdFailure();
@@ -3659,6 +3777,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
3659
3777
  var freshBids = (_this_pendingNextAdBids = _this.pendingNextAdBids) !== null && _this_pendingNextAdBids !== void 0 ? _this_pendingNextAdBids : bids;
3660
3778
  _this.pendingNextAdBids = null;
3661
3779
  _this.currentAdIndex++;
3780
+ _this.trackAdLoaded(freshBids);
3662
3781
  _this.adLayer.playAd(freshBids).catch(function(err) {
3663
3782
  if (_this.config.debugAdTiming) console.warn("[StormcloudVideoPlayer] playAd(pending) failed:", err);
3664
3783
  _this.handleAdFailure();
@@ -4038,7 +4157,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4038
4157
  }, ((_this_pendingAdBreak1 = this.pendingAdBreak) === null || _this_pendingAdBreak1 === void 0 ? void 0 : _this_pendingAdBreak1.detectedAtFragmentSn) != null && {
4039
4158
  detectedAtFragmentSn: this.pendingAdBreak.detectedAtFragmentSn
4040
4159
  });
4041
- sendAdDetectTracking(this.config.licenseKey, adDetectInfo);
4160
+ sendAdDetectTracking(this.config.licenseKey, adDetectInfo, this.getAnalyticsContext());
4042
4161
  }
4043
4162
  var isManifestMarker = this.isManifestBasedMarker(marker);
4044
4163
  var forceImmediate = (_this_config_immediateManifestAds = this.config.immediateManifestAds) !== null && _this_config_immediateManifestAds !== void 0 ? _this_config_immediateManifestAds : true;
@@ -4107,6 +4226,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4107
4226
  var bids = this.pendingNextAdBids;
4108
4227
  this.pendingNextAdBids = null;
4109
4228
  this.currentAdIndex++;
4229
+ this.trackAdLoaded(bids);
4110
4230
  this.adLayer.playAd(bids).catch(function() {
4111
4231
  return _this.handleAdFailure();
4112
4232
  });
@@ -4361,7 +4481,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4361
4481
  key: "initializeTracking",
4362
4482
  value: function initializeTracking() {
4363
4483
  var _this = this;
4364
- sendInitialTracking(this.config.licenseKey).then(function() {
4484
+ sendInitialTracking(this.config.licenseKey, this.getAnalyticsContext()).then(function() {
4365
4485
  _this.heartbeatInterval = window.setInterval(function() {
4366
4486
  _this.sendHeartbeatIfNeeded();
4367
4487
  }, 5e3);
@@ -4382,7 +4502,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4382
4502
  var now = Date.now();
4383
4503
  if (!this.lastHeartbeatTime || now - this.lastHeartbeatTime > 3e4) {
4384
4504
  this.lastHeartbeatTime = now;
4385
- sendHeartbeat(this.config.licenseKey).catch(function(error) {
4505
+ sendHeartbeat(this.config.licenseKey, this.getAnalyticsContext()).catch(function(error) {
4386
4506
  if (_this.config.debugAdTiming) {
4387
4507
  console.warn("[StormcloudVideoPlayer] Failed to send heartbeat:", error);
4388
4508
  }
@@ -4775,12 +4895,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4775
4895
  10
4776
4896
  ];
4777
4897
  _this.currentAdIndex++;
4778
- if (_this.config.licenseKey) {
4779
- sendAdLoadedTracking(_this.config.licenseKey, {
4780
- source: _this.getAdSource(),
4781
- timestamp: /* @__PURE__ */ new Date().toISOString()
4782
- });
4783
- }
4898
+ _this.trackAdLoaded(bids1);
4784
4899
  return [
4785
4900
  4,
4786
4901
  _this.adLayer.playAd(bids1)
@@ -4885,12 +5000,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
4885
5000
  ];
4886
5001
  case 18:
4887
5002
  _this.currentAdIndex++;
4888
- if (_this.config.licenseKey) {
4889
- sendAdLoadedTracking(_this.config.licenseKey, {
4890
- source: _this.getAdSource(),
4891
- timestamp: /* @__PURE__ */ new Date().toISOString()
4892
- });
4893
- }
5003
+ _this.trackAdLoaded(bids2);
4894
5004
  return [
4895
5005
  4,
4896
5006
  _this.adLayer.playAd(bids2)
@@ -5049,12 +5159,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5049
5159
  6
5050
5160
  ];
5051
5161
  this.currentAdIndex++;
5052
- if (this.config.licenseKey) {
5053
- sendAdLoadedTracking(this.config.licenseKey, {
5054
- source: this.getAdSource(),
5055
- timestamp: /* @__PURE__ */ new Date().toISOString()
5056
- });
5057
- }
5162
+ this.trackAdLoaded();
5058
5163
  _state.label = 1;
5059
5164
  case 1:
5060
5165
  _state.trys.push([
@@ -5248,12 +5353,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5248
5353
  5
5249
5354
  ];
5250
5355
  case 3:
5251
- if (this.config.licenseKey) {
5252
- sendAdLoadedTracking(this.config.licenseKey, {
5253
- source: this.getAdSource(),
5254
- timestamp: /* @__PURE__ */ new Date().toISOString()
5255
- });
5256
- }
5356
+ this.trackAdLoaded(bids);
5257
5357
  return [
5258
5358
  4,
5259
5359
  this.adLayer.playAd(bids)
@@ -5399,6 +5499,7 @@ var StormcloudVideoPlayer = /*#__PURE__*/ function() {
5399
5499
  ,
5400
5500
  7
5401
5501
  ]);
5502
+ this.trackAdLoaded(bids);
5402
5503
  return [
5403
5504
  4,
5404
5505
  this.adLayer.playAd(bids)