@folklore/ads 0.0.38 → 0.0.40
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/dist/cjs.js +49 -22
- package/dist/es.js +49 -22
- package/package.json +2 -2
package/dist/cjs.js
CHANGED
|
@@ -192,6 +192,13 @@ class AdSlot extends EventEmitter__default["default"] {
|
|
|
192
192
|
setRefreshDisabled() {
|
|
193
193
|
this.refreshDisabled = true;
|
|
194
194
|
}
|
|
195
|
+
setTargeting(targeting) {
|
|
196
|
+
if (this.adSlot !== null) {
|
|
197
|
+
this.adSlot.updateTargetingFromMap(targeting);
|
|
198
|
+
} else {
|
|
199
|
+
this.options.targeting = targeting;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
195
202
|
destroy() {
|
|
196
203
|
if (this.destroyed) {
|
|
197
204
|
return;
|
|
@@ -269,12 +276,16 @@ class AdSlot extends EventEmitter__default["default"] {
|
|
|
269
276
|
/* globals refreshDisabledLineItems: [] */
|
|
270
277
|
const debug = createDebug__default["default"]('folklore:ads');
|
|
271
278
|
class AdsManager extends EventEmitter__default["default"] {
|
|
272
|
-
static index = 0;
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
279
|
+
// static index = 0;
|
|
280
|
+
|
|
281
|
+
// static createAdId() {
|
|
282
|
+
// const newId = `div-gpt-ad-${new Date().getTime()}-${Math.round(
|
|
283
|
+
// Math.random() * (Math.random() * 1000),
|
|
284
|
+
// )}-${AdsManager.index}`;
|
|
285
|
+
// AdsManager.index += 1;
|
|
286
|
+
// return newId;
|
|
287
|
+
// }
|
|
288
|
+
|
|
278
289
|
static getArticleTargeting(article) {
|
|
279
290
|
if (article === null) {
|
|
280
291
|
return null;
|
|
@@ -339,10 +350,19 @@ class AdsManager extends EventEmitter__default["default"] {
|
|
|
339
350
|
cmd: []
|
|
340
351
|
};
|
|
341
352
|
this.slots = [];
|
|
353
|
+
this.index = 0;
|
|
342
354
|
if (this.options.autoInit) {
|
|
343
355
|
this.init();
|
|
344
356
|
}
|
|
345
357
|
}
|
|
358
|
+
createAdId() {
|
|
359
|
+
// const newId = `div-gpt-ad-${new Date().getTime()}-${Math.round(
|
|
360
|
+
// Math.random() * (Math.random() * 1000),
|
|
361
|
+
// )}-${this.index}`;
|
|
362
|
+
const newId = `div-gpt-ad-${this.index}`;
|
|
363
|
+
this.index += 1;
|
|
364
|
+
return newId;
|
|
365
|
+
}
|
|
346
366
|
onGPTReady() {
|
|
347
367
|
const {
|
|
348
368
|
googletag
|
|
@@ -471,7 +491,7 @@ class AdsManager extends EventEmitter__default["default"] {
|
|
|
471
491
|
const {
|
|
472
492
|
id: providedId = null
|
|
473
493
|
} = opts;
|
|
474
|
-
const id = providedId ||
|
|
494
|
+
const id = providedId || this.createAdId();
|
|
475
495
|
debug('Creating slot #%s(%s)...', id, path);
|
|
476
496
|
const slot = new AdSlot(id, path, size, {
|
|
477
497
|
...opts
|
|
@@ -745,25 +765,27 @@ function AdsProvider(_ref) {
|
|
|
745
765
|
onResize.cancel();
|
|
746
766
|
};
|
|
747
767
|
}, [ads, resizeDebounceDelay, refreshOnResize]);
|
|
768
|
+
const slotsWithSizeMapping = React.useMemo(() => Object.keys(slots || {}).reduce((map, key) => ({
|
|
769
|
+
...map,
|
|
770
|
+
[key]: {
|
|
771
|
+
...slots[key],
|
|
772
|
+
sizeMapping: getSizeMappingFromSlot(slots[key], viewports)
|
|
773
|
+
}
|
|
774
|
+
}), {}), []);
|
|
775
|
+
const finalSlotsPath = React.useMemo(() => defaultSlotPath !== null ? {
|
|
776
|
+
default: defaultSlotPath,
|
|
777
|
+
...slotsPath
|
|
778
|
+
} : {
|
|
779
|
+
...slotsPath
|
|
780
|
+
}, [defaultSlotPath, slotsPath]);
|
|
748
781
|
const value = React.useMemo(() => ({
|
|
749
782
|
ready,
|
|
750
783
|
ads,
|
|
751
784
|
viewports,
|
|
752
|
-
slots:
|
|
753
|
-
|
|
754
|
-
[key]: {
|
|
755
|
-
...slots[key],
|
|
756
|
-
sizeMapping: getSizeMappingFromSlot(slots[key], viewports)
|
|
757
|
-
}
|
|
758
|
-
}), {}),
|
|
759
|
-
slotsPath: defaultSlotPath !== null ? {
|
|
760
|
-
default: defaultSlotPath,
|
|
761
|
-
...slotsPath
|
|
762
|
-
} : {
|
|
763
|
-
...slotsPath
|
|
764
|
-
},
|
|
785
|
+
slots: slotsWithSizeMapping,
|
|
786
|
+
slotsPath: finalSlotsPath,
|
|
765
787
|
trackingDisabled: disableTracking
|
|
766
|
-
}), [ready, ads, viewports,
|
|
788
|
+
}), [ready, ads, viewports, slotsWithSizeMapping, finalSlotsPath, disableTracking]);
|
|
767
789
|
return /*#__PURE__*/jsxRuntime.jsx(AdsContext.Provider, {
|
|
768
790
|
value: value,
|
|
769
791
|
children: children
|
|
@@ -878,7 +900,12 @@ function useAd(path, size) {
|
|
|
878
900
|
// adsManager.defineSlot(currentSlot.current);
|
|
879
901
|
// }
|
|
880
902
|
return currentSlot.current;
|
|
881
|
-
}, [adsManager, path, disabled, size, sizeMapping,
|
|
903
|
+
}, [adsManager, path, disabled, size, sizeMapping, alwaysRender, categoryExclusions]);
|
|
904
|
+
React.useEffect(() => {
|
|
905
|
+
if (currentSlot.current !== null) {
|
|
906
|
+
currentSlot.current.setTargeting(targeting);
|
|
907
|
+
}
|
|
908
|
+
}, [targeting]);
|
|
882
909
|
|
|
883
910
|
// Set visibility
|
|
884
911
|
React.useEffect(() => {
|
package/dist/es.js
CHANGED
|
@@ -174,6 +174,13 @@ class AdSlot extends EventEmitter {
|
|
|
174
174
|
setRefreshDisabled() {
|
|
175
175
|
this.refreshDisabled = true;
|
|
176
176
|
}
|
|
177
|
+
setTargeting(targeting) {
|
|
178
|
+
if (this.adSlot !== null) {
|
|
179
|
+
this.adSlot.updateTargetingFromMap(targeting);
|
|
180
|
+
} else {
|
|
181
|
+
this.options.targeting = targeting;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
177
184
|
destroy() {
|
|
178
185
|
if (this.destroyed) {
|
|
179
186
|
return;
|
|
@@ -251,12 +258,16 @@ class AdSlot extends EventEmitter {
|
|
|
251
258
|
/* globals refreshDisabledLineItems: [] */
|
|
252
259
|
const debug = createDebug('folklore:ads');
|
|
253
260
|
class AdsManager extends EventEmitter {
|
|
254
|
-
static index = 0;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
261
|
+
// static index = 0;
|
|
262
|
+
|
|
263
|
+
// static createAdId() {
|
|
264
|
+
// const newId = `div-gpt-ad-${new Date().getTime()}-${Math.round(
|
|
265
|
+
// Math.random() * (Math.random() * 1000),
|
|
266
|
+
// )}-${AdsManager.index}`;
|
|
267
|
+
// AdsManager.index += 1;
|
|
268
|
+
// return newId;
|
|
269
|
+
// }
|
|
270
|
+
|
|
260
271
|
static getArticleTargeting(article) {
|
|
261
272
|
if (article === null) {
|
|
262
273
|
return null;
|
|
@@ -321,10 +332,19 @@ class AdsManager extends EventEmitter {
|
|
|
321
332
|
cmd: []
|
|
322
333
|
};
|
|
323
334
|
this.slots = [];
|
|
335
|
+
this.index = 0;
|
|
324
336
|
if (this.options.autoInit) {
|
|
325
337
|
this.init();
|
|
326
338
|
}
|
|
327
339
|
}
|
|
340
|
+
createAdId() {
|
|
341
|
+
// const newId = `div-gpt-ad-${new Date().getTime()}-${Math.round(
|
|
342
|
+
// Math.random() * (Math.random() * 1000),
|
|
343
|
+
// )}-${this.index}`;
|
|
344
|
+
const newId = `div-gpt-ad-${this.index}`;
|
|
345
|
+
this.index += 1;
|
|
346
|
+
return newId;
|
|
347
|
+
}
|
|
328
348
|
onGPTReady() {
|
|
329
349
|
const {
|
|
330
350
|
googletag
|
|
@@ -453,7 +473,7 @@ class AdsManager extends EventEmitter {
|
|
|
453
473
|
const {
|
|
454
474
|
id: providedId = null
|
|
455
475
|
} = opts;
|
|
456
|
-
const id = providedId ||
|
|
476
|
+
const id = providedId || this.createAdId();
|
|
457
477
|
debug('Creating slot #%s(%s)...', id, path);
|
|
458
478
|
const slot = new AdSlot(id, path, size, {
|
|
459
479
|
...opts
|
|
@@ -727,25 +747,27 @@ function AdsProvider(_ref) {
|
|
|
727
747
|
onResize.cancel();
|
|
728
748
|
};
|
|
729
749
|
}, [ads, resizeDebounceDelay, refreshOnResize]);
|
|
750
|
+
const slotsWithSizeMapping = useMemo(() => Object.keys(slots || {}).reduce((map, key) => ({
|
|
751
|
+
...map,
|
|
752
|
+
[key]: {
|
|
753
|
+
...slots[key],
|
|
754
|
+
sizeMapping: getSizeMappingFromSlot(slots[key], viewports)
|
|
755
|
+
}
|
|
756
|
+
}), {}), []);
|
|
757
|
+
const finalSlotsPath = useMemo(() => defaultSlotPath !== null ? {
|
|
758
|
+
default: defaultSlotPath,
|
|
759
|
+
...slotsPath
|
|
760
|
+
} : {
|
|
761
|
+
...slotsPath
|
|
762
|
+
}, [defaultSlotPath, slotsPath]);
|
|
730
763
|
const value = useMemo(() => ({
|
|
731
764
|
ready,
|
|
732
765
|
ads,
|
|
733
766
|
viewports,
|
|
734
|
-
slots:
|
|
735
|
-
|
|
736
|
-
[key]: {
|
|
737
|
-
...slots[key],
|
|
738
|
-
sizeMapping: getSizeMappingFromSlot(slots[key], viewports)
|
|
739
|
-
}
|
|
740
|
-
}), {}),
|
|
741
|
-
slotsPath: defaultSlotPath !== null ? {
|
|
742
|
-
default: defaultSlotPath,
|
|
743
|
-
...slotsPath
|
|
744
|
-
} : {
|
|
745
|
-
...slotsPath
|
|
746
|
-
},
|
|
767
|
+
slots: slotsWithSizeMapping,
|
|
768
|
+
slotsPath: finalSlotsPath,
|
|
747
769
|
trackingDisabled: disableTracking
|
|
748
|
-
}), [ready, ads, viewports,
|
|
770
|
+
}), [ready, ads, viewports, slotsWithSizeMapping, finalSlotsPath, disableTracking]);
|
|
749
771
|
return /*#__PURE__*/jsx(AdsContext.Provider, {
|
|
750
772
|
value: value,
|
|
751
773
|
children: children
|
|
@@ -860,7 +882,12 @@ function useAd(path, size) {
|
|
|
860
882
|
// adsManager.defineSlot(currentSlot.current);
|
|
861
883
|
// }
|
|
862
884
|
return currentSlot.current;
|
|
863
|
-
}, [adsManager, path, disabled, size, sizeMapping,
|
|
885
|
+
}, [adsManager, path, disabled, size, sizeMapping, alwaysRender, categoryExclusions]);
|
|
886
|
+
useEffect(() => {
|
|
887
|
+
if (currentSlot.current !== null) {
|
|
888
|
+
currentSlot.current.setTargeting(targeting);
|
|
889
|
+
}
|
|
890
|
+
}, [targeting]);
|
|
864
891
|
|
|
865
892
|
// Set visibility
|
|
866
893
|
useEffect(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@folklore/ads",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.40",
|
|
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": "
|
|
53
|
+
"gitHead": "9b792452940372423d526d0fb10d3f427b7ebe1c",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@folklore/hooks": "^0.0.44",
|
|
56
56
|
"@folklore/tracking": "^0.0.23",
|