@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,281 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._ = exports.init = exports.unregister = exports.registerPersistentListener = exports.register = void 0;
4
- const post_message_1 = require("./messenger/post-message");
5
- const LISTENERS = {};
6
- let REGISTERED_LISTENERS = 0;
7
- let reportError = () => {
8
- // not set yet
9
- };
10
- const error405 = {
11
- code: 405,
12
- message: 'Service %% not implemented',
13
- };
14
- const error500 = {
15
- code: 500,
16
- message: 'Internal server error\n\n%%',
17
- };
18
- /**
19
- * Determine if an unknown payload has the shape of a programmatic message
20
- *
21
- * @param payload The unknown message payload
22
- */
23
- const isProgrammaticMessage = (payload) => {
24
- const payloadToCheck = payload;
25
- return (payloadToCheck.type === 'set-ad-height' &&
26
- ('id' in payloadToCheck.value || 'slotId' in payloadToCheck.value) &&
27
- 'height' in payloadToCheck.value);
28
- };
29
- /**
30
- * Convert a legacy programmatic message to a standard message
31
- *
32
- * Note that this only applies to specific resize programmatic messages
33
- * (these include specific width and height values)
34
- */
35
- const toStandardMessage = (payload) => ({
36
- id: 'aaaa0000-bb11-cc22-dd33-eeeeee444444',
37
- type: 'resize',
38
- iframeId: payload.value.id,
39
- slotId: payload.value.slotId,
40
- value: {
41
- height: payload.value.height,
42
- width: payload.value.width,
43
- },
44
- });
45
- /**
46
- * Retrieve a reference to the calling iFrame
47
- *
48
- * Attempts the following strategies to find the correct iframe:
49
- * - using the slotId from the incoming message
50
- * - using the iframeId from the incoming message
51
- * - checking message event.source (i.e. window) against all page level iframe contentWindows
52
- *
53
- * Listeners can then use the iFrame to determine the slot making the postMessage call
54
- */
55
- const getIframe = (message, messageEventSource) => {
56
- if (message.slotId) {
57
- const container = document.getElementById(`dfp-ad--${message.slotId}`);
58
- return container?.querySelector('iframe') ?? undefined;
59
- }
60
- else if (message.iframeId) {
61
- const el = document.getElementById(message.iframeId);
62
- return el instanceof HTMLIFrameElement ? el : undefined;
63
- }
64
- else if (messageEventSource) {
65
- const iframes = document.querySelectorAll('iframe');
66
- return Array.from(iframes).find((iframe) => iframe.contentWindow === messageEventSource);
67
- }
68
- };
69
- // Regex for testing validity of message ids
70
- const validMessageRegex = /^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$/;
71
- /**
72
- * Narrow an `unknown` payload to the standard message format
73
- *
74
- * Until DFP provides a way for us to identify with 100% certainty our
75
- * in-house creatives, we are left with doing some basic tests
76
- * such as validating the anatomy of the payload and whitelisting
77
- * event type
78
- */
79
- const isValidPayload = (payload) => {
80
- const payloadToCheck = payload;
81
- return ('type' in payloadToCheck &&
82
- 'value' in payloadToCheck &&
83
- 'id' in payloadToCheck &&
84
- payloadToCheck.type in LISTENERS &&
85
- validMessageRegex.test(payloadToCheck.id));
86
- };
87
- /**
88
- * Cheap string formatting function
89
- *
90
- * @param error An object `{ code, message }`. `message` is a string where successive
91
- * occurrences of %% will be replaced by the following arguments
92
- * @param args Arguments that will replace %%
93
- *
94
- * @example
95
- * formatError({ message: "%%, you are so %%" }, "Regis", "lovely")
96
- * => { message: "Regis, you are so lovely" }
97
- */
98
- const formatError = (error, ...args) => args.reduce((e, arg) => {
99
- e.message = e.message.replace('%%', arg);
100
- return e;
101
- }, error);
102
- /**
103
- * Convert a posted message to our StandardMessage format
104
- *
105
- * @param event The message event received on the window
106
- * @returns A message with the `StandardMessage` format, or null if the conversion was unsuccessful
107
- */
108
- const eventToStandardMessage = (event) => {
109
- try {
110
- // Currently all non-string messages are discarded here since parsing throws an error
111
- // TODO Review whether this is the desired outcome
112
- const data = JSON.parse(event.data);
113
- const message = isProgrammaticMessage(data)
114
- ? toStandardMessage(data)
115
- : data;
116
- if (isValidPayload(message)) {
117
- return message;
118
- }
119
- }
120
- catch (ex) {
121
- // Do nothing
122
- }
123
- };
124
- /**
125
- * Respond to the original iframe with the result of calling the
126
- * persistent listener / listener chain
127
- */
128
- const respond = (id, target, error, result) => {
129
- (0, post_message_1.postMessage)({
130
- id,
131
- error,
132
- result,
133
- }, target ?? window);
134
- };
135
- /**
136
- * Callback that is fired when an arbitrary message is received on the window
137
- *
138
- * @param event The message event received on the window
139
- */
140
- const onMessage = async (event) => {
141
- const message = eventToStandardMessage(event);
142
- if (!message) {
143
- return;
144
- }
145
- const listener = LISTENERS[message.type];
146
- if (Array.isArray(listener) && listener.length) {
147
- // Because any listener can have side-effects (by unregistering itself),
148
- // we run the promise chain on a copy of the `LISTENERS` array.
149
- // Hat tip @piuccio
150
- const promise =
151
- // We offer, but don't impose, the possibility that a listener returns
152
- // a value that must be sent back to the calling frame. To do this,
153
- // we pass the cumulated returned value as a second argument to each
154
- // listener. Notice we don't try some clever way to compose the result
155
- // value ourselves, this would only make the solution more complex.
156
- // That means a listener can ignore the cumulated return value and
157
- // return something else entirely—life is unfair.
158
- // We don't know what each callack will be made of, we don't want to.
159
- // And so we wrap each call in a promise chain, in case one drops the
160
- // occasional fastdom bomb in the middle.
161
- listener.reduce((func, listener) => func.then((ret) => {
162
- const thisRet = listener(message.value, ret, getIframe(message, event.source));
163
- return thisRet === undefined ? ret : thisRet;
164
- }), Promise.resolve());
165
- return promise
166
- .then((response) => {
167
- respond(message.id, event.source, null, response);
168
- })
169
- .catch((ex) => {
170
- reportError(ex, {
171
- feature: 'native-ads',
172
- });
173
- respond(message.id, event.source, formatError(error500, ex.toString()), null);
174
- });
175
- }
176
- else if (typeof listener === 'function') {
177
- // We found a persistent listener, to which we just delegate
178
- // responsibility to write something. Anything. Really.
179
- // The listener writes something by being given the `respond` function as the spec
180
- listener(
181
- // TODO change the arguments expected by persistent listeners to avoid this
182
- (error, result) => respond(message.id, event.source, error, result), message.value, getIframe(message, event.source));
183
- }
184
- else {
185
- // If there is no routine attached to this event type, we just answer
186
- // with an error code
187
- respond(message.id, event.source, formatError(error405, message.type), null);
188
- }
189
- };
190
- const on = (window) => {
191
- window.addEventListener('message', (event) => void onMessage(event));
192
- };
193
- const off = (window) => {
194
- window.removeEventListener('message', (event) => void onMessage(event));
195
- };
196
- /**
197
- * Register a listener for a given type of iframe message
198
- *
199
- * @param type The `type` of message to register against
200
- * @param callback The listener callback to register that will receive messages of the given type
201
- * @param options Options for the target window
202
- */
203
- const register = (type, callback, options) => {
204
- if (REGISTERED_LISTENERS === 0) {
205
- on(options?.window ?? window);
206
- }
207
- const listeners = LISTENERS[type] ?? [];
208
- if (Array.isArray(listeners) && !listeners.includes(callback)) {
209
- LISTENERS[type] = [...listeners, callback];
210
- REGISTERED_LISTENERS += 1;
211
- }
212
- };
213
- exports.register = register;
214
- /**
215
- * Register a persistent listener for a given type of iframe message
216
- *
217
- * @param type The `type` of message to register against
218
- * @param callback The persistent listener callback to register that will receive messages of the given type
219
- * @param options Options for the target window and whether the callback is persistent
220
- */
221
- const registerPersistentListener = (type, callback, options) => {
222
- if (REGISTERED_LISTENERS === 0) {
223
- on(options?.window ?? window);
224
- }
225
- LISTENERS[type] = callback;
226
- REGISTERED_LISTENERS += 1;
227
- };
228
- exports.registerPersistentListener = registerPersistentListener;
229
- /**
230
- * Unregister a callback for a given type
231
- *
232
- * @param type The type of message to unregister against. An iframe will send
233
- * messages annotated with the type
234
- * @param callback Optionally include the original callback. If this is included
235
- * for a persistent callback this function will be unregistered. If it's
236
- * included for a non-persistent callback only the matching callback is removed,
237
- * otherwise all callbacks for that type will be unregistered
238
- * @param options Option for the target window
239
- */
240
- const unregister = (type, callback, options) => {
241
- const listeners = LISTENERS[type];
242
- if (listeners === undefined) {
243
- throw new Error(formatError(error405, type).message);
244
- }
245
- else if (listeners === callback) {
246
- LISTENERS[type] = undefined;
247
- REGISTERED_LISTENERS -= 1;
248
- }
249
- else if (Array.isArray(listeners)) {
250
- if (callback === undefined) {
251
- LISTENERS[type] = [];
252
- REGISTERED_LISTENERS -= listeners.length;
253
- }
254
- else {
255
- LISTENERS[type] = listeners.filter((cb) => {
256
- const callbacksEqual = cb === callback;
257
- if (callbacksEqual) {
258
- REGISTERED_LISTENERS -= 1;
259
- }
260
- return !callbacksEqual;
261
- });
262
- }
263
- }
264
- if (REGISTERED_LISTENERS === 0) {
265
- off(options?.window ?? window);
266
- }
267
- };
268
- exports.unregister = unregister;
269
- /**
270
- * Initialize an array of listener callbacks in a batch
271
- *
272
- * @param listeners The listener registration functions
273
- * @param persistentListeners The persistent listener registration functions
274
- */
275
- const init = (listeners, persistentListeners, errorHandler) => {
276
- reportError = errorHandler;
277
- listeners.forEach((moduleInit) => moduleInit(exports.register, errorHandler));
278
- persistentListeners.forEach((moduleInit) => moduleInit(exports.registerPersistentListener, errorHandler));
279
- };
280
- exports.init = init;
281
- exports._ = { onMessage };
@@ -1,15 +0,0 @@
1
- import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
2
- import type { PageTargeting } from './build-page-targeting';
3
- declare const consentlessTargetingKeys: readonly ["ab", "at", "bl", "bp", "br", "cc", "ct", "dcre", "edition", "k", "rc", "rp", "s", "se", "sens", "sh", "si", "skinsize", "su", "tn", "url", "urlkw"];
4
- type ConsentlessTargetingKeys = (typeof consentlessTargetingKeys)[number];
5
- type ConsentlessPageTargeting = Partial<Pick<PageTargeting, ConsentlessTargetingKeys>>;
6
- /**
7
- * Call buildPageTargeting then filter out the keys that are not needed for
8
- * consentless targeting.
9
- *
10
- * @param {ConsentState} consentState
11
- * @param {boolean} adFree
12
- * @returns ConsentlessPageTargeting
13
- */
14
- declare const buildPageTargetingConsentless: (consentState: ConsentState, adFree: boolean) => ConsentlessPageTargeting;
15
- export { buildPageTargetingConsentless };
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildPageTargetingConsentless = void 0;
4
- const build_page_targeting_1 = require("./build-page-targeting");
5
- const consentlessTargetingKeys = [
6
- 'ab',
7
- 'at',
8
- 'bl',
9
- 'bp',
10
- 'br',
11
- 'cc',
12
- 'ct',
13
- 'dcre',
14
- 'edition',
15
- 'k',
16
- 'rc',
17
- 'rp',
18
- 's',
19
- 'se',
20
- 'sens',
21
- 'sh',
22
- 'si',
23
- 'skinsize',
24
- 'su',
25
- 'tn',
26
- 'url',
27
- 'urlkw',
28
- ];
29
- const isConsentlessKey = (key) => consentlessTargetingKeys.includes(key);
30
- /**
31
- * Call buildPageTargeting then filter out the keys that are not needed for
32
- * consentless targeting.
33
- *
34
- * @param {ConsentState} consentState
35
- * @param {boolean} adFree
36
- * @returns ConsentlessPageTargeting
37
- */
38
- const buildPageTargetingConsentless = (consentState, adFree) => {
39
- const consentedPageTargeting = (0, build_page_targeting_1.buildPageTargeting)({
40
- adFree,
41
- consentState,
42
- clientSideParticipations: {},
43
- });
44
- return Object.fromEntries(Object.entries(consentedPageTargeting).filter(([k]) => isConsentlessKey(k)));
45
- };
46
- exports.buildPageTargetingConsentless = buildPageTargetingConsentless;
@@ -1,13 +0,0 @@
1
- import type { Participations } from '@guardian/ab-core';
2
- import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
3
- import type { AdsConfig, AdsConfigDisabled, CustomParams } from '../types';
4
- declare const disabledAds: AdsConfigDisabled;
5
- type BuildAdsConfigWithConsent = {
6
- isAdFreeUser: boolean;
7
- adUnit: string;
8
- customParams: CustomParams;
9
- consentState: ConsentState;
10
- clientSideParticipations: Participations;
11
- };
12
- declare const buildAdsConfigWithConsent: ({ adUnit, clientSideParticipations, consentState, customParams, isAdFreeUser, }: BuildAdsConfigWithConsent) => AdsConfig;
13
- export { buildAdsConfigWithConsent, disabledAds };
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.disabledAds = exports.buildAdsConfigWithConsent = void 0;
4
- const construct_query_1 = require("../lib/construct-query");
5
- const build_page_targeting_1 = require("./build-page-targeting");
6
- const disabledAds = { disableAds: true };
7
- exports.disabledAds = disabledAds;
8
- const buildAdsConfig = (cmpConsent, adUnit, customParams, clientSideParticipations) => {
9
- const mergedCustomParams = {
10
- ...customParams,
11
- ...(0, build_page_targeting_1.buildPageTargeting)({
12
- adFree: false,
13
- clientSideParticipations,
14
- consentState: cmpConsent,
15
- youtube: true,
16
- }),
17
- // 19/04/2023 This is a temporary update to assist reporting for a YouTube IMA test
18
- yt_embed_ima: '0',
19
- };
20
- const defaultAdsConfig = {
21
- adTagParameters: {
22
- iu: adUnit,
23
- // TODO: Why are we double encoding? Following Frontend process for now
24
- cust_params: encodeURIComponent((0, construct_query_1.constructQuery)(mergedCustomParams)),
25
- },
26
- };
27
- if (cmpConsent.ccpa) {
28
- const canTarget = !cmpConsent.ccpa.doNotSell;
29
- return {
30
- ...defaultAdsConfig,
31
- restrictedDataProcessor: !canTarget,
32
- };
33
- }
34
- if (cmpConsent.aus) {
35
- const canTarget = cmpConsent.aus.personalisedAdvertising;
36
- return {
37
- ...defaultAdsConfig,
38
- restrictedDataProcessor: !canTarget,
39
- };
40
- }
41
- if (cmpConsent.tcfv2) {
42
- const tcfData = cmpConsent.tcfv2;
43
- const canTarget = Object.values(tcfData.consents).every(Boolean);
44
- const mergedAdTagParameters = {
45
- ...defaultAdsConfig.adTagParameters,
46
- cmpGdpr: tcfData.gdprApplies ? 1 : 0,
47
- cmpGvcd: tcfData.addtlConsent,
48
- cmpVcd: tcfData.tcString,
49
- };
50
- return {
51
- adTagParameters: mergedAdTagParameters,
52
- nonPersonalizedAd: !canTarget,
53
- };
54
- }
55
- // Shouldn't happen but handle if no matching framework
56
- return disabledAds;
57
- };
58
- const buildAdsConfigWithConsent = ({ adUnit, clientSideParticipations, consentState, customParams, isAdFreeUser, }) => {
59
- if (isAdFreeUser) {
60
- return disabledAds;
61
- }
62
- return buildAdsConfig(consentState, adUnit, customParams, clientSideParticipations);
63
- };
64
- exports.buildAdsConfigWithConsent = buildAdsConfigWithConsent;
@@ -1,7 +0,0 @@
1
- import type { GetThirdPartyTag } from '../types';
2
- /**
3
- * IAS script filters bad ads
4
- * https://integralads.com/uk/
5
- * @param {} {shouldRun}
6
- */
7
- export declare const ias: GetThirdPartyTag;
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ias = void 0;
4
- /**
5
- * IAS script filters bad ads
6
- * https://integralads.com/uk/
7
- * @param {} {shouldRun}
8
- */
9
- const ias = ({ shouldRun }) => ({
10
- shouldRun,
11
- url: '//cdn.adsafeprotected.com/iasPET.1.js',
12
- name: 'ias',
13
- });
14
- exports.ias = ias;
@@ -1,13 +0,0 @@
1
- import type { GetThirdPartyTag } from '../types';
2
- /**
3
- * Allows creatives to show survey
4
- * https://trello.com/c/wHffHVF1/171-integrate-and-test-inizio
5
- * @param {} {shouldRun}
6
- */
7
- export declare const inizio: GetThirdPartyTag;
8
- export declare const _: {
9
- onLoad: () => void;
10
- handleQuerySurveyDone: (surveyAvailable: boolean, survey: {
11
- measurementId: string;
12
- }) => void;
13
- };
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._ = exports.inizio = void 0;
4
- const handleQuerySurveyDone = (surveyAvailable, survey) => {
5
- if (surveyAvailable) {
6
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- @types/googletag declares it, but it may be missing
7
- if (window.googletag) {
8
- window.googletag.cmd.push(() => {
9
- window.googletag.pubads().setTargeting('inizio', 't');
10
- });
11
- }
12
- console.log(`surveyAvailable: ${survey.measurementId}`);
13
- }
14
- };
15
- const onLoad = () => {
16
- window._brandmetrics || (window._brandmetrics = []);
17
- window._brandmetrics.push({
18
- cmd: '_querySurvey',
19
- val: {
20
- callback: handleQuerySurveyDone,
21
- },
22
- });
23
- };
24
- /**
25
- * Allows creatives to show survey
26
- * https://trello.com/c/wHffHVF1/171-integrate-and-test-inizio
27
- * @param {} {shouldRun}
28
- */
29
- const inizio = ({ shouldRun }) => ({
30
- shouldRun,
31
- url: '//cdn.brandmetrics.com/survey/script/e96d04c832084488a841a06b49b8fb2d.js',
32
- name: 'inizio',
33
- onLoad,
34
- });
35
- exports.inizio = inizio;
36
- exports._ = {
37
- onLoad,
38
- handleQuerySurveyDone,
39
- };
@@ -1,6 +0,0 @@
1
- import type { GetThirdPartyTag } from '../types';
2
- /**
3
- * Permutive script updates local user segmentation data
4
- * @param {} {shouldRun}
5
- */
6
- export declare const permutive: GetThirdPartyTag;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.permutive = void 0;
4
- /**
5
- * Permutive script updates local user segmentation data
6
- * @param {} {shouldRun}
7
- */
8
- const permutive = ({ shouldRun }) => ({
9
- shouldRun,
10
- url: '//cdn.permutive.com/d6691a17-6fdb-4d26-85d6-b3dd27f55f08-web.js',
11
- name: 'permutive',
12
- });
13
- exports.permutive = permutive;
@@ -1,7 +0,0 @@
1
- import type { GetThirdPartyTag } from '../types';
2
- /**
3
- * Google conversion tracking
4
- * https://support.google.com/google-ads/answer/6095821
5
- * @param {} {shouldRun}
6
- */
7
- export declare const remarketing: GetThirdPartyTag;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.remarketing = void 0;
4
- const onLoad = () => {
5
- window.google_trackConversion?.({
6
- google_conversion_id: 971225648,
7
- google_custom_params: window.google_tag_params,
8
- google_remarketing_only: true,
9
- });
10
- };
11
- /**
12
- * Google conversion tracking
13
- * https://support.google.com/google-ads/answer/6095821
14
- * @param {} {shouldRun}
15
- */
16
- const remarketing = ({ shouldRun }) => ({
17
- shouldRun,
18
- url: '//www.googleadservices.com/pagead/conversion_async.js',
19
- name: 'remarketing',
20
- onLoad,
21
- });
22
- exports.remarketing = remarketing;
@@ -1,7 +0,0 @@
1
- import type { GetThirdPartyTag } from '../types';
2
- /**
3
- * tracking pixel
4
- * https://business.twitter.com/en/help/campaign-measurement-and-analytics/conversion-tracking-for-websites.html
5
- * @param {} {shouldRun}
6
- */
7
- export declare const twitter: GetThirdPartyTag;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.twitter = void 0;
4
- const twitter_script_1 = require("../__vendor/twitter-script");
5
- /**
6
- * tracking pixel
7
- * https://business.twitter.com/en/help/campaign-measurement-and-analytics/conversion-tracking-for-websites.html
8
- * @param {} {shouldRun}
9
- */
10
- const twitter = ({ shouldRun }) => ({
11
- shouldRun,
12
- name: 'twitter',
13
- insertSnippet: twitter_script_1.twitterScript,
14
- });
15
- exports.twitter = twitter;
@@ -1,7 +0,0 @@
1
- import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
2
- /**
3
- * Collect metrics on gpcSignal presence and value
4
- * https://globalprivacycontrol.github.io/gpc-spec/
5
- */
6
- declare const initTrackGpcSignal: (consentState: ConsentState) => void;
7
- export { initTrackGpcSignal };
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initTrackGpcSignal = void 0;
4
- const libs_1 = require("@guardian/libs");
5
- const event_timer_1 = require("./event-timer");
6
- /**
7
- * Collect metrics on gpcSignal presence and value
8
- * https://globalprivacycontrol.github.io/gpc-spec/
9
- */
10
- const initTrackGpcSignal = (consentState) => {
11
- // If undefined we set the property value to -1, false is 0, true is 1
12
- const gpcSignal = consentState.gpcSignal === undefined ? -1 : +consentState.gpcSignal;
13
- const eventTimer = event_timer_1.EventTimer.get();
14
- (0, libs_1.log)('commercial', `gpcSignal ${gpcSignal}`);
15
- eventTimer.setProperty('gpcSignal', gpcSignal);
16
- };
17
- exports.initTrackGpcSignal = initTrackGpcSignal;
@@ -1,7 +0,0 @@
1
- /**
2
- * Collect commercial metrics on:
3
- * - whether the page contains a Guardian Labs container element (aka 'dumathoin'), and if so
4
- * - when the element is scrolled into view
5
- */
6
- declare const initTrackLabsContainer: () => void;
7
- export { initTrackLabsContainer };
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initTrackLabsContainer = void 0;
4
- const libs_1 = require("@guardian/libs");
5
- const event_timer_1 = require("./event-timer");
6
- /**
7
- * Collect commercial metrics on:
8
- * - whether the page contains a Guardian Labs container element (aka 'dumathoin'), and if so
9
- * - when the element is scrolled into view
10
- */
11
- const initTrackLabsContainer = () => {
12
- const target = document.querySelector('section.dumathoin');
13
- if (target === null)
14
- return;
15
- const labsUrl = document
16
- .querySelector('h1.dumathoin__title a')
17
- ?.getAttribute('href');
18
- if (labsUrl === null)
19
- return;
20
- const eventTimer = event_timer_1.EventTimer.get();
21
- (0, libs_1.log)('commercial', 'Page has labs container');
22
- eventTimer.setProperty('hasLabsContainer', true);
23
- eventTimer.setProperty('labsUrl', labsUrl);
24
- const observer = new IntersectionObserver((entries) => {
25
- entries.map((entry) => {
26
- if (entry.isIntersecting) {
27
- (0, libs_1.log)('commercial', 'Labs container in view');
28
- eventTimer.trigger('labsContainerInView');
29
- observer.unobserve(entry.target);
30
- }
31
- });
32
- });
33
- observer.observe(target);
34
- };
35
- exports.initTrackLabsContainer = initTrackLabsContainer;
@@ -1,8 +0,0 @@
1
- /**
2
- * Collect commercial metrics on scroll depth
3
- * Insert hidden elements at intervals of 1 viewport height
4
- * then use an intersection observer to mark the time when the viewport intersects with these elements.
5
- * Approach inspired by https://gist.github.com/bgreater/2412517f5a3f9c6fc4cafeb1ca71384f
6
- */
7
- declare const initTrackScrollDepth: () => void;
8
- export { initTrackScrollDepth };