@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.
- package/LICENSE +201 -0
- package/README.md +23 -34
- package/dist/cjs/ad-sizes.d.ts +150 -8
- package/dist/cjs/ad-sizes.js +129 -38
- package/dist/cjs/breakpoint.d.ts +8 -0
- package/dist/cjs/breakpoint.js +10 -0
- package/dist/cjs/constants/index.d.ts +1 -1
- package/dist/cjs/constants/index.js +2 -2
- package/dist/cjs/detect-ad-blocker.js +1 -2
- package/dist/cjs/event-timer.d.ts +60 -48
- package/dist/cjs/event-timer.js +149 -115
- package/dist/cjs/geo/country-code.d.ts +3 -0
- package/dist/cjs/geo/country-code.js +34 -0
- package/dist/cjs/geo/geo-utils.d.ts +11 -0
- package/dist/cjs/geo/geo-utils.js +31 -0
- package/dist/cjs/global.d.ts +58 -10
- package/dist/cjs/index.d.ts +9 -39
- package/dist/cjs/index.js +12 -67
- package/dist/cjs/send-commercial-metrics.d.ts +8 -2
- package/dist/cjs/send-commercial-metrics.js +51 -27
- package/dist/cjs/targeting/build-page-targeting.d.ts +4 -5
- package/dist/cjs/targeting/build-page-targeting.js +35 -7
- package/dist/cjs/targeting/content.d.ts +1 -1
- package/dist/cjs/targeting/content.js +1 -1
- package/dist/cjs/targeting/personalised.d.ts +2 -3
- package/dist/cjs/targeting/personalised.js +3 -3
- package/dist/cjs/targeting/pick-targeting-values.d.ts +1 -1
- package/dist/cjs/targeting/session.d.ts +2 -2
- package/dist/cjs/targeting/shared.d.ts +31 -20
- package/dist/cjs/targeting/shared.js +0 -30
- package/dist/cjs/targeting/teads-eligibility.d.ts +2 -0
- package/dist/cjs/targeting/teads-eligibility.js +20 -0
- package/dist/cjs/targeting/types.d.ts +6 -0
- package/dist/cjs/targeting/types.js +2 -0
- package/dist/cjs/targeting/viewport.d.ts +1 -1
- package/dist/cjs/targeting/youtube-ima.d.ts +4 -3
- package/dist/cjs/targeting/youtube-ima.js +7 -4
- package/dist/cjs/types.d.ts +403 -63
- package/dist/cjs/types.js +11 -0
- package/dist/esm/ad-sizes.d.ts +150 -8
- package/dist/esm/ad-sizes.js +127 -38
- package/dist/esm/breakpoint.d.ts +8 -0
- package/dist/esm/breakpoint.js +6 -0
- package/dist/esm/constants/index.d.ts +1 -1
- package/dist/esm/constants/index.js +1 -1
- package/dist/esm/event-timer.d.ts +60 -48
- package/dist/esm/event-timer.js +147 -115
- package/dist/esm/geo/country-code.d.ts +3 -0
- package/dist/esm/geo/country-code.js +31 -0
- package/dist/esm/geo/geo-utils.d.ts +11 -0
- package/dist/esm/geo/geo-utils.js +20 -0
- package/dist/esm/global.d.ts +58 -10
- package/dist/esm/global.js +0 -1
- package/dist/esm/index.d.ts +9 -39
- package/dist/esm/index.js +6 -31
- package/dist/esm/send-commercial-metrics.d.ts +8 -2
- package/dist/esm/send-commercial-metrics.js +48 -25
- package/dist/esm/targeting/build-page-targeting.d.ts +4 -5
- package/dist/esm/targeting/build-page-targeting.js +35 -7
- package/dist/esm/targeting/content.d.ts +1 -1
- package/dist/esm/targeting/content.js +1 -1
- package/dist/esm/targeting/personalised.d.ts +2 -3
- package/dist/esm/targeting/personalised.js +3 -3
- package/dist/esm/targeting/pick-targeting-values.d.ts +1 -1
- package/dist/esm/targeting/session.d.ts +2 -2
- package/dist/esm/targeting/shared.d.ts +31 -20
- package/dist/esm/targeting/shared.js +0 -30
- package/dist/esm/targeting/teads-eligibility.d.ts +2 -0
- package/dist/esm/targeting/teads-eligibility.js +17 -0
- package/dist/esm/targeting/types.d.ts +6 -0
- package/dist/esm/targeting/types.js +0 -0
- package/dist/esm/targeting/viewport.d.ts +1 -1
- package/dist/esm/targeting/youtube-ima.d.ts +4 -3
- package/dist/esm/targeting/youtube-ima.js +7 -4
- package/dist/esm/types.d.ts +403 -63
- package/dist/esm/types.js +11 -1
- package/package.json +64 -83
- package/dist/cjs/__vendor/a9-apstag.d.ts +0 -1
- package/dist/cjs/__vendor/a9-apstag.js +0 -34
- package/dist/cjs/__vendor/ipsos-mori.d.ts +0 -1
- package/dist/cjs/__vendor/ipsos-mori.js +0 -18
- package/dist/cjs/__vendor/launchpad.d.ts +0 -1
- package/dist/cjs/__vendor/launchpad.js +0 -25
- package/dist/cjs/__vendor/pubmatic.d.ts +0 -1
- package/dist/cjs/__vendor/pubmatic.js +0 -49
- package/dist/cjs/__vendor/twitter-script.d.ts +0 -1
- package/dist/cjs/__vendor/twitter-script.js +0 -26
- package/dist/cjs/create-ad-slot.d.ts +0 -17
- package/dist/cjs/create-ad-slot.js +0 -107
- package/dist/cjs/google-analytics.d.ts +0 -1
- package/dist/cjs/google-analytics.js +0 -14
- package/dist/cjs/lib/ab-localstorage.d.ts +0 -2
- package/dist/cjs/lib/ab-localstorage.js +0 -14
- package/dist/cjs/lib/breakpoint.d.ts +0 -4
- package/dist/cjs/lib/breakpoint.js +0 -5
- package/dist/cjs/lib/can-use-dom.d.ts +0 -2
- package/dist/cjs/lib/can-use-dom.js +0 -9
- package/dist/cjs/lib/construct-query.d.ts +0 -3
- package/dist/cjs/lib/construct-query.js +0 -12
- package/dist/cjs/messenger.d.ts +0 -97
- package/dist/cjs/messenger.js +0 -281
- package/dist/cjs/targeting/build-page-targeting-consentless.d.ts +0 -15
- package/dist/cjs/targeting/build-page-targeting-consentless.js +0 -46
- package/dist/cjs/targeting/youtube.d.ts +0 -13
- package/dist/cjs/targeting/youtube.js +0 -64
- package/dist/cjs/third-party-tags/ias.d.ts +0 -7
- package/dist/cjs/third-party-tags/ias.js +0 -14
- package/dist/cjs/third-party-tags/inizio.d.ts +0 -13
- package/dist/cjs/third-party-tags/inizio.js +0 -39
- package/dist/cjs/third-party-tags/permutive.d.ts +0 -6
- package/dist/cjs/third-party-tags/permutive.js +0 -13
- package/dist/cjs/third-party-tags/remarketing.d.ts +0 -7
- package/dist/cjs/third-party-tags/remarketing.js +0 -22
- package/dist/cjs/third-party-tags/twitter-uwt.d.ts +0 -7
- package/dist/cjs/third-party-tags/twitter-uwt.js +0 -15
- package/dist/cjs/track-gpc-signal.d.ts +0 -7
- package/dist/cjs/track-gpc-signal.js +0 -17
- package/dist/cjs/track-labs-container.d.ts +0 -7
- package/dist/cjs/track-labs-container.js +0 -35
- package/dist/cjs/track-scroll-depth.d.ts +0 -8
- package/dist/cjs/track-scroll-depth.js +0 -41
- package/dist/esm/__vendor/a9-apstag.d.ts +0 -1
- package/dist/esm/__vendor/a9-apstag.js +0 -30
- package/dist/esm/__vendor/ipsos-mori.d.ts +0 -1
- package/dist/esm/__vendor/ipsos-mori.js +0 -14
- package/dist/esm/__vendor/launchpad.d.ts +0 -1
- package/dist/esm/__vendor/launchpad.js +0 -21
- package/dist/esm/__vendor/pubmatic.d.ts +0 -1
- package/dist/esm/__vendor/pubmatic.js +0 -45
- package/dist/esm/__vendor/twitter-script.d.ts +0 -1
- package/dist/esm/__vendor/twitter-script.js +0 -22
- package/dist/esm/create-ad-slot.d.ts +0 -17
- package/dist/esm/create-ad-slot.js +0 -103
- package/dist/esm/google-analytics.d.ts +0 -1
- package/dist/esm/google-analytics.js +0 -10
- package/dist/esm/lib/ab-localstorage.d.ts +0 -2
- package/dist/esm/lib/ab-localstorage.js +0 -10
- package/dist/esm/lib/breakpoint.d.ts +0 -4
- package/dist/esm/lib/breakpoint.js +0 -2
- package/dist/esm/lib/can-use-dom.d.ts +0 -2
- package/dist/esm/lib/can-use-dom.js +0 -6
- package/dist/esm/lib/construct-query.d.ts +0 -3
- package/dist/esm/lib/construct-query.js +0 -9
- package/dist/esm/messenger.d.ts +0 -97
- package/dist/esm/messenger.js +0 -274
- package/dist/esm/targeting/build-page-targeting-consentless.d.ts +0 -15
- package/dist/esm/targeting/build-page-targeting-consentless.js +0 -43
- package/dist/esm/targeting/youtube.d.ts +0 -13
- package/dist/esm/targeting/youtube.js +0 -60
- package/dist/esm/third-party-tags/ias.d.ts +0 -7
- package/dist/esm/third-party-tags/ias.js +0 -10
- package/dist/esm/third-party-tags/inizio.d.ts +0 -13
- package/dist/esm/third-party-tags/inizio.js +0 -35
- package/dist/esm/third-party-tags/permutive.d.ts +0 -6
- package/dist/esm/third-party-tags/permutive.js +0 -9
- package/dist/esm/third-party-tags/remarketing.d.ts +0 -7
- package/dist/esm/third-party-tags/remarketing.js +0 -18
- package/dist/esm/third-party-tags/twitter-uwt.d.ts +0 -7
- package/dist/esm/third-party-tags/twitter-uwt.js +0 -11
- package/dist/esm/track-gpc-signal.d.ts +0 -7
- package/dist/esm/track-gpc-signal.js +0 -14
- package/dist/esm/track-labs-container.d.ts +0 -7
- package/dist/esm/track-labs-container.js +0 -32
- package/dist/esm/track-scroll-depth.d.ts +0 -8
- package/dist/esm/track-scroll-depth.js +0 -38
- /package/dist/cjs/constants/{adLabelHeight.d.ts → ad-label-height.d.ts} +0 -0
- /package/dist/cjs/constants/{adLabelHeight.js → ad-label-height.js} +0 -0
- /package/dist/cjs/{lib → geo}/get-locale.d.ts +0 -0
- /package/dist/cjs/{lib → geo}/get-locale.js +0 -0
- /package/dist/esm/constants/{adLabelHeight.d.ts → ad-label-height.d.ts} +0 -0
- /package/dist/esm/constants/{adLabelHeight.js → ad-label-height.js} +0 -0
- /package/dist/esm/{lib → geo}/get-locale.d.ts +0 -0
- /package/dist/esm/{lib → geo}/get-locale.js +0 -0
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initTrackScrollDepth = void 0;
|
|
4
|
-
const libs_1 = require("@guardian/libs");
|
|
5
|
-
const event_timer_1 = require("./event-timer");
|
|
6
|
-
/**
|
|
7
|
-
* Collect commercial metrics on scroll depth
|
|
8
|
-
* Insert hidden elements at intervals of 1 viewport height
|
|
9
|
-
* then use an intersection observer to mark the time when the viewport intersects with these elements.
|
|
10
|
-
* Approach inspired by https://gist.github.com/bgreater/2412517f5a3f9c6fc4cafeb1ca71384f
|
|
11
|
-
*/
|
|
12
|
-
const initTrackScrollDepth = () => {
|
|
13
|
-
const pageHeight = document.body.offsetHeight;
|
|
14
|
-
const intViewportHeight = window.innerHeight;
|
|
15
|
-
// how many viewports tall is the page?
|
|
16
|
-
const pageHeightVH = Math.floor(pageHeight / intViewportHeight);
|
|
17
|
-
const eventTimer = event_timer_1.EventTimer.get();
|
|
18
|
-
eventTimer.setProperty('pageHeightVH', pageHeightVH);
|
|
19
|
-
const observer = new IntersectionObserver(
|
|
20
|
-
/* istanbul ignore next */
|
|
21
|
-
(entries) => {
|
|
22
|
-
entries.forEach((entry) => {
|
|
23
|
-
if (entry.isIntersecting) {
|
|
24
|
-
const currentDepthVH = String(entry.target.getAttribute('data-depth'));
|
|
25
|
-
(0, libs_1.log)('commercial', `current scroll depth ${currentDepthVH}`);
|
|
26
|
-
eventTimer.trigger(`scroll-depth-vh-${currentDepthVH}`);
|
|
27
|
-
observer.unobserve(entry.target);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
for (let depth = 1; depth <= pageHeightVH; depth++) {
|
|
32
|
-
const div = document.createElement('div');
|
|
33
|
-
div.dataset.depth = String(depth);
|
|
34
|
-
div.style.top = String(100 * depth) + '%';
|
|
35
|
-
div.style.position = 'absolute';
|
|
36
|
-
div.className = 'scroll-depth-marker';
|
|
37
|
-
document.body.appendChild(div);
|
|
38
|
-
observer.observe(div);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
exports.initTrackScrollDepth = initTrackScrollDepth;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function a9Apstag(): void;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Load Amazon A9 library as {@link https://ams.amazon.com/webpublisher/uam/docs/web-integration-documentation/integration-guide/javascript-guide/display.html described here}
|
|
3
|
-
*/
|
|
4
|
-
export const a9Apstag = () => {
|
|
5
|
-
(function (a9, a, p, s, t, A, g) {
|
|
6
|
-
if (a[a9])
|
|
7
|
-
return;
|
|
8
|
-
function q(c, r) {
|
|
9
|
-
a[a9]._Q.push([c, r]);
|
|
10
|
-
}
|
|
11
|
-
a[a9] = {
|
|
12
|
-
init() {
|
|
13
|
-
q('i', arguments);
|
|
14
|
-
},
|
|
15
|
-
fetchBids() {
|
|
16
|
-
q('f', arguments);
|
|
17
|
-
},
|
|
18
|
-
setDisplayBids() { },
|
|
19
|
-
targetingKeys() {
|
|
20
|
-
return [];
|
|
21
|
-
},
|
|
22
|
-
_Q: [],
|
|
23
|
-
};
|
|
24
|
-
A = p.createElement(s);
|
|
25
|
-
A.async = !0;
|
|
26
|
-
A.src = t;
|
|
27
|
-
g = p.getElementsByTagName(s)[0];
|
|
28
|
-
g.parentNode.insertBefore(A, g);
|
|
29
|
-
})('apstag', window, document, 'script', '//c.amazon-adsystem.com/aax2/apstag.js');
|
|
30
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function ipsosMoriStub(): void;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Load the Ipsos Mori Stub
|
|
3
|
-
*
|
|
4
|
-
* See {@Link https://github.com/guardian/dotcom-rendering/blob/150fc2d81e6a66d9c3336185e874fc8cd0288546/dotcom-rendering/docs/architecture/3rd%20party%20technical%20review/002-ipsos-mori.md documentation here }
|
|
5
|
-
*/
|
|
6
|
-
export const ipsosMoriStub = () => {
|
|
7
|
-
window.dm = window.dm || { AjaxData: [] };
|
|
8
|
-
window.dm.AjaxEvent = (et, d, ssid, ad) => {
|
|
9
|
-
dm.AjaxData.push({ et, d, ssid, ad });
|
|
10
|
-
if (window.DotMetricsObj) {
|
|
11
|
-
DotMetricsObj.onAjaxDataUpdate();
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function launchpad(): void;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Loads the Launchpad js tracker (used by Redplanet) into the page,
|
|
3
|
-
* and creates the global "launchpad" method
|
|
4
|
-
*/
|
|
5
|
-
export const launchpad = () => {
|
|
6
|
-
(function (p, l, o, w, i, n, g) {
|
|
7
|
-
if (!p[i]) {
|
|
8
|
-
p.GlobalSnowplowNamespace = p.GlobalSnowplowNamespace || [];
|
|
9
|
-
p.GlobalSnowplowNamespace.push(i);
|
|
10
|
-
p[i] = function () {
|
|
11
|
-
(p[i].q = p[i].q || []).push(arguments);
|
|
12
|
-
};
|
|
13
|
-
p[i].q = p[i].q || [];
|
|
14
|
-
n = l.createElement(o);
|
|
15
|
-
g = l.getElementsByTagName(o)[0];
|
|
16
|
-
n.async = 1;
|
|
17
|
-
n.src = w;
|
|
18
|
-
g.parentNode.insertBefore(n, g);
|
|
19
|
-
}
|
|
20
|
-
}(window, document, "script", "https://lps.qantas.com/sp.js", "launchpad"));
|
|
21
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function pubmatic(bid: any, data: any, acEnabled: any, utils: any, defaultFn: any): void;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pubmatic custom override script
|
|
3
|
-
*
|
|
4
|
-
* From {@Link https://gist.github.com/abhinavsinha001/de46bd4ac4f02d98eb50c1f4f995545e}
|
|
5
|
-
*/
|
|
6
|
-
export const pubmatic = function (bid, data, acEnabled, utils, defaultFn) {
|
|
7
|
-
if (defaultFn) {
|
|
8
|
-
// keep this to move to default function once supported by RTD submodule
|
|
9
|
-
bid = defaultFn(bid, data, acEnabled);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
let segments = [];
|
|
13
|
-
// add all user segments
|
|
14
|
-
try {
|
|
15
|
-
const psegs = JSON.parse(localStorage._psegs || '[]').map(String);
|
|
16
|
-
const ppam = JSON.parse(localStorage._ppam || '[]');
|
|
17
|
-
const pcrprs = JSON.parse(localStorage._pcrprs || '[]');
|
|
18
|
-
segments = [...psegs, ...ppam, ...pcrprs];
|
|
19
|
-
}
|
|
20
|
-
catch (e) { }
|
|
21
|
-
// add AC specific segments (these would typically go to a separate key-value, but not sure if we can have 2 lists of segments here?)
|
|
22
|
-
if (acEnabled && data.ac && data.ac.length > 0) {
|
|
23
|
-
segments = segments.concat(data.ac);
|
|
24
|
-
}
|
|
25
|
-
segments = segments.map(function (seg) {
|
|
26
|
-
return { id: seg };
|
|
27
|
-
});
|
|
28
|
-
pbjs.setBidderConfig({
|
|
29
|
-
// Note this will replace existing bidder FPD config till merge is supported.
|
|
30
|
-
bidders: ['pubmatic'],
|
|
31
|
-
config: {
|
|
32
|
-
ortb2: {
|
|
33
|
-
user: {
|
|
34
|
-
data: [
|
|
35
|
-
{
|
|
36
|
-
name: 'permutive.com',
|
|
37
|
-
segment: segments,
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function twitterScript(): void;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Twitter universal website tag code
|
|
2
|
-
// How to set up conversion tracking: https://business.twitter.com/en/help/campaign-measurement-and-analytics/conversion-tracking-for-websites.html
|
|
3
|
-
export const twitterScript = () => {
|
|
4
|
-
!(function (e, t, n, s, u, a) {
|
|
5
|
-
e.twq ||
|
|
6
|
-
((s = e.twq = function () {
|
|
7
|
-
s.exe ? s.exe(...arguments) : s.queue.push(arguments);
|
|
8
|
-
}),
|
|
9
|
-
(s.version = '1.1'),
|
|
10
|
-
(s.queue = []),
|
|
11
|
-
(u = t.createElement(n)),
|
|
12
|
-
(u.async = !0),
|
|
13
|
-
(u.src = '//static.ads-twitter.com/uwt.js'),
|
|
14
|
-
(a = t.getElementsByTagName(n)[0]),
|
|
15
|
-
a.parentNode.insertBefore(u, a));
|
|
16
|
-
})(window, document, 'script');
|
|
17
|
-
// Insert Twitter Pixel ID and Standard Event data below
|
|
18
|
-
twq('init', 'nyl43'); // The Guardian ID
|
|
19
|
-
twq('track', 'PageView');
|
|
20
|
-
twq('init', 'ny4k9'); // PHD ID
|
|
21
|
-
twq('track', 'PageView');
|
|
22
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { SizeMapping } from './ad-sizes';
|
|
2
|
-
type SlotName = 'carrot' | 'comments-expanded' | 'comments' | 'epic' | 'exclusion' | 'fronts-banner' | 'high-merch-lucky' | 'high-merch-paid' | 'high-merch' | 'im' | 'inline' | 'mobile-sticky' | 'mostpop' | 'top-above-nav';
|
|
3
|
-
type CreateSlotOptions = {
|
|
4
|
-
classes?: string;
|
|
5
|
-
name?: string;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Given default size mappings and additional size mappings from
|
|
9
|
-
* the createAdSlot options parameter.
|
|
10
|
-
*
|
|
11
|
-
* 1. Check that the options size mappings use known device names
|
|
12
|
-
* 2. If so concat the size mappings
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
declare const concatSizeMappings: (defaultSizeMappings: SizeMapping, optionSizeMappings?: SizeMapping) => SizeMapping;
|
|
16
|
-
declare const createAdSlot: (name: SlotName, options?: CreateSlotOptions) => HTMLElement;
|
|
17
|
-
export { createAdSlot, concatSizeMappings };
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { isBreakpoint } from './lib/breakpoint';
|
|
2
|
-
const adSlotIdPrefix = 'dfp-ad--';
|
|
3
|
-
const adSlotConfigs = {
|
|
4
|
-
im: {
|
|
5
|
-
label: false,
|
|
6
|
-
refresh: false,
|
|
7
|
-
},
|
|
8
|
-
'high-merch': {
|
|
9
|
-
label: false,
|
|
10
|
-
refresh: false,
|
|
11
|
-
name: 'merchandising-high',
|
|
12
|
-
},
|
|
13
|
-
'high-merch-lucky': {
|
|
14
|
-
label: false,
|
|
15
|
-
refresh: false,
|
|
16
|
-
name: 'merchandising-high-lucky',
|
|
17
|
-
},
|
|
18
|
-
'high-merch-paid': {
|
|
19
|
-
label: false,
|
|
20
|
-
refresh: false,
|
|
21
|
-
name: 'merchandising-high',
|
|
22
|
-
},
|
|
23
|
-
carrot: {
|
|
24
|
-
label: false,
|
|
25
|
-
refresh: false,
|
|
26
|
-
name: 'carrot',
|
|
27
|
-
},
|
|
28
|
-
epic: {
|
|
29
|
-
label: false,
|
|
30
|
-
refresh: false,
|
|
31
|
-
name: 'epic',
|
|
32
|
-
},
|
|
33
|
-
'mobile-sticky': {
|
|
34
|
-
label: true,
|
|
35
|
-
refresh: true,
|
|
36
|
-
name: 'mobile-sticky',
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
Returns an adSlot HTMLElement which is the main DFP slot.
|
|
41
|
-
|
|
42
|
-
Insert that element as siblings at the place you want adverts to appear.
|
|
43
|
-
|
|
44
|
-
Note that for the DFP slot to be filled by GTP, you'll have to
|
|
45
|
-
use addSlot from add-slot.js
|
|
46
|
-
*/
|
|
47
|
-
const createAdSlotElement = (name, attrs, classes) => {
|
|
48
|
-
const id = `${adSlotIdPrefix}${name}`;
|
|
49
|
-
// 3562dc07-78e9-4507-b922-78b979d4c5cb
|
|
50
|
-
if (window.guardian.config.isDotcomRendering && name === 'top-above-nav') {
|
|
51
|
-
// This is to prevent a problem that appeared with DCR.
|
|
52
|
-
// We are simply making sure that if we are about to
|
|
53
|
-
// introduce dfp-ad--top-above-nav then there isn't already one.
|
|
54
|
-
const node = document.getElementById(id);
|
|
55
|
-
if (node?.parentNode) {
|
|
56
|
-
const pnode = node.parentNode;
|
|
57
|
-
console.log(`warning: cleaning up dom node id: dfp-ad--${name}`);
|
|
58
|
-
pnode.removeChild(node);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// The 'main' adSlot
|
|
62
|
-
const adSlot = document.createElement('div');
|
|
63
|
-
adSlot.id = id;
|
|
64
|
-
adSlot.className = `js-ad-slot ad-slot ${classes.join(' ')}`;
|
|
65
|
-
adSlot.dataset.linkName = `ad slot ${name}`;
|
|
66
|
-
adSlot.dataset.name = name;
|
|
67
|
-
adSlot.setAttribute('aria-hidden', 'true');
|
|
68
|
-
Object.entries(attrs).forEach(([k, v]) => (adSlot.dataset[k] = v));
|
|
69
|
-
return adSlot;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Split class names and prefix all with ad-slot--${className}
|
|
73
|
-
*/
|
|
74
|
-
const createClasses = (slotName, classes) => [...(classes?.split(' ') ?? []), slotName].map((className) => `ad-slot--${className}`);
|
|
75
|
-
/**
|
|
76
|
-
* Given default size mappings and additional size mappings from
|
|
77
|
-
* the createAdSlot options parameter.
|
|
78
|
-
*
|
|
79
|
-
* 1. Check that the options size mappings use known device names
|
|
80
|
-
* 2. If so concat the size mappings
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
const concatSizeMappings = (defaultSizeMappings, optionSizeMappings = {}) => Object.entries(optionSizeMappings).reduce((sizeMappings, [breakpoint, optionSizes]) => {
|
|
84
|
-
// Only perform concatenation if breakpoint is of the correct type
|
|
85
|
-
if (isBreakpoint(breakpoint)) {
|
|
86
|
-
// Concatenate the option sizes onto any existing sizes present for a given breakpoint
|
|
87
|
-
sizeMappings[breakpoint] = (sizeMappings[breakpoint] ?? []).concat(optionSizes);
|
|
88
|
-
}
|
|
89
|
-
return sizeMappings;
|
|
90
|
-
}, { ...defaultSizeMappings });
|
|
91
|
-
const createAdSlot = (name, options = {}) => {
|
|
92
|
-
const adSlotConfig = adSlotConfigs[name] ?? {};
|
|
93
|
-
const slotName = options.name ?? adSlotConfig.name ?? name;
|
|
94
|
-
const dataAttributes = {};
|
|
95
|
-
if (adSlotConfig.label === false) {
|
|
96
|
-
dataAttributes.label = 'false';
|
|
97
|
-
}
|
|
98
|
-
if (adSlotConfig.refresh === false) {
|
|
99
|
-
dataAttributes.refresh = 'false';
|
|
100
|
-
}
|
|
101
|
-
return createAdSlotElement(slotName, dataAttributes, createClasses(slotName, options.classes));
|
|
102
|
-
};
|
|
103
|
-
export { createAdSlot, concatSizeMappings };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const trackEvent: (timingCategory: string, timingVar: string, timingLabel: string) => void;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export const trackEvent = (timingCategory, timingVar, timingLabel) => {
|
|
2
|
-
const { ga, guardian } = window;
|
|
3
|
-
const trackerName = guardian.config.googleAnalytics?.trackers.editorial;
|
|
4
|
-
if (typeof ga !== 'function') {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
const timeSincePageLoad = Math.round(window.performance.now());
|
|
8
|
-
const send = trackerName ? `${trackerName}.send` : 'send';
|
|
9
|
-
window.ga(send, 'timing', timingCategory, timingVar, timeSincePageLoad, timingLabel);
|
|
10
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { isObject, isString, storage } from '@guardian/libs';
|
|
2
|
-
const participationsKey = 'gu.ab.participations';
|
|
3
|
-
const isParticipations = (participations) => {
|
|
4
|
-
return (isObject(participations) &&
|
|
5
|
-
Object.values(participations).every((participation) => isObject(participation) && isString(participation.variant)));
|
|
6
|
-
};
|
|
7
|
-
export const getParticipationsFromLocalStorage = () => {
|
|
8
|
-
const participations = storage.local.get(participationsKey);
|
|
9
|
-
return isParticipations(participations) ? participations : {};
|
|
10
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// Based on https://github.com/JedWatson/exenv
|
|
2
|
-
const canUseDom = () => !!(typeof window !== 'undefined' &&
|
|
3
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- ensure we check at runtime
|
|
4
|
-
window.document &&
|
|
5
|
-
window.document.createElement);
|
|
6
|
-
export { canUseDom };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const constructQuery = (query) => Object.entries(query)
|
|
2
|
-
.map(([key, value]) => {
|
|
3
|
-
const queryValue = Array.isArray(value)
|
|
4
|
-
? value.map((v) => encodeURIComponent(v)).join(',')
|
|
5
|
-
: encodeURIComponent(value);
|
|
6
|
-
return `${key}=${queryValue}`;
|
|
7
|
-
})
|
|
8
|
-
.join('&');
|
|
9
|
-
export { constructQuery };
|
package/dist/esm/messenger.d.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The type of iframe messages we accept
|
|
3
|
-
*/
|
|
4
|
-
type MessageType = 'background' | 'click' | 'disable-refresh' | 'get-page-targeting' | 'get-page-url' | 'get-styles' | 'measure-ad-load' | 'passback' | 'resize' | 'set-ad-height' | 'scroll' | 'type' | 'viewport';
|
|
5
|
-
/**
|
|
6
|
-
* Callbacks that can be registered to fire when receiving messages from an iframe
|
|
7
|
-
*/
|
|
8
|
-
type ListenerCallback = (
|
|
9
|
-
/**
|
|
10
|
-
* The data payload sent by an iframe, and has type `unknown` because we can't
|
|
11
|
-
* predict what the iframe will send. It is the responsibility of the callback
|
|
12
|
-
* to obtain a value of the desired type (or fail gracefully)
|
|
13
|
-
*/
|
|
14
|
-
specs: unknown | undefined,
|
|
15
|
-
/**
|
|
16
|
-
* Non-persistent callbacks can be chained together. This value is the return
|
|
17
|
-
* value of the previously fired callback in the chain. It is the responsibility
|
|
18
|
-
* of the current callback to either ignore it or use it / pass along
|
|
19
|
-
*/
|
|
20
|
-
ret: unknown,
|
|
21
|
-
/**
|
|
22
|
-
* Reference to the iframe that is the source of the message
|
|
23
|
-
*/
|
|
24
|
-
iframe?: HTMLIFrameElement) => unknown;
|
|
25
|
-
type RespondProxy = (error: {
|
|
26
|
-
message: string;
|
|
27
|
-
} | null, result: unknown) => void;
|
|
28
|
-
/**
|
|
29
|
-
* Persistent callbacks that can be registered to fire when receiving messages from an iframe
|
|
30
|
-
*
|
|
31
|
-
* A persistent callback listener will be passed a RespondProxy function
|
|
32
|
-
*
|
|
33
|
-
* This function allows the listener to call respond (i.e. postMessage the originating iFrame) itself whenever it needs to
|
|
34
|
-
*
|
|
35
|
-
* This is useful for listeners such as viewport or scroll where the values change over time
|
|
36
|
-
*/
|
|
37
|
-
type PersistentListenerCallback = (respondProxy: RespondProxy, specs: unknown,
|
|
38
|
-
/**
|
|
39
|
-
* Reference to the iframe that is the source of the message
|
|
40
|
-
*/
|
|
41
|
-
iframe?: HTMLIFrameElement) => void;
|
|
42
|
-
type ListenerOptions = {
|
|
43
|
-
window?: WindowProxy;
|
|
44
|
-
};
|
|
45
|
-
type MessengerErrorHandler = (err: Error, features: Record<string, string>) => void;
|
|
46
|
-
/**
|
|
47
|
-
* Types of functions to register a listener for a given type of iframe message
|
|
48
|
-
*/
|
|
49
|
-
type RegisterListener = (type: MessageType, callback: ListenerCallback, options?: ListenerOptions) => void;
|
|
50
|
-
/**
|
|
51
|
-
* Types of functions to register a persistent listener for a given type of iframe message
|
|
52
|
-
*/
|
|
53
|
-
type RegisterPersistentListener = (type: MessageType, callback: PersistentListenerCallback, options?: ListenerOptions) => void;
|
|
54
|
-
/**
|
|
55
|
-
* Types of functions to unregister a listener for a given type of iframe message
|
|
56
|
-
*
|
|
57
|
-
*/
|
|
58
|
-
type UnregisterListener = (type: MessageType, callback?: ListenerCallback, options?: ListenerOptions) => void;
|
|
59
|
-
/**
|
|
60
|
-
* Register a listener for a given type of iframe message
|
|
61
|
-
*
|
|
62
|
-
* @param type The `type` of message to register against
|
|
63
|
-
* @param callback The listener callback to register that will receive messages of the given type
|
|
64
|
-
* @param options Options for the target window
|
|
65
|
-
*/
|
|
66
|
-
export declare const register: RegisterListener;
|
|
67
|
-
/**
|
|
68
|
-
* Register a persistent listener for a given type of iframe message
|
|
69
|
-
*
|
|
70
|
-
* @param type The `type` of message to register against
|
|
71
|
-
* @param callback The persistent listener callback to register that will receive messages of the given type
|
|
72
|
-
* @param options Options for the target window and whether the callback is persistent
|
|
73
|
-
*/
|
|
74
|
-
export declare const registerPersistentListener: RegisterPersistentListener;
|
|
75
|
-
/**
|
|
76
|
-
* Unregister a callback for a given type
|
|
77
|
-
*
|
|
78
|
-
* @param type The type of message to unregister against. An iframe will send
|
|
79
|
-
* messages annotated with the type
|
|
80
|
-
* @param callback Optionally include the original callback. If this is included
|
|
81
|
-
* for a persistent callback this function will be unregistered. If it's
|
|
82
|
-
* included for a non-persistent callback only the matching callback is removed,
|
|
83
|
-
* otherwise all callbacks for that type will be unregistered
|
|
84
|
-
* @param options Option for the target window
|
|
85
|
-
*/
|
|
86
|
-
export declare const unregister: UnregisterListener;
|
|
87
|
-
/**
|
|
88
|
-
* Initialize an array of listener callbacks in a batch
|
|
89
|
-
*
|
|
90
|
-
* @param listeners The listener registration functions
|
|
91
|
-
* @param persistentListeners The persistent listener registration functions
|
|
92
|
-
*/
|
|
93
|
-
export declare const init: (listeners: ((register: RegisterListener, errorHandler: MessengerErrorHandler) => void)[], persistentListeners: ((register: RegisterPersistentListener, errorHandler: MessengerErrorHandler) => void)[], errorHandler: MessengerErrorHandler) => void;
|
|
94
|
-
export declare const _: {
|
|
95
|
-
onMessage: (event: MessageEvent) => Promise<void>;
|
|
96
|
-
};
|
|
97
|
-
export type { RespondProxy, RegisterListener, RegisterPersistentListener, UnregisterListener, ListenerOptions, MessengerErrorHandler, };
|