@guardian/commercial-core 7.1.0 → 27.0.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 +399 -63
  39. package/dist/cjs/types.js +10 -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 +399 -63
  76. package/dist/esm/types.js +10 -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,3 +1,4 @@
1
+ import { breakpoints, isBreakpoint } from './breakpoint';
1
2
  /**
2
3
  * Store ad sizes in a way that is compatible with google-tag but also accessible via
3
4
  * more semantic `width`/`height` properties and keep things readonly.
@@ -16,6 +17,8 @@
16
17
  *
17
18
  */
18
19
  class AdSize extends Array {
20
+ [0];
21
+ [1];
19
22
  constructor([width, height]) {
20
23
  super();
21
24
  this[0] = width;
@@ -36,7 +39,8 @@ class AdSize extends Array {
36
39
  const isEmpty = this.width === 2 && this.height === 2;
37
40
  const isFluid = this.toString() === 'fluid';
38
41
  const isMerch = this.width === 88;
39
- return isOutOfPage || isEmpty || isFluid || isMerch;
42
+ const isSponsorLogo = this.width === 3 && this.height === 3;
43
+ return isOutOfPage || isEmpty || isFluid || isMerch || isSponsorLogo;
40
44
  }
41
45
  get width() {
42
46
  return this[0];
@@ -79,6 +83,7 @@ const proprietaryAdSizes = {
79
83
  fluid: createAdSize(0, 0),
80
84
  googleCard: createAdSize(300, 274),
81
85
  outOfPage: createAdSize(1, 1),
86
+ pubmaticInterscroller: createAdSize(371, 660), // pubmatic only mobile size
82
87
  };
83
88
  /**
84
89
  * Ad sizes associated with in-house formats
@@ -86,10 +91,15 @@ const proprietaryAdSizes = {
86
91
  const guardianProprietaryAdSizes = {
87
92
  empty: createAdSize(2, 2),
88
93
  fabric: createAdSize(88, 71),
89
- inlineMerchandising: createAdSize(88, 85),
90
94
  merchandising: createAdSize(88, 88),
91
95
  merchandisingHigh: createAdSize(88, 87),
92
96
  merchandisingHighAdFeature: createAdSize(88, 89),
97
+ /**
98
+ * This is a proxy size (not the true size of the rendered creative)
99
+ * that can be used to ensure that no other high priority line items
100
+ * fill a certain slot.
101
+ */
102
+ sponsorLogo: createAdSize(3, 3),
93
103
  };
94
104
  const adSizes = {
95
105
  ...namedStandardAdSizes,
@@ -102,6 +112,16 @@ const adSizes = {
102
112
  * mark: 432b3a46-90c1-4573-90d3-2400b51af8d0
103
113
  * Some of these may or may not need to be synced for with the sizes in ./create-ad-slot.ts
104
114
  * these were originally from DCR, create-ad-slot.ts ones were in frontend.
115
+ *
116
+ * Note:
117
+ * If a breakpoint is not defined in a size mapping for a slot, that breakpoint will use the sizes
118
+ * of the next breakpoint down that has a size mapping. For example, if only "mobile" and "phablet" sizes
119
+ * are defined for a slot, all breakpoints larger than "phablet" will use the mapping for "phablet".
120
+ *
121
+ * In another example, if a slot has only "tablet" as a size mapping defined,
122
+ * then "desktop" will use the size mapping for "tablet". "mobile" and "phablet"
123
+ * will have no size mapping. This type of example may be used in cases where
124
+ * we only want the slot to appear on the "tablet" size or greater.
105
125
  **/
106
126
  const slotSizeMappings = {
107
127
  inline: {
@@ -113,14 +133,6 @@ const slotSizeMappings = {
113
133
  adSizes.googleCard,
114
134
  adSizes.fluid,
115
135
  ],
116
- phablet: [
117
- adSizes.outOfPage,
118
- adSizes.empty,
119
- adSizes.outstreamMobile,
120
- adSizes.mpu,
121
- adSizes.googleCard,
122
- adSizes.fluid,
123
- ],
124
136
  desktop: [
125
137
  adSizes.outOfPage,
126
138
  adSizes.empty,
@@ -148,14 +160,6 @@ const slotSizeMappings = {
148
160
  adSizes.googleCard,
149
161
  adSizes.fluid,
150
162
  ],
151
- phablet: [
152
- adSizes.outOfPage,
153
- adSizes.empty,
154
- adSizes.outstreamMobile,
155
- adSizes.mpu,
156
- adSizes.googleCard,
157
- adSizes.fluid,
158
- ],
159
163
  desktop: [
160
164
  adSizes.outOfPage,
161
165
  adSizes.empty,
@@ -165,7 +169,8 @@ const slotSizeMappings = {
165
169
  ],
166
170
  },
167
171
  'comments-expanded': {
168
- mobile: [
172
+ mobile: [adSizes.mpu, adSizes.empty],
173
+ desktop: [
169
174
  adSizes.outOfPage,
170
175
  adSizes.empty,
171
176
  adSizes.mpu,
@@ -203,11 +208,12 @@ const slotSizeMappings = {
203
208
  ],
204
209
  },
205
210
  'fronts-banner': {
211
+ tablet: [adSizes.empty, adSizes.leaderboard],
206
212
  desktop: [
207
213
  adSizes.outOfPage,
208
214
  adSizes.empty,
209
215
  adSizes.billboard,
210
- adSizes.fabric,
216
+ adSizes.merchandisingHigh,
211
217
  adSizes.fluid,
212
218
  ],
213
219
  },
@@ -234,7 +240,6 @@ const slotSizeMappings = {
234
240
  adSizes.mpu,
235
241
  adSizes.googleCard,
236
242
  adSizes.halfPage,
237
- adSizes.leaderboard,
238
243
  adSizes.fluid,
239
244
  ],
240
245
  desktop: [
@@ -246,24 +251,32 @@ const slotSizeMappings = {
246
251
  adSizes.fluid,
247
252
  ],
248
253
  },
249
- im: {
254
+ 'liveblog-top': {
255
+ mobile: [adSizes.outOfPage, adSizes.empty, adSizes.mpu, adSizes.fluid],
256
+ tablet: [],
257
+ desktop: [],
258
+ },
259
+ 'merchandising-high': {
250
260
  mobile: [
251
261
  adSizes.outOfPage,
252
262
  adSizes.empty,
253
- adSizes.inlineMerchandising,
263
+ adSizes.merchandisingHigh,
254
264
  adSizes.fluid,
265
+ adSizes.mpu,
255
266
  ],
256
- },
257
- 'merchandising-high': {
258
- mobile: [
267
+ tablet: [
259
268
  adSizes.outOfPage,
260
269
  adSizes.empty,
261
270
  adSizes.merchandisingHigh,
262
271
  adSizes.fluid,
263
272
  ],
264
- },
265
- 'merchandising-high-lucky': {
266
- mobile: [adSizes.outOfPage, adSizes.empty, adSizes.fluid],
273
+ desktop: [
274
+ adSizes.outOfPage,
275
+ adSizes.empty,
276
+ adSizes.merchandisingHigh,
277
+ adSizes.fluid,
278
+ adSizes.billboard,
279
+ ],
267
280
  },
268
281
  merchandising: {
269
282
  mobile: [
@@ -271,6 +284,20 @@ const slotSizeMappings = {
271
284
  adSizes.empty,
272
285
  adSizes.merchandising,
273
286
  adSizes.fluid,
287
+ adSizes.mpu,
288
+ ],
289
+ tablet: [
290
+ adSizes.outOfPage,
291
+ adSizes.empty,
292
+ adSizes.merchandising,
293
+ adSizes.fluid,
294
+ ],
295
+ desktop: [
296
+ adSizes.outOfPage,
297
+ adSizes.empty,
298
+ adSizes.merchandising,
299
+ adSizes.fluid,
300
+ adSizes.billboard,
274
301
  ],
275
302
  },
276
303
  survey: {
@@ -279,23 +306,85 @@ const slotSizeMappings = {
279
306
  carrot: {
280
307
  mobile: [adSizes.fluid],
281
308
  },
282
- epic: {
283
- mobile: [adSizes.fluid],
284
- },
285
309
  'mobile-sticky': {
310
+ mobile: [adSizes.mobilesticky, adSizes.empty, createAdSize(300, 50)],
311
+ },
312
+ 'crossword-banner-mobile': {
286
313
  mobile: [adSizes.mobilesticky],
287
314
  },
288
- 'crossword-banner': {
289
- phablet: [adSizes.outOfPage, adSizes.empty, adSizes.leaderboard],
290
- tablet: [adSizes.outOfPage, adSizes.empty, adSizes.leaderboard],
315
+ 'football-right': {
316
+ desktop: [
317
+ adSizes.empty,
318
+ adSizes.mpu,
319
+ adSizes.skyscraper,
320
+ adSizes.halfPage,
321
+ ],
322
+ },
323
+ 'article-end': {
324
+ mobile: [], // Mappings are dynamically added for this slot using additionalSizes
291
325
  },
292
326
  exclusion: {
293
327
  mobile: [adSizes.empty],
294
- phablet: [adSizes.empty],
295
- desktop: [adSizes.empty],
328
+ },
329
+ /**
330
+ * @deprecated Use `slotSizeMappings['sponsor-logo']` instead
331
+ */
332
+ external: {
333
+ mobile: [adSizes.outOfPage, adSizes.empty, adSizes.fluid, adSizes.mpu],
334
+ },
335
+ 'sponsor-logo': {
336
+ mobile: [
337
+ adSizes.outOfPage,
338
+ adSizes.empty,
339
+ adSizes.fluid,
340
+ adSizes.sponsorLogo,
341
+ ],
342
+ },
343
+ interactive: {
344
+ // Mappings are dynamically added for this slot using data attributes
345
+ mobile: [adSizes.outOfPage, adSizes.empty],
346
+ tablet: [adSizes.outOfPage, adSizes.empty],
347
+ desktop: [adSizes.outOfPage, adSizes.empty],
296
348
  },
297
349
  };
298
350
  const getAdSize = (size) => adSizes[size];
351
+ /**
352
+ * Finds the ad sizes that will be used for a breakpoint given a size mapping
353
+ *
354
+ * If ad sizes are defined in the size mapping for the specified breakpoint, we use that.
355
+ * If no sizes are defined for the breakpoint, use the next smallest breakpoint with defined ad sizes.
356
+ * If no smaller breakpoints have defined ad sizes, return an empty array
357
+ *
358
+ * Example:
359
+ * For the following slotSizeMappings:
360
+ * inline: {
361
+ * phablet: [adSizes.mpu],
362
+ * desktop: [adSizes.billboard]
363
+ * }
364
+ * the applied sizes for each breakpoint for the "inline" slot will be:
365
+ * mobile: []
366
+ * phablet: [adSizes.mpu]
367
+ * tablet: [adSizes.mpu]
368
+ * desktop: [adSizes.billboard]
369
+ *
370
+ * See ad-sizes.test.ts for more examples
371
+ */
372
+ const findAppliedSizesForBreakpoint = (sizeMappings, breakpoint) => {
373
+ if (!isBreakpoint(breakpoint)) {
374
+ return [];
375
+ }
376
+ let breakpointIndex = breakpoints.findIndex((b) => b === breakpoint);
377
+ while (breakpointIndex >= 0) {
378
+ const breakpointToTry = breakpoints[breakpointIndex];
379
+ const sizeMapping = sizeMappings[breakpointToTry];
380
+ if (sizeMapping?.length) {
381
+ return sizeMapping;
382
+ }
383
+ breakpointIndex--;
384
+ }
385
+ // There are no size mappings defined for any size smaller than the breakpoint
386
+ return [];
387
+ };
299
388
  // Export for testing
300
389
  export const _ = { createAdSize };
301
- export { adSizes, standardAdSizes, outstreamSizes, getAdSize, slotSizeMappings, createAdSize, };
390
+ export { AdSize, adSizes, standardAdSizes, outstreamSizes, getAdSize, slotSizeMappings, createAdSize, findAppliedSizesForBreakpoint, };
@@ -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,6 @@
1
+ /**
2
+ * Breakpoints ordered from smallest to largest
3
+ */
4
+ const breakpoints = ['mobile', 'phablet', 'tablet', 'desktop', 'wide'];
5
+ const isBreakpoint = (s) => breakpoints.includes(s);
6
+ export { breakpoints, 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,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,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 };