@folklore/ads 0.0.76 → 0.0.78

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.
Files changed (3) hide show
  1. package/dist/cjs.js +68 -41
  2. package/dist/es.js +68 -41
  3. package/package.json +2 -2
package/dist/cjs.js CHANGED
@@ -276,7 +276,7 @@ class AdSlot extends EventEmitter__default["default"] {
276
276
  }
277
277
 
278
278
  /* globals refreshDisabledLineItems: [] */
279
- const debug = createDebug__default["default"]('folklore:ads');
279
+ const debug$1 = createDebug__default["default"]('folklore:ads');
280
280
  class AdsManager extends EventEmitter__default["default"] {
281
281
  // static index = 0;
282
282
 
@@ -384,7 +384,7 @@ class AdsManager extends EventEmitter__default["default"] {
384
384
  if (this.disabled) {
385
385
  return;
386
386
  }
387
- debug('Initializing GPT...');
387
+ debug$1('Initializing GPT...');
388
388
  const {
389
389
  disabled,
390
390
  personnalizedAdsDisabled
@@ -398,19 +398,19 @@ class AdsManager extends EventEmitter__default["default"] {
398
398
  fetchMarginPercent = 300
399
399
  } = this.options;
400
400
  if (disabled) {
401
- debug('Disable initial load');
401
+ debug$1('Disable initial load');
402
402
  googletag.pubads().disableInitialLoad();
403
403
  }
404
404
  if (!disableSingleRequest) {
405
- debug('Enable single request');
405
+ debug$1('Enable single request');
406
406
  googletag.pubads().enableSingleRequest();
407
407
  }
408
408
  if (personnalizedAdsDisabled) {
409
- debug('Disable personalized ads');
409
+ debug$1('Disable personalized ads');
410
410
  googletag.pubads().setRequestNonPersonalizedAds(1);
411
411
  }
412
412
  if (!disableLazyLoad) {
413
- debug('Enable lazy loading %o', {
413
+ debug$1('Enable lazy loading %o', {
414
414
  fetchMarginPercent,
415
415
  renderMarginPercent,
416
416
  mobileScaling
@@ -422,13 +422,13 @@ class AdsManager extends EventEmitter__default["default"] {
422
422
  });
423
423
  }
424
424
  if (!disableVideoAds) {
425
- debug('Enable video ads');
425
+ debug$1('Enable video ads');
426
426
  googletag.pubads().enableVideoAds();
427
427
  }
428
428
  googletag.pubads().addEventListener('slotRenderEnded', this.onSlotRenderEnded);
429
429
  googletag.pubads().addEventListener('impressionViewable', this.onSlotImpressionViewable);
430
430
  googletag.enableServices();
431
- debug('GPT is ready');
431
+ debug$1('GPT is ready');
432
432
  this.enabled = true;
433
433
  this.ready = true;
434
434
  this.emit('ready');
@@ -448,9 +448,9 @@ class AdsManager extends EventEmitter__default["default"] {
448
448
  renderSlot.setRefreshDisabled();
449
449
  }
450
450
  if (event.isEmpty) {
451
- debug('Render ended for slot #%s(%s). Slot is empty.', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath());
451
+ debug$1('Render ended for slot #%s(%s). Slot is empty.', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath());
452
452
  } else {
453
- debug('Render ended for slot #%s(%s) with size %s.', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath(), size !== null ? size.join('x') : '-');
453
+ debug$1('Render ended for slot #%s(%s) with size %s.', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath(), size !== null ? size.join('x') : '-');
454
454
  }
455
455
  }
456
456
  onSlotImpressionViewable(event) {
@@ -461,12 +461,12 @@ class AdsManager extends EventEmitter__default["default"] {
461
461
  if (impressionSlot !== null) {
462
462
  impressionSlot.setViewable(true);
463
463
  }
464
- debug('Impression viewable for slot #%s(%s).', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath());
464
+ debug$1('Impression viewable for slot #%s(%s).', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath());
465
465
  }
466
466
 
467
467
  // eslint-disable-next-line class-methods-use-this
468
468
  onSlotVisibleChange(visible, slot) {
469
- debug('Slot #%s(%s) visibility change to %s', slot.getElementId(), slot.getAdPath(), visible ? 'visible' : 'not visible');
469
+ debug$1('Slot #%s(%s) visibility change to %s', slot.getElementId(), slot.getAdPath(), visible ? 'visible' : 'not visible');
470
470
  }
471
471
  isReady() {
472
472
  return this.ready && this.enabled && !this.disabled;
@@ -504,7 +504,7 @@ class AdsManager extends EventEmitter__default["default"] {
504
504
  id: providedId = null
505
505
  } = opts;
506
506
  const id = providedId || this.createAdId();
507
- debug('Creating slot #%s(%s)...', id, path);
507
+ debug$1('Creating slot #%s(%s)...', id, path);
508
508
  const slot = new AdSlot(id, path, size, {
509
509
  ...opts
510
510
  });
@@ -523,7 +523,7 @@ class AdsManager extends EventEmitter__default["default"] {
523
523
  const id = slot.getElementId();
524
524
  const path = slot.getAdPath();
525
525
  const size = slot.getAdSize();
526
- debug('Defining slot #%s(%s)...', id, path);
526
+ debug$1('Defining slot #%s(%s)...', id, path);
527
527
  const adSlot = googletag.defineSlot(path, size, id).addService(googletag.pubads());
528
528
  slot.setAdSlot(adSlot);
529
529
  });
@@ -532,7 +532,7 @@ class AdsManager extends EventEmitter__default["default"] {
532
532
  const slotsToDisplay = this.slots.filter(slot => slot.canBeDisplayed());
533
533
  const slotsCount = slotsToDisplay.length;
534
534
  if (slotsCount > 0) {
535
- debug('Displaying %i slot(s)...', slotsCount);
535
+ debug$1('Displaying %i slot(s)...', slotsCount);
536
536
  slotsToDisplay.forEach(slot => this.callDisplaySlot(slot));
537
537
  }
538
538
  return true;
@@ -552,7 +552,7 @@ class AdsManager extends EventEmitter__default["default"] {
552
552
  googletag.cmd.push(() => {
553
553
  const id = slot.getElementId();
554
554
  const path = slot.getAdPath();
555
- debug('Displaying slot #%s(%s)...', id, path);
555
+ debug$1('Displaying slot #%s(%s)...', id, path);
556
556
  googletag.display(slot.getAdSlot());
557
557
  if (googletag.pubads().isInitialLoadDisabled()) {
558
558
  googletag.pubads().refresh([slot.getAdSlot()]);
@@ -574,7 +574,7 @@ class AdsManager extends EventEmitter__default["default"] {
574
574
  slot.destroy();
575
575
  this.slots = this.slots.filter(it => it !== slot);
576
576
  if (adSlot !== null) {
577
- debug('Destroying slot #%s(%s)...', adSlot.getAdUnitPath(), adSlot.getSlotElementId());
577
+ debug$1('Destroying slot #%s(%s)...', adSlot.getAdUnitPath(), adSlot.getSlotElementId());
578
578
  googletag.cmd.push(() => {
579
579
  googletag.destroySlots([adSlot]);
580
580
  });
@@ -591,7 +591,7 @@ class AdsManager extends EventEmitter__default["default"] {
591
591
  }
592
592
  const adSlot = slot.getAdSlot();
593
593
  if (adSlot !== null) {
594
- debug('Refreshing slot #%s(%s)...', adSlot.getAdUnitPath(), slot.getElementId());
594
+ debug$1('Refreshing slot #%s(%s)...', adSlot.getAdUnitPath(), slot.getElementId());
595
595
  googletag.cmd.push(() => {
596
596
  googletag.pubads().refresh([adSlot], {
597
597
  changeCorrelator: false
@@ -607,7 +607,7 @@ class AdsManager extends EventEmitter__default["default"] {
607
607
  if (slots.length === 0) {
608
608
  return;
609
609
  }
610
- debug('Refreshing slots %o...', slots.map(slot => `#${slot.getElementId()}(${slot.getAdUnitPath()})`));
610
+ debug$1('Refreshing slots %o...', slots.map(slot => `#${slot.getElementId()}(${slot.getAdUnitPath()})`));
611
611
  googletag.cmd.push(() => {
612
612
  googletag.pubads().refresh(slots);
613
613
  });
@@ -616,7 +616,7 @@ class AdsManager extends EventEmitter__default["default"] {
616
616
  const {
617
617
  googletag
618
618
  } = this;
619
- debug('Refreshing all slots...');
619
+ debug$1('Refreshing all slots...');
620
620
  googletag.cmd.push(() => {
621
621
  googletag.pubads().refresh();
622
622
  });
@@ -1065,27 +1065,46 @@ function useAd(path, size) {
1065
1065
  };
1066
1066
  }
1067
1067
 
1068
- function useRichAd(containerRef, id) {
1068
+ const debug = createDebug__default["default"]('folklore:ads');
1069
+ function parseRichAd(data) {
1070
+ let richAd = null;
1071
+ try {
1072
+ const eventData = JSON.parse(data) || null;
1073
+ richAd = eventData !== null ? eventData.richAd || null : null;
1074
+ } catch (e) {}
1075
+ return richAd;
1076
+ }
1077
+ function useRichAd(containerRef, id, opts) {
1069
1078
  const [richAd, setRichAd] = React.useState(null);
1079
+ const {
1080
+ onRichAd = null
1081
+ } = opts || {};
1070
1082
  React.useEffect(() => {
1071
1083
  setRichAd(null);
1072
- window.addEventListener('message', event => {
1073
- if (event.origin.match(/safeframe\.googlesyndication\.com/) !== null) {
1074
- let newRichAd = null;
1075
- try {
1076
- const eventData = JSON.parse(event.data) || null;
1077
- newRichAd = eventData !== null ? eventData.richAd || null : null;
1078
- } catch (e) {}
1079
- if (newRichAd !== null) {
1080
- const container = containerRef.current || document;
1081
- const iframe = container.querySelector('iframe') || null;
1082
- if (iframe !== null && iframe.contentWindow === event.source) {
1083
- setRichAd(newRichAd);
1084
- }
1085
- }
1084
+ function onMessage(event) {
1085
+ if (event.origin.match(/safeframe\.googlesyndication\.com/) === null) {
1086
+ return;
1086
1087
  }
1087
- });
1088
- }, [id]);
1088
+ const container = containerRef.current || document;
1089
+ const iframe = container.querySelector('iframe') || null;
1090
+ if (iframe === null || iframe.contentWindow !== event.source) {
1091
+ return;
1092
+ }
1093
+ const newRichAd = parseRichAd(event.data);
1094
+ if (newRichAd === null) {
1095
+ return;
1096
+ }
1097
+ debug('Received rich ad for %s %O', id, newRichAd);
1098
+ setRichAd(newRichAd);
1099
+ if (onRichAd !== null) {
1100
+ onRichAd(newRichAd);
1101
+ }
1102
+ }
1103
+ window.addEventListener('message', onMessage);
1104
+ return () => {
1105
+ window.removeEventListener('message', onMessage);
1106
+ };
1107
+ }, [id, onRichAd]);
1089
1108
  return richAd;
1090
1109
  }
1091
1110
 
@@ -1106,8 +1125,10 @@ const propTypes = {
1106
1125
  emptyClassName: PropTypes__default["default"].string,
1107
1126
  adClassName: PropTypes__default["default"].string,
1108
1127
  richAdClassName: PropTypes__default["default"].string,
1128
+ richAdIframeClassName: PropTypes__default["default"].string,
1109
1129
  onRender: PropTypes__default["default"].func,
1110
1130
  onDestroy: PropTypes__default["default"].func,
1131
+ onRichAd: PropTypes__default["default"].func,
1111
1132
  slotRef: PropTypes__default["default"].oneOfType([PropTypes__default["default"].func, PropTypes__default["default"].object])
1112
1133
  };
1113
1134
  const defaultProps = {
@@ -1126,8 +1147,10 @@ const defaultProps = {
1126
1147
  emptyClassName: null,
1127
1148
  adClassName: null,
1128
1149
  richAdClassName: null,
1150
+ richAdIframeClassName: null,
1129
1151
  onRender: null,
1130
1152
  onDestroy: null,
1153
+ onRichAd: null,
1131
1154
  slotRef: null
1132
1155
  };
1133
1156
  function Ad(_ref) {
@@ -1148,8 +1171,10 @@ function Ad(_ref) {
1148
1171
  emptyClassName,
1149
1172
  adClassName,
1150
1173
  richAdClassName,
1174
+ richAdIframeClassName,
1151
1175
  onRender,
1152
1176
  onDestroy,
1177
+ onRichAd,
1153
1178
  slotRef
1154
1179
  } = _ref;
1155
1180
  const {
@@ -1248,7 +1273,9 @@ function Ad(_ref) {
1248
1273
  disableTracking
1249
1274
  });
1250
1275
  const adContainerRef = React.useRef(null);
1251
- const richAd = useRichAd(adContainerRef, id);
1276
+ const richAd = useRichAd(adContainerRef, id, {
1277
+ onRichAd
1278
+ });
1252
1279
  if (slotRef !== null && isFunction__default["default"](slotRef)) {
1253
1280
  slotRef(slotObject);
1254
1281
  } else if (slotRef !== null && isObject__default["default"](slotRef)) {
@@ -1306,9 +1333,9 @@ function Ad(_ref) {
1306
1333
  ref: adContainerRef,
1307
1334
  children: [/*#__PURE__*/jsxRuntime.jsx("div", {
1308
1335
  id: id,
1309
- style: {
1310
- position: isRendered && richAd !== null ? 'absolute' : null
1311
- }
1336
+ className: classNames__default["default"]([{
1337
+ [richAdIframeClassName]: richAdIframeClassName !== null && isRendered && richAd !== null
1338
+ }])
1312
1339
  }), isRendered && richAd !== null ? /*#__PURE__*/jsxRuntime.jsx(RichAd, {
1313
1340
  richAd: richAd,
1314
1341
  isFluid: isFluid,
package/dist/es.js CHANGED
@@ -258,7 +258,7 @@ class AdSlot extends EventEmitter {
258
258
  }
259
259
 
260
260
  /* globals refreshDisabledLineItems: [] */
261
- const debug = createDebug('folklore:ads');
261
+ const debug$1 = createDebug('folklore:ads');
262
262
  class AdsManager extends EventEmitter {
263
263
  // static index = 0;
264
264
 
@@ -366,7 +366,7 @@ class AdsManager extends EventEmitter {
366
366
  if (this.disabled) {
367
367
  return;
368
368
  }
369
- debug('Initializing GPT...');
369
+ debug$1('Initializing GPT...');
370
370
  const {
371
371
  disabled,
372
372
  personnalizedAdsDisabled
@@ -380,19 +380,19 @@ class AdsManager extends EventEmitter {
380
380
  fetchMarginPercent = 300
381
381
  } = this.options;
382
382
  if (disabled) {
383
- debug('Disable initial load');
383
+ debug$1('Disable initial load');
384
384
  googletag.pubads().disableInitialLoad();
385
385
  }
386
386
  if (!disableSingleRequest) {
387
- debug('Enable single request');
387
+ debug$1('Enable single request');
388
388
  googletag.pubads().enableSingleRequest();
389
389
  }
390
390
  if (personnalizedAdsDisabled) {
391
- debug('Disable personalized ads');
391
+ debug$1('Disable personalized ads');
392
392
  googletag.pubads().setRequestNonPersonalizedAds(1);
393
393
  }
394
394
  if (!disableLazyLoad) {
395
- debug('Enable lazy loading %o', {
395
+ debug$1('Enable lazy loading %o', {
396
396
  fetchMarginPercent,
397
397
  renderMarginPercent,
398
398
  mobileScaling
@@ -404,13 +404,13 @@ class AdsManager extends EventEmitter {
404
404
  });
405
405
  }
406
406
  if (!disableVideoAds) {
407
- debug('Enable video ads');
407
+ debug$1('Enable video ads');
408
408
  googletag.pubads().enableVideoAds();
409
409
  }
410
410
  googletag.pubads().addEventListener('slotRenderEnded', this.onSlotRenderEnded);
411
411
  googletag.pubads().addEventListener('impressionViewable', this.onSlotImpressionViewable);
412
412
  googletag.enableServices();
413
- debug('GPT is ready');
413
+ debug$1('GPT is ready');
414
414
  this.enabled = true;
415
415
  this.ready = true;
416
416
  this.emit('ready');
@@ -430,9 +430,9 @@ class AdsManager extends EventEmitter {
430
430
  renderSlot.setRefreshDisabled();
431
431
  }
432
432
  if (event.isEmpty) {
433
- debug('Render ended for slot #%s(%s). Slot is empty.', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath());
433
+ debug$1('Render ended for slot #%s(%s). Slot is empty.', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath());
434
434
  } else {
435
- debug('Render ended for slot #%s(%s) with size %s.', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath(), size !== null ? size.join('x') : '-');
435
+ debug$1('Render ended for slot #%s(%s) with size %s.', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath(), size !== null ? size.join('x') : '-');
436
436
  }
437
437
  }
438
438
  onSlotImpressionViewable(event) {
@@ -443,12 +443,12 @@ class AdsManager extends EventEmitter {
443
443
  if (impressionSlot !== null) {
444
444
  impressionSlot.setViewable(true);
445
445
  }
446
- debug('Impression viewable for slot #%s(%s).', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath());
446
+ debug$1('Impression viewable for slot #%s(%s).', eventSlot.getSlotElementId(), eventSlot.getAdUnitPath());
447
447
  }
448
448
 
449
449
  // eslint-disable-next-line class-methods-use-this
450
450
  onSlotVisibleChange(visible, slot) {
451
- debug('Slot #%s(%s) visibility change to %s', slot.getElementId(), slot.getAdPath(), visible ? 'visible' : 'not visible');
451
+ debug$1('Slot #%s(%s) visibility change to %s', slot.getElementId(), slot.getAdPath(), visible ? 'visible' : 'not visible');
452
452
  }
453
453
  isReady() {
454
454
  return this.ready && this.enabled && !this.disabled;
@@ -486,7 +486,7 @@ class AdsManager extends EventEmitter {
486
486
  id: providedId = null
487
487
  } = opts;
488
488
  const id = providedId || this.createAdId();
489
- debug('Creating slot #%s(%s)...', id, path);
489
+ debug$1('Creating slot #%s(%s)...', id, path);
490
490
  const slot = new AdSlot(id, path, size, {
491
491
  ...opts
492
492
  });
@@ -505,7 +505,7 @@ class AdsManager extends EventEmitter {
505
505
  const id = slot.getElementId();
506
506
  const path = slot.getAdPath();
507
507
  const size = slot.getAdSize();
508
- debug('Defining slot #%s(%s)...', id, path);
508
+ debug$1('Defining slot #%s(%s)...', id, path);
509
509
  const adSlot = googletag.defineSlot(path, size, id).addService(googletag.pubads());
510
510
  slot.setAdSlot(adSlot);
511
511
  });
@@ -514,7 +514,7 @@ class AdsManager extends EventEmitter {
514
514
  const slotsToDisplay = this.slots.filter(slot => slot.canBeDisplayed());
515
515
  const slotsCount = slotsToDisplay.length;
516
516
  if (slotsCount > 0) {
517
- debug('Displaying %i slot(s)...', slotsCount);
517
+ debug$1('Displaying %i slot(s)...', slotsCount);
518
518
  slotsToDisplay.forEach(slot => this.callDisplaySlot(slot));
519
519
  }
520
520
  return true;
@@ -534,7 +534,7 @@ class AdsManager extends EventEmitter {
534
534
  googletag.cmd.push(() => {
535
535
  const id = slot.getElementId();
536
536
  const path = slot.getAdPath();
537
- debug('Displaying slot #%s(%s)...', id, path);
537
+ debug$1('Displaying slot #%s(%s)...', id, path);
538
538
  googletag.display(slot.getAdSlot());
539
539
  if (googletag.pubads().isInitialLoadDisabled()) {
540
540
  googletag.pubads().refresh([slot.getAdSlot()]);
@@ -556,7 +556,7 @@ class AdsManager extends EventEmitter {
556
556
  slot.destroy();
557
557
  this.slots = this.slots.filter(it => it !== slot);
558
558
  if (adSlot !== null) {
559
- debug('Destroying slot #%s(%s)...', adSlot.getAdUnitPath(), adSlot.getSlotElementId());
559
+ debug$1('Destroying slot #%s(%s)...', adSlot.getAdUnitPath(), adSlot.getSlotElementId());
560
560
  googletag.cmd.push(() => {
561
561
  googletag.destroySlots([adSlot]);
562
562
  });
@@ -573,7 +573,7 @@ class AdsManager extends EventEmitter {
573
573
  }
574
574
  const adSlot = slot.getAdSlot();
575
575
  if (adSlot !== null) {
576
- debug('Refreshing slot #%s(%s)...', adSlot.getAdUnitPath(), slot.getElementId());
576
+ debug$1('Refreshing slot #%s(%s)...', adSlot.getAdUnitPath(), slot.getElementId());
577
577
  googletag.cmd.push(() => {
578
578
  googletag.pubads().refresh([adSlot], {
579
579
  changeCorrelator: false
@@ -589,7 +589,7 @@ class AdsManager extends EventEmitter {
589
589
  if (slots.length === 0) {
590
590
  return;
591
591
  }
592
- debug('Refreshing slots %o...', slots.map(slot => `#${slot.getElementId()}(${slot.getAdUnitPath()})`));
592
+ debug$1('Refreshing slots %o...', slots.map(slot => `#${slot.getElementId()}(${slot.getAdUnitPath()})`));
593
593
  googletag.cmd.push(() => {
594
594
  googletag.pubads().refresh(slots);
595
595
  });
@@ -598,7 +598,7 @@ class AdsManager extends EventEmitter {
598
598
  const {
599
599
  googletag
600
600
  } = this;
601
- debug('Refreshing all slots...');
601
+ debug$1('Refreshing all slots...');
602
602
  googletag.cmd.push(() => {
603
603
  googletag.pubads().refresh();
604
604
  });
@@ -1047,27 +1047,46 @@ function useAd(path, size) {
1047
1047
  };
1048
1048
  }
1049
1049
 
1050
- function useRichAd(containerRef, id) {
1050
+ const debug = createDebug('folklore:ads');
1051
+ function parseRichAd(data) {
1052
+ let richAd = null;
1053
+ try {
1054
+ const eventData = JSON.parse(data) || null;
1055
+ richAd = eventData !== null ? eventData.richAd || null : null;
1056
+ } catch (e) {}
1057
+ return richAd;
1058
+ }
1059
+ function useRichAd(containerRef, id, opts) {
1051
1060
  const [richAd, setRichAd] = useState(null);
1061
+ const {
1062
+ onRichAd = null
1063
+ } = opts || {};
1052
1064
  useEffect(() => {
1053
1065
  setRichAd(null);
1054
- window.addEventListener('message', event => {
1055
- if (event.origin.match(/safeframe\.googlesyndication\.com/) !== null) {
1056
- let newRichAd = null;
1057
- try {
1058
- const eventData = JSON.parse(event.data) || null;
1059
- newRichAd = eventData !== null ? eventData.richAd || null : null;
1060
- } catch (e) {}
1061
- if (newRichAd !== null) {
1062
- const container = containerRef.current || document;
1063
- const iframe = container.querySelector('iframe') || null;
1064
- if (iframe !== null && iframe.contentWindow === event.source) {
1065
- setRichAd(newRichAd);
1066
- }
1067
- }
1066
+ function onMessage(event) {
1067
+ if (event.origin.match(/safeframe\.googlesyndication\.com/) === null) {
1068
+ return;
1068
1069
  }
1069
- });
1070
- }, [id]);
1070
+ const container = containerRef.current || document;
1071
+ const iframe = container.querySelector('iframe') || null;
1072
+ if (iframe === null || iframe.contentWindow !== event.source) {
1073
+ return;
1074
+ }
1075
+ const newRichAd = parseRichAd(event.data);
1076
+ if (newRichAd === null) {
1077
+ return;
1078
+ }
1079
+ debug('Received rich ad for %s %O', id, newRichAd);
1080
+ setRichAd(newRichAd);
1081
+ if (onRichAd !== null) {
1082
+ onRichAd(newRichAd);
1083
+ }
1084
+ }
1085
+ window.addEventListener('message', onMessage);
1086
+ return () => {
1087
+ window.removeEventListener('message', onMessage);
1088
+ };
1089
+ }, [id, onRichAd]);
1071
1090
  return richAd;
1072
1091
  }
1073
1092
 
@@ -1088,8 +1107,10 @@ const propTypes = {
1088
1107
  emptyClassName: PropTypes.string,
1089
1108
  adClassName: PropTypes.string,
1090
1109
  richAdClassName: PropTypes.string,
1110
+ richAdIframeClassName: PropTypes.string,
1091
1111
  onRender: PropTypes.func,
1092
1112
  onDestroy: PropTypes.func,
1113
+ onRichAd: PropTypes.func,
1093
1114
  slotRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
1094
1115
  };
1095
1116
  const defaultProps = {
@@ -1108,8 +1129,10 @@ const defaultProps = {
1108
1129
  emptyClassName: null,
1109
1130
  adClassName: null,
1110
1131
  richAdClassName: null,
1132
+ richAdIframeClassName: null,
1111
1133
  onRender: null,
1112
1134
  onDestroy: null,
1135
+ onRichAd: null,
1113
1136
  slotRef: null
1114
1137
  };
1115
1138
  function Ad(_ref) {
@@ -1130,8 +1153,10 @@ function Ad(_ref) {
1130
1153
  emptyClassName,
1131
1154
  adClassName,
1132
1155
  richAdClassName,
1156
+ richAdIframeClassName,
1133
1157
  onRender,
1134
1158
  onDestroy,
1159
+ onRichAd,
1135
1160
  slotRef
1136
1161
  } = _ref;
1137
1162
  const {
@@ -1230,7 +1255,9 @@ function Ad(_ref) {
1230
1255
  disableTracking
1231
1256
  });
1232
1257
  const adContainerRef = useRef(null);
1233
- const richAd = useRichAd(adContainerRef, id);
1258
+ const richAd = useRichAd(adContainerRef, id, {
1259
+ onRichAd
1260
+ });
1234
1261
  if (slotRef !== null && isFunction(slotRef)) {
1235
1262
  slotRef(slotObject);
1236
1263
  } else if (slotRef !== null && isObject(slotRef)) {
@@ -1288,9 +1315,9 @@ function Ad(_ref) {
1288
1315
  ref: adContainerRef,
1289
1316
  children: [/*#__PURE__*/jsx("div", {
1290
1317
  id: id,
1291
- style: {
1292
- position: isRendered && richAd !== null ? 'absolute' : null
1293
- }
1318
+ className: classNames([{
1319
+ [richAdIframeClassName]: richAdIframeClassName !== null && isRendered && richAd !== null
1320
+ }])
1294
1321
  }), isRendered && richAd !== null ? /*#__PURE__*/jsx(RichAd, {
1295
1322
  richAd: richAd,
1296
1323
  isFluid: isFluid,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folklore/ads",
3
- "version": "0.0.76",
3
+ "version": "0.0.78",
4
4
  "description": "Ads library",
5
5
  "keywords": [
6
6
  "javascript",
@@ -50,7 +50,7 @@
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "gitHead": "4c607d1f1a031278d3cf2249a84452a214af57b0",
53
+ "gitHead": "305e55290b425a9b60853ce4b1a9688956f77f68",
54
54
  "dependencies": {
55
55
  "@folklore/hooks": "^0.0.65",
56
56
  "@folklore/tracking": "^0.0.25",