@guardian/commercial-core 7.1.0 → 27.1.0

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 (173) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +23 -34
  3. package/dist/cjs/ad-sizes.d.ts +150 -8
  4. package/dist/cjs/ad-sizes.js +129 -38
  5. package/dist/cjs/breakpoint.d.ts +8 -0
  6. package/dist/cjs/breakpoint.js +10 -0
  7. package/dist/cjs/constants/index.d.ts +1 -1
  8. package/dist/cjs/constants/index.js +2 -2
  9. package/dist/cjs/detect-ad-blocker.js +1 -2
  10. package/dist/cjs/event-timer.d.ts +60 -48
  11. package/dist/cjs/event-timer.js +149 -115
  12. package/dist/cjs/geo/country-code.d.ts +3 -0
  13. package/dist/cjs/geo/country-code.js +34 -0
  14. package/dist/cjs/geo/geo-utils.d.ts +11 -0
  15. package/dist/cjs/geo/geo-utils.js +31 -0
  16. package/dist/cjs/global.d.ts +58 -10
  17. package/dist/cjs/index.d.ts +9 -39
  18. package/dist/cjs/index.js +12 -67
  19. package/dist/cjs/send-commercial-metrics.d.ts +8 -2
  20. package/dist/cjs/send-commercial-metrics.js +51 -27
  21. package/dist/cjs/targeting/build-page-targeting.d.ts +4 -5
  22. package/dist/cjs/targeting/build-page-targeting.js +35 -7
  23. package/dist/cjs/targeting/content.d.ts +1 -1
  24. package/dist/cjs/targeting/content.js +1 -1
  25. package/dist/cjs/targeting/personalised.d.ts +2 -3
  26. package/dist/cjs/targeting/personalised.js +3 -3
  27. package/dist/cjs/targeting/pick-targeting-values.d.ts +1 -1
  28. package/dist/cjs/targeting/session.d.ts +2 -2
  29. package/dist/cjs/targeting/shared.d.ts +31 -20
  30. package/dist/cjs/targeting/shared.js +0 -30
  31. package/dist/cjs/targeting/teads-eligibility.d.ts +2 -0
  32. package/dist/cjs/targeting/teads-eligibility.js +20 -0
  33. package/dist/cjs/targeting/types.d.ts +6 -0
  34. package/dist/cjs/targeting/types.js +2 -0
  35. package/dist/cjs/targeting/viewport.d.ts +1 -1
  36. package/dist/cjs/targeting/youtube-ima.d.ts +4 -3
  37. package/dist/cjs/targeting/youtube-ima.js +7 -4
  38. package/dist/cjs/types.d.ts +403 -63
  39. package/dist/cjs/types.js +11 -0
  40. package/dist/esm/ad-sizes.d.ts +150 -8
  41. package/dist/esm/ad-sizes.js +127 -38
  42. package/dist/esm/breakpoint.d.ts +8 -0
  43. package/dist/esm/breakpoint.js +6 -0
  44. package/dist/esm/constants/index.d.ts +1 -1
  45. package/dist/esm/constants/index.js +1 -1
  46. package/dist/esm/event-timer.d.ts +60 -48
  47. package/dist/esm/event-timer.js +147 -115
  48. package/dist/esm/geo/country-code.d.ts +3 -0
  49. package/dist/esm/geo/country-code.js +31 -0
  50. package/dist/esm/geo/geo-utils.d.ts +11 -0
  51. package/dist/esm/geo/geo-utils.js +20 -0
  52. package/dist/esm/global.d.ts +58 -10
  53. package/dist/esm/global.js +0 -1
  54. package/dist/esm/index.d.ts +9 -39
  55. package/dist/esm/index.js +6 -31
  56. package/dist/esm/send-commercial-metrics.d.ts +8 -2
  57. package/dist/esm/send-commercial-metrics.js +48 -25
  58. package/dist/esm/targeting/build-page-targeting.d.ts +4 -5
  59. package/dist/esm/targeting/build-page-targeting.js +35 -7
  60. package/dist/esm/targeting/content.d.ts +1 -1
  61. package/dist/esm/targeting/content.js +1 -1
  62. package/dist/esm/targeting/personalised.d.ts +2 -3
  63. package/dist/esm/targeting/personalised.js +3 -3
  64. package/dist/esm/targeting/pick-targeting-values.d.ts +1 -1
  65. package/dist/esm/targeting/session.d.ts +2 -2
  66. package/dist/esm/targeting/shared.d.ts +31 -20
  67. package/dist/esm/targeting/shared.js +0 -30
  68. package/dist/esm/targeting/teads-eligibility.d.ts +2 -0
  69. package/dist/esm/targeting/teads-eligibility.js +17 -0
  70. package/dist/esm/targeting/types.d.ts +6 -0
  71. package/dist/esm/targeting/types.js +0 -0
  72. package/dist/esm/targeting/viewport.d.ts +1 -1
  73. package/dist/esm/targeting/youtube-ima.d.ts +4 -3
  74. package/dist/esm/targeting/youtube-ima.js +7 -4
  75. package/dist/esm/types.d.ts +403 -63
  76. package/dist/esm/types.js +11 -1
  77. package/package.json +64 -83
  78. package/dist/cjs/__vendor/a9-apstag.d.ts +0 -1
  79. package/dist/cjs/__vendor/a9-apstag.js +0 -34
  80. package/dist/cjs/__vendor/ipsos-mori.d.ts +0 -1
  81. package/dist/cjs/__vendor/ipsos-mori.js +0 -18
  82. package/dist/cjs/__vendor/launchpad.d.ts +0 -1
  83. package/dist/cjs/__vendor/launchpad.js +0 -25
  84. package/dist/cjs/__vendor/pubmatic.d.ts +0 -1
  85. package/dist/cjs/__vendor/pubmatic.js +0 -49
  86. package/dist/cjs/__vendor/twitter-script.d.ts +0 -1
  87. package/dist/cjs/__vendor/twitter-script.js +0 -26
  88. package/dist/cjs/create-ad-slot.d.ts +0 -17
  89. package/dist/cjs/create-ad-slot.js +0 -107
  90. package/dist/cjs/google-analytics.d.ts +0 -1
  91. package/dist/cjs/google-analytics.js +0 -14
  92. package/dist/cjs/lib/ab-localstorage.d.ts +0 -2
  93. package/dist/cjs/lib/ab-localstorage.js +0 -14
  94. package/dist/cjs/lib/breakpoint.d.ts +0 -4
  95. package/dist/cjs/lib/breakpoint.js +0 -5
  96. package/dist/cjs/lib/can-use-dom.d.ts +0 -2
  97. package/dist/cjs/lib/can-use-dom.js +0 -9
  98. package/dist/cjs/lib/construct-query.d.ts +0 -3
  99. package/dist/cjs/lib/construct-query.js +0 -12
  100. package/dist/cjs/messenger.d.ts +0 -97
  101. package/dist/cjs/messenger.js +0 -281
  102. package/dist/cjs/targeting/build-page-targeting-consentless.d.ts +0 -15
  103. package/dist/cjs/targeting/build-page-targeting-consentless.js +0 -46
  104. package/dist/cjs/targeting/youtube.d.ts +0 -13
  105. package/dist/cjs/targeting/youtube.js +0 -64
  106. package/dist/cjs/third-party-tags/ias.d.ts +0 -7
  107. package/dist/cjs/third-party-tags/ias.js +0 -14
  108. package/dist/cjs/third-party-tags/inizio.d.ts +0 -13
  109. package/dist/cjs/third-party-tags/inizio.js +0 -39
  110. package/dist/cjs/third-party-tags/permutive.d.ts +0 -6
  111. package/dist/cjs/third-party-tags/permutive.js +0 -13
  112. package/dist/cjs/third-party-tags/remarketing.d.ts +0 -7
  113. package/dist/cjs/third-party-tags/remarketing.js +0 -22
  114. package/dist/cjs/third-party-tags/twitter-uwt.d.ts +0 -7
  115. package/dist/cjs/third-party-tags/twitter-uwt.js +0 -15
  116. package/dist/cjs/track-gpc-signal.d.ts +0 -7
  117. package/dist/cjs/track-gpc-signal.js +0 -17
  118. package/dist/cjs/track-labs-container.d.ts +0 -7
  119. package/dist/cjs/track-labs-container.js +0 -35
  120. package/dist/cjs/track-scroll-depth.d.ts +0 -8
  121. package/dist/cjs/track-scroll-depth.js +0 -41
  122. package/dist/esm/__vendor/a9-apstag.d.ts +0 -1
  123. package/dist/esm/__vendor/a9-apstag.js +0 -30
  124. package/dist/esm/__vendor/ipsos-mori.d.ts +0 -1
  125. package/dist/esm/__vendor/ipsos-mori.js +0 -14
  126. package/dist/esm/__vendor/launchpad.d.ts +0 -1
  127. package/dist/esm/__vendor/launchpad.js +0 -21
  128. package/dist/esm/__vendor/pubmatic.d.ts +0 -1
  129. package/dist/esm/__vendor/pubmatic.js +0 -45
  130. package/dist/esm/__vendor/twitter-script.d.ts +0 -1
  131. package/dist/esm/__vendor/twitter-script.js +0 -22
  132. package/dist/esm/create-ad-slot.d.ts +0 -17
  133. package/dist/esm/create-ad-slot.js +0 -103
  134. package/dist/esm/google-analytics.d.ts +0 -1
  135. package/dist/esm/google-analytics.js +0 -10
  136. package/dist/esm/lib/ab-localstorage.d.ts +0 -2
  137. package/dist/esm/lib/ab-localstorage.js +0 -10
  138. package/dist/esm/lib/breakpoint.d.ts +0 -4
  139. package/dist/esm/lib/breakpoint.js +0 -2
  140. package/dist/esm/lib/can-use-dom.d.ts +0 -2
  141. package/dist/esm/lib/can-use-dom.js +0 -6
  142. package/dist/esm/lib/construct-query.d.ts +0 -3
  143. package/dist/esm/lib/construct-query.js +0 -9
  144. package/dist/esm/messenger.d.ts +0 -97
  145. package/dist/esm/messenger.js +0 -274
  146. package/dist/esm/targeting/build-page-targeting-consentless.d.ts +0 -15
  147. package/dist/esm/targeting/build-page-targeting-consentless.js +0 -43
  148. package/dist/esm/targeting/youtube.d.ts +0 -13
  149. package/dist/esm/targeting/youtube.js +0 -60
  150. package/dist/esm/third-party-tags/ias.d.ts +0 -7
  151. package/dist/esm/third-party-tags/ias.js +0 -10
  152. package/dist/esm/third-party-tags/inizio.d.ts +0 -13
  153. package/dist/esm/third-party-tags/inizio.js +0 -35
  154. package/dist/esm/third-party-tags/permutive.d.ts +0 -6
  155. package/dist/esm/third-party-tags/permutive.js +0 -9
  156. package/dist/esm/third-party-tags/remarketing.d.ts +0 -7
  157. package/dist/esm/third-party-tags/remarketing.js +0 -18
  158. package/dist/esm/third-party-tags/twitter-uwt.d.ts +0 -7
  159. package/dist/esm/third-party-tags/twitter-uwt.js +0 -11
  160. package/dist/esm/track-gpc-signal.d.ts +0 -7
  161. package/dist/esm/track-gpc-signal.js +0 -14
  162. package/dist/esm/track-labs-container.d.ts +0 -7
  163. package/dist/esm/track-labs-container.js +0 -32
  164. package/dist/esm/track-scroll-depth.d.ts +0 -8
  165. package/dist/esm/track-scroll-depth.js +0 -38
  166. /package/dist/cjs/constants/{adLabelHeight.d.ts → ad-label-height.d.ts} +0 -0
  167. /package/dist/cjs/constants/{adLabelHeight.js → ad-label-height.js} +0 -0
  168. /package/dist/cjs/{lib → geo}/get-locale.d.ts +0 -0
  169. /package/dist/cjs/{lib → geo}/get-locale.js +0 -0
  170. /package/dist/esm/constants/{adLabelHeight.d.ts → ad-label-height.d.ts} +0 -0
  171. /package/dist/esm/constants/{adLabelHeight.js → ad-label-height.js} +0 -0
  172. /package/dist/esm/{lib → geo}/get-locale.d.ts +0 -0
  173. /package/dist/esm/{lib → geo}/get-locale.js +0 -0
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAdSize = exports.slotSizeMappings = exports.getAdSize = exports.outstreamSizes = exports.standardAdSizes = exports.adSizes = exports._ = void 0;
3
+ exports.findAppliedSizesForBreakpoint = exports.createAdSize = exports.slotSizeMappings = exports.getAdSize = exports.outstreamSizes = exports.standardAdSizes = exports.adSizes = exports.AdSize = exports._ = void 0;
4
+ const breakpoint_1 = require("./breakpoint");
4
5
  /**
5
6
  * Store ad sizes in a way that is compatible with google-tag but also accessible via
6
7
  * more semantic `width`/`height` properties and keep things readonly.
@@ -19,6 +20,8 @@ exports.createAdSize = exports.slotSizeMappings = exports.getAdSize = exports.ou
19
20
  *
20
21
  */
