@folklore/ads 0.0.41 → 0.0.43

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 +73 -64
  2. package/dist/es.js +73 -64
  3. package/package.json +2 -2
package/dist/cjs.js CHANGED
@@ -351,7 +351,7 @@ class AdsManager extends EventEmitter__default["default"] {
351
351
  };
352
352
  this.slots = [];
353
353
  this.index = 0;
354
- if (this.options.autoInit) {
354
+ if (this.options.autoInit && !this.disabled) {
355
355
  this.init();
356
356
  }
357
357
  }
@@ -363,60 +363,73 @@ class AdsManager extends EventEmitter__default["default"] {
363
363
  this.index += 1;
364
364
  return newId;
365
365
  }
366
- onGPTReady() {
366
+ init() {
367
367
  const {
368
368
  googletag
369
369
  } = this;
370
- this.ready = true;
371
370
  googletag.cmd.push(() => {
372
- const {
373
- disabled,
374
- personnalizedAdsDisabled
375
- } = this;
376
- const {
377
- disableSingleRequest = false,
378
- disableLazyLoad = false,
379
- disableVideoAds = false,
380
- mobileScaling = 1.0,
381
- renderMarginPercent = 100,
382
- fetchMarginPercent = 300
383
- } = this.options;
384
- if (disabled) {
385
- debug('Disable initial load');
386
- googletag.pubads().disableInitialLoad();
387
- }
388
- if (!disableSingleRequest) {
389
- debug('Enable single request');
390
- googletag.pubads().enableSingleRequest();
391
- }
392
- if (personnalizedAdsDisabled) {
393
- debug('Disable personalized ads');
394
- googletag.pubads().setRequestNonPersonalizedAds(1);
395
- }
396
- if (!disableLazyLoad) {
397
- googletag.pubads().enableLazyLoad({
398
- // Fetch slots within 5 viewports.
399
- fetchMarginPercent,
400
- // Render slots within 2 viewports.
401
- renderMarginPercent,
402
- // Double the above values on mobile, where viewports are smaller
403
- // and users tend to scroll faster.
404
- mobileScaling
405
- });
406
- }
407
- if (!disableVideoAds) {
408
- googletag.pubads().enableVideoAds();
409
- }
410
- googletag.pubads().addEventListener('slotRenderEnded', this.onSlotRenderEnded);
411
- googletag.pubads().addEventListener('impressionViewable', this.onSlotImpressionViewable);
412
- googletag.enableServices();
413
- this.enabled = true;
414
- debug('GPT is ready');
415
- if (!disabled) {
416
- this.emit('ready');
371
+ if (this.disabled) {
372
+ return;
417
373
  }
374
+ this.initGpt();
418
375
  });
419
376
  }
377
+ initGpt() {
378
+ const {
379
+ googletag
380
+ } = this;
381
+ if (this.disabled) {
382
+ return;
383
+ }
384
+ debug('Initializing GPT...');
385
+ const {
386
+ disabled,
387
+ personnalizedAdsDisabled
388
+ } = this;
389
+ const {
390
+ disableSingleRequest = false,
391
+ disableLazyLoad = false,
392
+ disableVideoAds = false,
393
+ mobileScaling = 1.0,
394
+ renderMarginPercent = 100,
395
+ fetchMarginPercent = 300
396
+ } = this.options;
397
+ if (disabled) {
398
+ debug('Disable initial load');
399
+ googletag.pubads().disableInitialLoad();
400
+ }
401
+ if (!disableSingleRequest) {
402
+ debug('Enable single request');
403
+ googletag.pubads().enableSingleRequest();
404
+ }
405
+ if (personnalizedAdsDisabled) {
406
+ debug('Disable personalized ads');
407
+ googletag.pubads().setRequestNonPersonalizedAds(1);
408
+ }
409
+ if (!disableLazyLoad) {
410
+ debug('Enable lazy loading %o', {
411
+ fetchMarginPercent,
412
+ renderMarginPercent,
413
+ mobileScaling
414
+ });
415
+ googletag.pubads().enableLazyLoad({
416
+ fetchMarginPercent,
417
+ renderMarginPercent,
418
+ mobileScaling
419
+ });
420
+ }
421
+ if (!disableVideoAds) {
422
+ debug('Enable video ads');
423
+ googletag.pubads().enableVideoAds();
424
+ }
425
+ googletag.pubads().addEventListener('slotRenderEnded', this.onSlotRenderEnded);
426
+ googletag.pubads().addEventListener('impressionViewable', this.onSlotImpressionViewable);
427
+ googletag.enableServices();
428
+ debug('GPT is ready');
429
+ this.enabled = true;
430
+ this.ready = true;
431
+ this.emit('ready');
432
+ }
420
433
  onSlotRenderEnded(event) {
421
434
  const {
422
435
  slot: eventSlot,
@@ -452,15 +465,6 @@ class AdsManager extends EventEmitter__default["default"] {
452
465
  onSlotVisibleChange(visible, slot) {
453
466
  debug('Slot #%s(%s) visibility change to %s', slot.getElementId(), slot.getAdPath(), visible ? 'visible' : 'not visible');
454
467
  }
455
- init() {
456
- const {
457
- googletag
458
- } = this;
459
- debug('Initializing ads manager...');
460
- googletag.cmd.push(() => {
461
- this.onGPTReady();
462
- });
463
- }
464
468
  isReady() {
465
469
  return this.ready && this.enabled && !this.disabled;
466
470
  }
@@ -468,14 +472,19 @@ class AdsManager extends EventEmitter__default["default"] {
468
472
  return this.disabled;
469
473
  }
470
474
  setDisabled(disabled) {
471
- const shouldRefresh = this.disabled && !disabled;
475
+ // const shouldRefresh = this.disabled && !disabled;
472
476
  this.disabled = disabled;
473
- if (shouldRefresh) {
474
- this.refreshAllSlots();
475
- }
476
- if (this.enabled && !disabled) {
477
- this.emit('ready');
477
+ if (!this.enabled && !disabled) {
478
+ this.init();
478
479
  }
480
+
481
+ // if (shouldRefresh) {
482
+ // this.refreshAllSlots();
483
+ // }
484
+
485
+ // if (this.enabled && !disabled) {
486
+ // this.emit('ready');
487
+ // }
479
488
  }
480
489
  disablePersonnalizedAds(disablePersonnalizedAds) {
481
490
  const {
@@ -885,7 +894,7 @@ function useAd(path, size) {
885
894
 
886
895
  // Create slot
887
896
  // const currentSlot = useRef(null);
888
- const [slot, setSlot] = React.useState();
897
+ const [slot, setSlot] = React.useState(null);
889
898
  React.useEffect(() => {
890
899
  // if (currentSlot.current !== null) {
891
900
  // adsManager.destroySlot(currentSlot.current);
package/dist/es.js CHANGED
@@ -333,7 +333,7 @@ class AdsManager extends EventEmitter {
333
333
  };
334
334
  this.slots = [];
335
335
  this.index = 0;
336
- if (this.options.autoInit) {
336
+ if (this.options.autoInit && !this.disabled) {
337
337
  this.init();
338
338
  }
339
339
  }
@@ -345,60 +345,73 @@ class AdsManager extends EventEmitter {
345
345
  this.index += 1;
346
346
  return newId;
347
347
  }
348
- onGPTReady() {
348
+ init() {
349
349
  const {
350
350
  googletag
351
351
  } = this;
352
- this.ready = true;
353
352
  googletag.cmd.push(() => {
354
- const {
355
- disabled,
356
- personnalizedAdsDisabled
357
- } = this;
358
- const {
359
- disableSingleRequest = false,
360
- disableLazyLoad = false,
361
- disableVideoAds = false,
362
- mobileScaling = 1.0,
363
- renderMarginPercent = 100,
364
- fetchMarginPercent = 300
365
- } = this.options;
366
- if (disabled) {
367
- debug('Disable initial load');
368
- googletag.pubads().disableInitialLoad();
369
- }
370
- if (!disableSingleRequest) {
371
- debug('Enable single request');
372
- googletag.pubads().enableSingleRequest();
373
- }
374
- if (personnalizedAdsDisabled) {
375
- debug('Disable personalized ads');
376
- googletag.pubads().setRequestNonPersonalizedAds(1);
377
- }
378
- if (!disableLazyLoad) {
379
- googletag.pubads().enableLazyLoad({
380
- // Fetch slots within 5 viewports.
381
- fetchMarginPercent,
382
- // Render slots within 2 viewports.
383
- renderMarginPercent,
384
- // Double the above values on mobile, where viewports are smaller
385
- // and users tend to scroll faster.
386
- mobileScaling
387
- });
388
- }
389
- if (!disableVideoAds) {
390
- googletag.pubads().enableVideoAds();
391
- }
392
- googletag.pubads().addEventListener('slotRenderEnded', this.onSlotRenderEnded);
393
- googletag.pubads().addEventListener('impressionViewable', this.onSlotImpressionViewable);
394
- googletag.enableServices();
395
- this.enabled = true;
396
- debug('GPT is ready');
397
- if (!disabled) {
398
- this.emit('ready');
353
+ if (this.disabled) {
354
+ return;
399
355
  }
356
+ this.initGpt();
400
357
  });
401
358
  }
359
+ initGpt() {
360
+ const {
361
+ googletag
362
+ } = this;
363
+ if (this.disabled) {
364
+ return;
365
+ }
366
+ debug('Initializing GPT...');
367
+ const {
368
+ disabled,
369
+ personnalizedAdsDisabled
370
+ } = this;
371
+ const {
372
+ disableSingleRequest = false,
373
+ disableLazyLoad = false,
374
+ disableVideoAds = false,
375
+ mobileScaling = 1.0,
376
+ renderMarginPercent = 100,
377
+ fetchMarginPercent = 300
378
+ } = this.options;
379
+ if (disabled) {
380
+ debug('Disable initial load');
381
+ googletag.pubads().disableInitialLoad();
382
+ }
383
+ if (!disableSingleRequest) {
384
+ debug('Enable single request');
385
+ googletag.pubads().enableSingleRequest();
386
+ }
387
+ if (personnalizedAdsDisabled) {
388
+ debug('Disable personalized ads');
389
+ googletag.pubads().setRequestNonPersonalizedAds(1);
390
+ }
391
+ if (!disableLazyLoad) {
392
+ debug('Enable lazy loading %o', {
393
+ fetchMarginPercent,
394
+ renderMarginPercent,
395
+ mobileScaling
396
+ });
397
+ googletag.pubads().enableLazyLoad({
398
+ fetchMarginPercent,
399
+ renderMarginPercent,
400
+ mobileScaling
401
+ });
402
+ }
403
+ if (!disableVideoAds) {
404
+ debug('Enable video ads');
405
+ googletag.pubads().enableVideoAds();
406
+ }
407
+ googletag.pubads().addEventListener('slotRenderEnded', this.onSlotRenderEnded);
408
+ googletag.pubads().addEventListener('impressionViewable', this.onSlotImpressionViewable);
409
+ googletag.enableServices();
410
+ debug('GPT is ready');
411
+ this.enabled = true;
412
+ this.ready = true;
413
+ this.emit('ready');
414
+ }
402
415
  onSlotRenderEnded(event) {
403
416
  const {
404
417
  slot: eventSlot,
@@ -434,15 +447,6 @@ class AdsManager extends EventEmitter {
434
447
  onSlotVisibleChange(visible, slot) {
435
448
  debug('Slot #%s(%s) visibility change to %s', slot.getElementId(), slot.getAdPath(), visible ? 'visible' : 'not visible');
436
449
  }
437
- init() {
438
- const {
439
- googletag
440
- } = this;
441
- debug('Initializing ads manager...');
442
- googletag.cmd.push(() => {
443
- this.onGPTReady();
444
- });
445
- }
446
450
  isReady() {
447
451
  return this.ready && this.enabled && !this.disabled;
448
452
  }
@@ -450,14 +454,19 @@ class AdsManager extends EventEmitter {
450
454
  return this.disabled;
451
455
  }
452
456
  setDisabled(disabled) {
453
- const shouldRefresh = this.disabled && !disabled;
457
+ // const shouldRefresh = this.disabled && !disabled;
454
458
  this.disabled = disabled;
455
- if (shouldRefresh) {
456
- this.refreshAllSlots();
457
- }
458
- if (this.enabled && !disabled) {
459
- this.emit('ready');
459
+ if (!this.enabled && !disabled) {
460
+ this.init();
460
461
  }
462
+
463
+ // if (shouldRefresh) {
464
+ // this.refreshAllSlots();
465
+ // }
466
+
467
+ // if (this.enabled && !disabled) {
468
+ // this.emit('ready');
469
+ // }
461
470
  }
462
471
  disablePersonnalizedAds(disablePersonnalizedAds) {
463
472
  const {
@@ -867,7 +876,7 @@ function useAd(path, size) {
867
876
 
868
877
  // Create slot
869
878
  // const currentSlot = useRef(null);
870
- const [slot, setSlot] = useState();
879
+ const [slot, setSlot] = useState(null);
871
880
  useEffect(() => {
872
881
  // if (currentSlot.current !== null) {
873
882
  // adsManager.destroySlot(currentSlot.current);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folklore/ads",
3
- "version": "0.0.41",
3
+ "version": "0.0.43",
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": "ee7a99e9a056e466320a99c43f1982d1d5900079",
53
+ "gitHead": "d4638f437512793501b8a132606d08abfd1782dd",
54
54
  "dependencies": {
55
55
  "@folklore/hooks": "^0.0.44",
56
56
  "@folklore/tracking": "^0.0.23",