@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,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.a9Apstag = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Load Amazon A9 library as {@link https://ams.amazon.com/webpublisher/uam/docs/web-integration-documentation/integration-guide/javascript-guide/display.html described here}
|
|
6
|
-
*/
|
|
7
|
-
const a9Apstag = () => {
|
|
8
|
-
(function (a9, a, p, s, t, A, g) {
|
|
9
|
-
if (a[a9])
|
|
10
|
-
return;
|
|
11
|
-
function q(c, r) {
|
|
12
|
-
a[a9]._Q.push([c, r]);
|
|
13
|
-
}
|
|
14
|
-
a[a9] = {
|
|
15
|
-
init() {
|
|
16
|
-
q('i', arguments);
|
|
17
|
-
},
|
|
18
|
-
fetchBids() {
|
|
19
|
-
q('f', arguments);
|
|
20
|
-
},
|
|
21
|
-
setDisplayBids() { },
|
|
22
|
-
targetingKeys() {
|
|
23
|
-
return [];
|
|
24
|
-
},
|
|
25
|
-
_Q: [],
|
|
26
|
-
};
|
|
27
|
-
A = p.createElement(s);
|
|
28
|
-
A.async = !0;
|
|
29
|
-
A.src = t;
|
|
30
|
-
g = p.getElementsByTagName(s)[0];
|
|
31
|
-
g.parentNode.insertBefore(A, g);
|
|
32
|
-
})('apstag', window, document, 'script', '//c.amazon-adsystem.com/aax2/apstag.js');
|
|
33
|
-
};
|
|
34
|
-
exports.a9Apstag = a9Apstag;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function ipsosMoriStub(): void;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ipsosMoriStub = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Load the Ipsos Mori Stub
|
|
6
|
-
*
|
|
7
|
-
* See {@Link https://github.com/guardian/dotcom-rendering/blob/150fc2d81e6a66d9c3336185e874fc8cd0288546/dotcom-rendering/docs/architecture/3rd%20party%20technical%20review/002-ipsos-mori.md documentation here }
|
|
8
|
-
*/
|
|
9
|
-
const ipsosMoriStub = () => {
|
|
10
|
-
window.dm = window.dm || { AjaxData: [] };
|
|
11
|
-
window.dm.AjaxEvent = (et, d, ssid, ad) => {
|
|
12
|
-
dm.AjaxData.push({ et, d, ssid, ad });
|
|
13
|
-
if (window.DotMetricsObj) {
|
|
14
|
-
DotMetricsObj.onAjaxDataUpdate();
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
exports.ipsosMoriStub = ipsosMoriStub;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function launchpad(): void;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.launchpad = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Loads the Launchpad js tracker (used by Redplanet) into the page,
|
|
6
|
-
* and creates the global "launchpad" method
|
|
7
|
-
*/
|
|
8
|
-
const launchpad = () => {
|
|
9
|
-
(function (p, l, o, w, i, n, g) {
|
|
10
|
-
if (!p[i]) {
|
|
11
|
-
p.GlobalSnowplowNamespace = p.GlobalSnowplowNamespace || [];
|
|
12
|
-
p.GlobalSnowplowNamespace.push(i);
|
|
13
|
-
p[i] = function () {
|
|
14
|
-
(p[i].q = p[i].q || []).push(arguments);
|
|
15
|
-
};
|
|
16
|
-
p[i].q = p[i].q || [];
|
|
17
|
-
n = l.createElement(o);
|
|
18
|
-
g = l.getElementsByTagName(o)[0];
|
|
19
|
-
n.async = 1;
|
|
20
|
-
n.src = w;
|
|
21
|
-
g.parentNode.insertBefore(n, g);
|
|
22
|
-
}
|
|
23
|
-
}(window, document, "script", "https://lps.qantas.com/sp.js", "launchpad"));
|
|
24
|
-
};
|
|
25
|
-
exports.launchpad = launchpad;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function pubmatic(bid: any, data: any, acEnabled: any, utils: any, defaultFn: any): void;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pubmatic = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Pubmatic custom override script
|
|
6
|
-
*
|
|
7
|
-
* From {@Link https://gist.github.com/abhinavsinha001/de46bd4ac4f02d98eb50c1f4f995545e}
|
|
8
|
-
*/
|
|
9
|
-
const pubmatic = function (bid, data, acEnabled, utils, defaultFn) {
|
|
10
|
-
if (defaultFn) {
|
|
11
|
-
// keep this to move to default function once supported by RTD submodule
|
|
12
|
-
bid = defaultFn(bid, data, acEnabled);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
let segments = [];
|
|
16
|
-
// add all user segments
|
|
17
|
-
try {
|
|
18
|
-
const psegs = JSON.parse(localStorage._psegs || '[]').map(String);
|
|
19
|
-
const ppam = JSON.parse(localStorage._ppam || '[]');
|
|
20
|
-
const pcrprs = JSON.parse(localStorage._pcrprs || '[]');
|
|
21
|
-
segments = [...psegs, ...ppam, ...pcrprs];
|
|
22
|
-
}
|
|
23
|
-
catch (e) { }
|
|
24
|
-
// 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?)
|
|
25
|
-
if (acEnabled && data.ac && data.ac.length > 0) {
|
|
26
|
-
segments = segments.concat(data.ac);
|
|
27
|
-
}
|
|
28
|
-
segments = segments.map(function (seg) {
|
|
29
|
-
return { id: seg };
|
|
30
|
-
});
|
|
31
|
-
pbjs.setBidderConfig({
|
|
32
|
-
// Note this will replace existing bidder FPD config till merge is supported.
|
|
33
|
-
bidders: ['pubmatic'],
|
|
34
|
-
config: {
|
|
35
|
-
ortb2: {
|
|
36
|
-
user: {
|
|
37
|
-
data: [
|
|
38
|
-
{
|
|
39
|
-
name: 'permutive.com',
|
|
40
|
-
segment: segments,
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
exports.pubmatic = pubmatic;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function twitterScript(): void;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Twitter universal website tag code
|
|
3
|
-
// How to set up conversion tracking: https://business.twitter.com/en/help/campaign-measurement-and-analytics/conversion-tracking-for-websites.html
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.twitterScript = void 0;
|
|
6
|
-
const twitterScript = () => {
|
|
7
|
-
!(function (e, t, n, s, u, a) {
|
|
8
|
-
e.twq ||
|
|
9
|
-
((s = e.twq = function () {
|
|
10
|
-
s.exe ? s.exe(...arguments) : s.queue.push(arguments);
|
|
11
|
-
}),
|
|
12
|
-
(s.version = '1.1'),
|
|
13
|
-
(s.queue = []),
|
|
14
|
-
(u = t.createElement(n)),
|
|
15
|
-
(u.async = !0),
|
|
16
|
-
(u.src = '//static.ads-twitter.com/uwt.js'),
|
|
17
|
-
(a = t.getElementsByTagName(n)[0]),
|
|
18
|
-
a.parentNode.insertBefore(u, a));
|
|
19
|
-
})(window, document, 'script');
|
|
20
|
-
// Insert Twitter Pixel ID and Standard Event data below
|
|
21
|
-
twq('init', 'nyl43'); // The Guardian ID
|
|
22
|
-
twq('track', 'PageView');
|
|
23
|
-
twq('init', 'ny4k9'); // PHD ID
|
|
24
|
-
twq('track', 'PageView');
|
|
25
|
-
};
|
|
26
|
-
exports.twitterScript = twitterScript;
|
|
@@ -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,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.concatSizeMappings = exports.createAdSlot = void 0;
|
|
4
|
-
const breakpoint_1 = require("./lib/breakpoint");
|
|
5
|
-
const adSlotIdPrefix = 'dfp-ad--';
|
|
6
|
-
const adSlotConfigs = {
|
|
7
|
-
im: {
|
|
8
|
-
label: false,
|
|
9
|
-
refresh: false,
|
|
10
|
-
},
|
|
11
|
-
'high-merch': {
|
|
12
|
-
label: false,
|
|
13
|
-
refresh: false,
|
|
14
|
-
name: 'merchandising-high',
|
|
15
|
-
},
|
|
16
|
-
'high-merch-lucky': {
|
|
17
|
-
label: false,
|
|
18
|
-
refresh: false,
|
|
19
|
-
name: 'merchandising-high-lucky',
|
|
20
|
-
},
|
|
21
|
-
'high-merch-paid': {
|
|
22
|
-
label: false,
|
|
23
|
-
refresh: false,
|
|
24
|
-
name: 'merchandising-high',
|
|
25
|
-
},
|
|
26
|
-
carrot: {
|
|
27
|
-
label: false,
|
|
28
|
-
refresh: false,
|
|
29
|
-
name: 'carrot',
|
|
30
|
-
},
|
|
31
|
-
epic: {
|
|
32
|
-
label: false,
|
|
33
|
-
refresh: false,
|
|
34
|
-
name: 'epic',
|
|
35
|
-
},
|
|
36
|
-
'mobile-sticky': {
|
|
37
|
-
label: true,
|
|
38
|
-
refresh: true,
|
|
39
|
-
name: 'mobile-sticky',
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
Returns an adSlot HTMLElement which is the main DFP slot.
|
|
44
|
-
|
|
45
|
-
Insert that element as siblings at the place you want adverts to appear.
|
|
46
|
-
|
|
47
|
-
Note that for the DFP slot to be filled by GTP, you'll have to
|
|
48
|
-
use addSlot from add-slot.js
|
|
49
|
-
*/
|
|
50
|
-
const createAdSlotElement = (name, attrs, classes) => {
|
|
51
|
-
const id = `${adSlotIdPrefix}${name}`;
|
|
52
|
-
// 3562dc07-78e9-4507-b922-78b979d4c5cb
|
|
53
|
-
if (window.guardian.config.isDotcomRendering && name === 'top-above-nav') {
|
|
54
|
-
// This is to prevent a problem that appeared with DCR.
|
|
55
|
-
// We are simply making sure that if we are about to
|
|
56
|
-
// introduce dfp-ad--top-above-nav then there isn't already one.
|
|
57
|
-
const node = document.getElementById(id);
|
|
58
|
-
if (node?.parentNode) {
|
|
59
|
-
const pnode = node.parentNode;
|
|
60
|
-
console.log(`warning: cleaning up dom node id: dfp-ad--${name}`);
|
|
61
|
-
pnode.removeChild(node);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// The 'main' adSlot
|
|
65
|
-
const adSlot = document.createElement('div');
|
|
66
|
-
adSlot.id = id;
|
|
67
|
-
adSlot.className = `js-ad-slot ad-slot ${classes.join(' ')}`;
|
|
68
|
-
adSlot.dataset.linkName = `ad slot ${name}`;
|
|
69
|
-
adSlot.dataset.name = name;
|
|
70
|
-
adSlot.setAttribute('aria-hidden', 'true');
|
|
71
|
-
Object.entries(attrs).forEach(([k, v]) => (adSlot.dataset[k] = v));
|
|
72
|
-
return adSlot;
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Split class names and prefix all with ad-slot--${className}
|
|
76
|
-
*/
|
|
77
|
-
const createClasses = (slotName, classes) => [...(classes?.split(' ') ?? []), slotName].map((className) => `ad-slot--${className}`);
|
|
78
|
-
/**
|
|
79
|
-
* Given default size mappings and additional size mappings from
|
|
80
|
-
* the createAdSlot options parameter.
|
|
81
|
-
*
|
|
82
|
-
* 1. Check that the options size mappings use known device names
|
|
83
|
-
* 2. If so concat the size mappings
|
|
84
|
-
*
|
|
85
|
-
*/
|
|
86
|
-
const concatSizeMappings = (defaultSizeMappings, optionSizeMappings = {}) => Object.entries(optionSizeMappings).reduce((sizeMappings, [breakpoint, optionSizes]) => {
|
|
87
|
-
// Only perform concatenation if breakpoint is of the correct type
|
|
88
|
-
if ((0, breakpoint_1.isBreakpoint)(breakpoint)) {
|
|
89
|
-
// Concatenate the option sizes onto any existing sizes present for a given breakpoint
|
|
90
|
-
sizeMappings[breakpoint] = (sizeMappings[breakpoint] ?? []).concat(optionSizes);
|
|
91
|
-
}
|
|
92
|
-
return sizeMappings;
|
|
93
|
-
}, { ...defaultSizeMappings });
|
|
94
|
-
exports.concatSizeMappings = concatSizeMappings;
|
|
95
|
-
const createAdSlot = (name, options = {}) => {
|
|
96
|
-
const adSlotConfig = adSlotConfigs[name] ?? {};
|
|
97
|
-
const slotName = options.name ?? adSlotConfig.name ?? name;
|
|
98
|
-
const dataAttributes = {};
|
|
99
|
-
if (adSlotConfig.label === false) {
|
|
100
|
-
dataAttributes.label = 'false';
|
|
101
|
-
}
|
|
102
|
-
if (adSlotConfig.refresh === false) {
|
|
103
|
-
dataAttributes.refresh = 'false';
|
|
104
|
-
}
|
|
105
|
-
return createAdSlotElement(slotName, dataAttributes, createClasses(slotName, options.classes));
|
|
106
|
-
};
|
|
107
|
-
exports.createAdSlot = createAdSlot;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const trackEvent: (timingCategory: string, timingVar: string, timingLabel: string) => void;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.trackEvent = void 0;
|
|
4
|
-
const trackEvent = (timingCategory, timingVar, timingLabel) => {
|
|
5
|
-
const { ga, guardian } = window;
|
|
6
|
-
const trackerName = guardian.config.googleAnalytics?.trackers.editorial;
|
|
7
|
-
if (typeof ga !== 'function') {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const timeSincePageLoad = Math.round(window.performance.now());
|
|
11
|
-
const send = trackerName ? `${trackerName}.send` : 'send';
|
|
12
|
-
window.ga(send, 'timing', timingCategory, timingVar, timeSincePageLoad, timingLabel);
|
|
13
|
-
};
|
|
14
|
-
exports.trackEvent = trackEvent;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getParticipationsFromLocalStorage = void 0;
|
|
4
|
-
const libs_1 = require("@guardian/libs");
|
|
5
|
-
const participationsKey = 'gu.ab.participations';
|
|
6
|
-
const isParticipations = (participations) => {
|
|
7
|
-
return ((0, libs_1.isObject)(participations) &&
|
|
8
|
-
Object.values(participations).every((participation) => (0, libs_1.isObject)(participation) && (0, libs_1.isString)(participation.variant)));
|
|
9
|
-
};
|
|
10
|
-
const getParticipationsFromLocalStorage = () => {
|
|
11
|
-
const participations = libs_1.storage.local.get(participationsKey);
|
|
12
|
-
return isParticipations(participations) ? participations : {};
|
|
13
|
-
};
|
|
14
|
-
exports.getParticipationsFromLocalStorage = getParticipationsFromLocalStorage;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Based on https://github.com/JedWatson/exenv
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.canUseDom = void 0;
|
|
5
|
-
const canUseDom = () => !!(typeof window !== 'undefined' &&
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- ensure we check at runtime
|
|
7
|
-
window.document &&
|
|
8
|
-
window.document.createElement);
|
|
9
|
-
exports.canUseDom = canUseDom;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.constructQuery = void 0;
|
|
4
|
-
const constructQuery = (query) => Object.entries(query)
|
|
5
|
-
.map(([key, value]) => {
|
|
6
|
-
const queryValue = Array.isArray(value)
|
|
7
|
-
? value.map((v) => encodeURIComponent(v)).join(',')
|
|
8
|
-
: encodeURIComponent(value);
|
|
9
|
-
return `${key}=${queryValue}`;
|
|
10
|
-
})
|
|
11
|
-
.join('&');
|
|
12
|
-
exports.constructQuery = constructQuery;
|
package/dist/cjs/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, };
|