21
22
  class AdSize extends Array {
23
+ [0];
24
+ [1];
22
25
  constructor([width, height]) {
23
26
  super();
24
27
  this[0] = width;
@@ -39,7 +42,8 @@ class AdSize extends Array {
39
42
  const isEmpty = this.width === 2 && this.height === 2;
40
43
  const isFluid = this.toString() === 'fluid';
41
44
  const isMerch = this.width === 88;
42
- return isOutOfPage || isEmpty || isFluid || isMerch;
45
+ const isSponsorLogo = this.width === 3 && this.height === 3;
46
+ return isOutOfPage || isEmpty || isFluid || isMerch || isSponsorLogo;
43
47
  }
44
48
  get width() {
45
49
  return this[0];
@@ -48,6 +52,7 @@ class AdSize extends Array {
48
52
  return this[1];
49
53
  }
50
54
  }
55
+ exports.AdSize = AdSize;
51
56
  const createAdSize = (width, height) => {
52
57
  return new AdSize([width, height]);
53
58
  };
@@ -85,6 +90,7 @@ const proprietaryAdSizes = {
85
90
  fluid: createAdSize(0, 0),
86
91
  googleCard: createAdSize(300, 274),
87
92
  outOfPage: createAdSize(1, 1),
93
+ pubmaticInterscroller: createAdSize(371, 660), // pubmatic only mobile size
88
94
  };
89
95
  /**
90
96
  * Ad sizes associated with in-house formats
@@ -92,10 +98,15 @@ const proprietaryAdSizes = {
92
98
  const guardianProprietaryAdSizes = {
93
99
  empty: createAdSize(2, 2),
94
100
  fabric: createAdSize(88, 71),
95
- inlineMerchandising: createAdSize(88, 85),
96
101
  merchandising: createAdSize(88, 88),
97
102
  merchandisingHigh: createAdSize(88, 87),
98
103
  merchandisingHighAdFeature: createAdSize(88, 89),
104
+ /**
105
+ * This is a proxy size (not the true size of the rendered creative)
106
+ * that can be used to ensure that no other high priority line items
107
+ * fill a certain slot.
108
+ */
109
+ sponsorLogo: createAdSize(3, 3),
99
110
  };
100
111
  const adSizes = {
101
112
  ...namedStandardAdSizes,
@@ -109,6 +120,16 @@ exports.adSizes = adSizes;
109
120
  * mark: 432b3a46-90c1-4573-90d3-2400b51af8d0
110
121
  * Some of these may or may not need to be synced for with the sizes in ./create-ad-slot.ts
111
122
  * these were originally from DCR, create-ad-slot.ts ones were in frontend.
123
+ *
124
+ * Note:
125
+ * If a breakpoint is not defined in a size mapping for a slot, that breakpoint will use the sizes
126
+ * of the next breakpoint down that has a size mapping. For example, if only "mobile" and "phablet" sizes
127
+ * are defined for a slot, all breakpoints larger than "phablet" will use the mapping for "phablet".
128
+ *
129
+ * In another example, if a slot has only "tablet" as a size mapping defined,
130
+ * then "desktop" will use the size mapping for "tablet". "mobile" and "phablet"
131
+ * will have no size mapping. This type of example may be used in cases where
132
+ * we only want the slot to appear on the "tablet" size or greater.
112
133
  **/
113
134
  const slotSizeMappings = {
114
135
  inline: {
@@ -120,14 +141,6 @@ const slotSizeMappings = {
120
141
  adSizes.googleCard,
121
142
  adSizes.fluid,
122
143
  ],
123
- phablet: [
124
- adSizes.outOfPage,
125
- adSizes.empty,
126
- adSizes.outstreamMobile,
127
- adSizes.mpu,
128
- adSizes.googleCard,
129
- adSizes.fluid,
130
- ],
131
144
  desktop: [
132
145
  adSizes.outOfPage,
133
146
  adSizes.empty,
@@ -155,14 +168,6 @@ const slotSizeMappings = {
155
168
  adSizes.googleCard,
156
169
  adSizes.fluid,
157
170
  ],
158
- phablet: [
159
- adSizes.outOfPage,
160
- adSizes.empty,
161
- adSizes.outstreamMobile,
162
- adSizes.mpu,
163
- adSizes.googleCard,
164
- adSizes.fluid,
165
- ],
166
171
  desktop: [
167
172
  adSizes.outOfPage,
168
173
  adSizes.empty,
@@ -172,7 +177,8 @@ const slotSizeMappings = {
172
177
  ],
173
178
  },
174
179
  'comments-expanded': {
175
- mobile: [
180
+ mobile: [adSizes.mpu, adSizes.empty],
181
+ desktop: [
176
182
  adSizes.outOfPage,
177
183
  adSizes.empty,
178
184
  adSizes.mpu,
@@ -210,11 +216,12 @@ const slotSizeMappings = {
210
216
  ],
211
217
  },
212
218
  'fronts-banner': {
219
+ tablet: [adSizes.empty, adSizes.leaderboard],
213
220
  desktop: [
214
221
  adSizes.outOfPage,
215
222
  adSizes.empty,
216
223
  adSizes.billboard,
217
- adSizes.fabric,
224
+ adSizes.merchandisingHigh,
218
225
  adSizes.fluid,
219
226
  ],
220
227
  },
@@ -241,7 +248,6 @@ const slotSizeMappings = {
241
248
  adSizes.mpu,
242
249
  adSizes.googleCard,
243
250
  adSizes.halfPage,
244
- adSizes.leaderboard,
245
251
  adSizes.fluid,
246
252
  ],
247
253
  desktop: [
@@ -253,24 +259,32 @@ const slotSizeMappings = {
253
259
  adSizes.fluid,
254
260
  ],
255
261
  },
256
- im: {
262
+ 'liveblog-top': {
263
+ mobile: [adSizes.outOfPage, adSizes.empty, adSizes.mpu, adSizes.fluid],
264
+ tablet: [],
265
+ desktop: [],
266
+ },
267
+ 'merchandising-high': {
257
268
  mobile: [
258
269
  adSizes.outOfPage,
259
270
  adSizes.empty,
260
- adSizes.inlineMerchandising,
271
+ adSizes.merchandisingHigh,
261
272
  adSizes.fluid,
273
+ adSizes.mpu,
262
274
  ],
263
- },
264
- 'merchandising-high': {
265
- mobile: [
275
+ tablet: [
266
276
  adSizes.outOfPage,
267
277
  adSizes.empty,
268
278
  adSizes.merchandisingHigh,
269
279
  adSizes.fluid,
270
280
  ],
271
- },
272
- 'merchandising-high-lucky': {
273
- mobile: [adSizes.outOfPage, adSizes.empty, adSizes.fluid],
281
+ desktop: [
282
+ adSizes.outOfPage,
283
+ adSizes.empty,
284
+ adSizes.merchandisingHigh,
285
+ adSizes.fluid,
286
+ adSizes.billboard,
287
+ ],
274
288
  },
275
289
  merchandising: {
276
290
  mobile: [
@@ -278,6 +292,20 @@ const slotSizeMappings = {
278
292
  adSizes.empty,
279
293
  adSizes.merchandising,
280
294
  adSizes.fluid,
295
+ adSizes.mpu,
296
+ ],
297
+ tablet: [
298
+ adSizes.outOfPage,
299
+ adSizes.empty,
300
+ adSizes.merchandising,
301
+ adSizes.fluid,
302
+ ],
303
+ desktop: [
304
+ adSizes.outOfPage,
305
+ adSizes.empty,
306
+ adSizes.merchandising,
307
+ adSizes.fluid,
308
+ adSizes.billboard,
281
309
  ],
282
310
  },
283
311
  survey: {
@@ -286,24 +314,87 @@ const slotSizeMappings = {
286
314
  carrot: {
287
315
  mobile: [adSizes.fluid],
288
316
  },
289
- epic: {
290
- mobile: [adSizes.fluid],
291
- },
292
317
  'mobile-sticky': {
318
+ mobile: [adSizes.mobilesticky, adSizes.empty, createAdSize(300, 50)],
319
+ },
320
+ 'crossword-banner-mobile': {
293
321
  mobile: [adSizes.mobilesticky],
294
322
  },
295
- 'crossword-banner': {
296
- phablet: [adSizes.outOfPage, adSizes.empty, adSizes.leaderboard],
297
- tablet: [adSizes.outOfPage, adSizes.empty, adSizes.leaderboard],
323
+ 'football-right': {
324
+ desktop: [
325
+ adSizes.empty,
326
+ adSizes.mpu,
327
+ adSizes.skyscraper,
328
+ adSizes.halfPage,
329
+ ],
330
+ },
331
+ 'article-end': {
332
+ mobile: [], // Mappings are dynamically added for this slot using additionalSizes
298
333
  },
299
334
  exclusion: {
300
335
  mobile: [adSizes.empty],
301
- phablet: [adSizes.empty],
302
- desktop: [adSizes.empty],
336
+ },
337
+ /**
338
+ * @deprecated Use `slotSizeMappings['sponsor-logo']` instead
339
+ */
340
+ external: {
341
+ mobile: [adSizes.outOfPage, adSizes.empty, adSizes.fluid, adSizes.mpu],
342
+ },
343
+ 'sponsor-logo': {
344
+ mobile: [
345
+ adSizes.outOfPage,
346
+ adSizes.empty,
347
+ adSizes.fluid,
348
+ adSizes.sponsorLogo,
349
+ ],
350
+ },
351
+ interactive: {
352
+ // Mappings are dynamically added for this slot using data attributes
353
+ mobile: [adSizes.outOfPage, adSizes.empty],
354
+ tablet: [adSizes.outOfPage, adSizes.empty],
355
+ desktop: [adSizes.outOfPage, adSizes.empty],
303
356
  },
304
357
  };
305
358
  exports.slotSizeMappings = slotSizeMappings;
306
359
  const getAdSize = (size) => adSizes[size];
307
360
  exports.getAdSize = getAdSize;
361
+ /**
362
+ * Finds the ad sizes that will be used for a breakpoint given a size mapping
363
+ *
364
+ * If ad sizes are defined in the size mapping for the specified breakpoint, we use that.
365
+ * If no sizes are defined for the breakpoint, use the next smallest breakpoint with defined ad sizes.
366
+ * If no smaller breakpoints have defined ad sizes, return an empty array
367
+ *
368
+ * Example:
369
+ * For the following slotSizeMappings:
370
+ * inline: {
371
+ * phablet: [adSizes.mpu],
372
+ * desktop: [adSizes.billboard]
373
+ * }
374
+ * the applied sizes for each breakpoint for the "inline" slot will be:
375
+ * mobile: []
376
+ * phablet: [adSizes.mpu]
377
+ * tablet: [adSizes.mpu]
378
+ * desktop: [adSizes.billboard]
379
+ *
380
+ * See ad-sizes.test.ts for more examples
381
+ */
382
+ const findAppliedSizesForBreakpoint = (sizeMappings, breakpoint) => {
383
+ if (!(0, breakpoint_1.isBreakpoint)(breakpoint)) {
384
+ return [];
385
+ }
386
+ let breakpointIndex = breakpoint_1.breakpoints.findIndex((b) => b === breakpoint);
387
+ while (breakpointIndex >= 0) {
388
+ const breakpointToTry = breakpoint_1.breakpoints[breakpointIndex];
389
+ const sizeMapping = sizeMappings[breakpointToTry];
390
+ if (sizeMapping?.length) {
391
+ return sizeMapping;
392
+ }
393
+ breakpointIndex--;
394
+ }
395
+ // There are no size mappings defined for any size smaller than the breakpoint
396
+ return [];
397
+ };
398
+ exports.findAppliedSizesForBreakpoint = findAppliedSizesForBreakpoint;
308
399
  // Export for testing
309
400
  exports._ = { createAdSize };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Breakpoints ordered from smallest to largest
3
+ */
4
+ declare const breakpoints: readonly ["mobile", "phablet", "tablet", "desktop", "wide"];
5
+ type Breakpoint = (typeof breakpoints)[number];
6
+ declare const isBreakpoint: (s: string) => s is Breakpoint;
7
+ export type { Breakpoint };
8
+ export { breakpoints, isBreakpoint };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isBreakpoint = exports.breakpoints = void 0;
4
+ /**
5
+ * Breakpoints ordered from smallest to largest
6
+ */
7
+ const breakpoints = ['mobile', 'phablet', 'tablet', 'desktop', 'wide'];
8
+ exports.breakpoints = breakpoints;
9
+ const isBreakpoint = (s) => breakpoints.includes(s);
10
+ exports.isBreakpoint = isBreakpoint;
@@ -1,3 +1,3 @@
1
- export { AD_LABEL_HEIGHT } from './adLabelHeight';
1
+ export { AD_LABEL_HEIGHT } from './ad-label-height';
2
2
  export { PREBID_TIMEOUT } from './prebid-timeout';
3
3
  export { TOP_ABOVE_NAV_HEIGHT } from './top-above-nav-height';
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TOP_ABOVE_NAV_HEIGHT = exports.PREBID_TIMEOUT = exports.AD_LABEL_HEIGHT = void 0;
4
- var adLabelHeight_1 = require("./adLabelHeight");
5
- Object.defineProperty(exports, "AD_LABEL_HEIGHT", { enumerable: true, get: function () { return adLabelHeight_1.AD_LABEL_HEIGHT; } });
4
+ var ad_label_height_1 = require("./ad-label-height");
5
+ Object.defineProperty(exports, "AD_LABEL_HEIGHT", { enumerable: true, get: function () { return ad_label_height_1.AD_LABEL_HEIGHT; } });
6
6
  var prebid_timeout_1 = require("./prebid-timeout");
7
7
  Object.defineProperty(exports, "PREBID_TIMEOUT", { enumerable: true, get: function () { return prebid_timeout_1.PREBID_TIMEOUT; } });
8
8
  var top_above_nav_height_1 = require("./top-above-nav-height");
@@ -8,7 +8,7 @@ https://github.com/wmcmurray/just-detect-adblock/blob/master/src/helpers.js
8
8
  /*istanbul ignore file -- adElementBlocked can't be tested without patching each of the properties of
9
9
  HTMLElement.prototype that it accesses, defeating the purpose of the test! */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.isAdBlockInUse = void 0;
11
+ exports.isAdBlockInUse = isAdBlockInUse;
12
12
  let adBlockInUse = undefined;
13
13
  function adElementBlocked(ad) {
14
14
  if (ad.offsetParent === null ||
@@ -59,4 +59,3 @@ function isAdBlockInUse() {
59
59
  });
60
60
  });
61
61
  }
62
- exports.isAdBlockInUse = isAdBlockInUse;
@@ -1,51 +1,32 @@
1
1
  import type { ConnectionType } from './types';
2
- declare class Event {
3
- name: string;
4
- ts: DOMHighResTimeStamp;
5
- constructor(name: string, mark: PerformanceEntry);
6
- }
7
- interface GALogEvent {
8
- timingVariable: string;
9
- timingLabel?: string;
10
- }
11
- interface GAConfig {
12
- logEvents: GALogEvent[];
13
- }
14
- interface SlotEventStatus {
15
- prebidStart: boolean;
16
- prebidEnd: boolean;
17
- slotInitialised: boolean;
18
- slotReady: boolean;
19
- adOnPage: boolean;
20
- }
21
- interface PageEventStatus {
22
- commercialStart: boolean;
23
- commercialExtraModulesLoaded: boolean;
24
- commercialBaseModulesLoaded: boolean;
25
- commercialModulesLoaded: boolean;
26
- }
2
+ declare const supportsPerformanceAPI: () => boolean;
27
3
  interface EventTimerProperties {
28
4
  type?: ConnectionType;
29
5
  downlink?: number;
30
6
  effectiveType?: string;
31
7
  adSlotsInline?: number;
32
8
  adSlotsTotal?: number;
9
+ /** the height of the page / the viewport height */
33
10
  pageHeightVH?: number;
34
11
  gpcSignal?: number;
12
+ /** distance in percentage of viewport height at which ads are lazy loaded */
35
13
  lazyLoadMarginPercent?: number;
36
14
  hasLabsContainer?: boolean;
37
15
  labsUrl?: string;
16
+ /** Record whether we've detected an ad blocker. This is intentionally
17
+ * distinct from the property we pass into commercial metrics, and in the
18
+ * future _could_ be removed in favour of this property */
19
+ detectedAdBlocker?: boolean;
20
+ /** Record whether we've shown the adblock as message */
21
+ didDisplayAdBlockAsk?: boolean;
22
+ /** creative ID of a video interscroller for video reporting metrics */
23
+ videoInterscrollerCreativeId?: number | null | undefined;
24
+ /** percentage progress of video interscroller on page unload */
25
+ videoInterscrollerPercentageProgress?: number;
38
26
  }
39
27
  declare class EventTimer {
40
- private _events;
41
- private static _externallyDefinedEventNames;
42
- startTS: DOMHighResTimeStamp;
43
- triggers: {
44
- first: SlotEventStatus;
45
- 'top-above-nav': SlotEventStatus;
46
- page: PageEventStatus;
47
- };
48
- gaConfig: GAConfig;
28
+ private _marks;
29
+ private _measures;
49
30
  properties: EventTimerProperties;
50
31
  /**
51
32
  * Initialise the EventTimer class on page.
@@ -53,7 +34,7 @@ declare class EventTimer {
53
34
  * to window.guardian.commercialTimer. If it's been previously
54
35
  * initialised and bound it returns the original instance
55
36
  * Note: We save to window.guardian.commercialTimer because
56
- * different bundles (DCR / DCP) can use commercial core, and we want
37
+ * different bundles (DCR / DCP) can use commercial, and we want
57
38
  * all timer events saved to a single instance per-page
58
39
  * @returns {EventTimer} Instance of EventTimer
59
40
  */
@@ -64,28 +45,59 @@ declare class EventTimer {
64
45
  */
65
46
  static get(): EventTimer;
66
47
  /**
67
- * Returns all commercial timers. CMP-related timers are not tracked
68
- * by EventTimer so they need to be concatenated to EventTimer's private events array.
48
+ * These are marks that are not triggered by commercial but we are interested in
49
+ * tracking their performance. For example, CMP-related events.
50
+ **/
51
+ private get _externalMarks();
52
+ /**
53
+ * Returns all performance marks that should be saved as commercial metrics.
69
54
  */
70
- get events(): Event[];
55
+ get marks(): {
56
+ name: string;
57
+ ts: number;
58
+ }[];
59
+ /**
60
+ * Returns all performance measures that should be saved as commercial metrics.
61
+ */
62
+ get measures(): {
63
+ name: string;
64
+ duration: number;
65
+ }[];
71
66
  private constructor();
72
67
  /**
73
- * Adds an event timer property
68
+ * Adds a non timer measurement
74
69
  *
75
70
  * @param {string} name - the property's name
76
71
  * @param value - the property's value
77
72
  */
78
73
  setProperty<T extends keyof EventTimerProperties>(name: T, value: EventTimerProperties[T]): void;
79
74
  /**
80
- * Creates a new performance mark
81
- * For slot events also ensures each TYPE of event event is marked only once for 'first'
82
- * (the first time that event is triggered for ANY slot) and once for topAboveNav
75
+ * Creates a new performance mark, and if the mark ends with 'End' it will
76
+ * create a performance measure between the start and end marks.
77
+ *
78
+ * Marks can be triggered multiple times, but we only save the first
79
+ * instance of a mark, as things like ad refreshes can trigger the same mark.
83
80
  *
84
- * @param {string} eventName - The short name applied to the mark
85
- * @param {origin} [origin=page] - Either 'page' (default) or the name of the slot
81
+ * More info on the performance API:
82
+ * https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark
83
+ * https://developer.mozilla.org/en-US/docs/Web/API/Performance/measure
84
+ *
85
+ * @todo more strict typing for eventName and origin
86
+ * @param eventName The short name applied to the mark
87
+ * @param origin - Either 'page' (default) or the name of the slot
86
88
  */
87
- trigger(eventName: string, origin?: string): void;
88
- private mark;
89
- private trackInGA;
89
+ mark(eventName: string, origin?: string): void;
90
+ /**
91
+ * Creates a performance measure given the name of the end marks.
92
+ * The start mark is inferred from the end mark.
93
+ *
94
+ * @param endMark - The name of the mark that ends the measure
95
+ **/
96
+ private measure;
90
97
  }
91
- export { EventTimer };
98
+ declare const _: {
99
+ slotMarks: readonly ["slotReady", "adRenderStart", "prebidStart", "adOnPage", "viewable"];
100
+ slotMeasures: readonly ["adRender", "defineSlot", "prepareSlot", "prebid", "fetchAd"];
101
+ trackedSlots: readonly ["top-above-nav", "inline1", "inline2", "fronts-banner-1", "fronts-banner-2"];
102
+ };
103
+ export { EventTimer, _, supportsPerformanceAPI };