@reuters-graphics/graphics-components 1.0.14 → 1.0.16

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.
@@ -8,15 +8,27 @@ export let adType;
8
8
  export let dataFreestarAd = '__970x250';
9
9
  const adId = getRandomAdId();
10
10
  onMount(() => {
11
- window.graphicsAdQueue = window.graphicsAdQueue || [];
12
- window.graphicsAdQueue.push({
11
+ const adSlot = {
13
12
  placementName,
14
13
  slotId: adId,
15
14
  targeting: {
16
15
  div_id: adId,
17
16
  type: adType,
18
17
  },
19
- });
18
+ };
19
+ // @ts-ignore
20
+ const freestar = window?.freestar;
21
+ // Add adSlot to freestar queue directly if already initialised
22
+ if (freestar) {
23
+ freestar.queue.push(function () {
24
+ freestar.newAdSlots([adSlot], freestar.config.channel);
25
+ });
26
+ // ... otherwise add to the graphicsAdQueue queue.
27
+ }
28
+ else {
29
+ window.graphicsAdQueue = window.graphicsAdQueue || [];
30
+ window.graphicsAdQueue.push(adSlot);
31
+ }
20
32
  });
21
33
  </script>
22
34
 
@@ -45,12 +45,6 @@ export const loadBootstrap = () => {
45
45
  window.googletag.pubads().enableAsyncRendering();
46
46
  window.googletag.pubads().collapseEmptyDivs(true);
47
47
  });
48
- if (!Array.isArray(window.graphicsAdQueue)) {
49
- console.error('Ad queue not initialized!');
50
- }
51
- freestar.queue.push(function () {
52
- freestar.newAdSlots(window.graphicsAdQueue || [], freestar.config.channel);
53
- });
54
48
  // Set page-level key-values
55
49
  // cf: https://help.freestar.com/help/using-key-values
56
50
  freestar.queue.push(function () {
@@ -60,12 +54,18 @@ export const loadBootstrap = () => {
60
54
  window.googletag.pubads().setTargeting('adstest', adstest);
61
55
  }
62
56
  // Use the URL path to create a unique ID for the page.
63
- const graphicId = window.location.pathname
64
- .replace(/^\/(.*)\/$/, '$1')
65
- .replaceAll('/', '-');
57
+ const graphicId = window.location.pathname.split('/')
58
+ // Get the first lowercase slug in the pathname, which is the graphic UID.
59
+ .filter(d => d.match(/[a-z0-9]+/) && d !== 'graphics')[0] || 'unknown-graphic';
66
60
  window.googletag.pubads().setTargeting('template', 'graphics');
67
61
  window.googletag.pubads().setTargeting('graphicId', graphicId);
68
62
  });
63
+ if (!Array.isArray(window.graphicsAdQueue)) {
64
+ console.error('Ad queue not initialized!');
65
+ }
66
+ freestar.queue.push(function () {
67
+ freestar.newAdSlots(window.graphicsAdQueue || [], freestar.config.channel);
68
+ });
69
69
  });
70
70
  };
71
71
  //# sourceMappingURL=bootstrap.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reuters-graphics/graphics-components",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://reuters-graphics.github.io/graphics-components",