@guardian/commercial-core 4.16.0 → 4.18.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 (35) hide show
  1. package/dist/cjs/__vendor/a9-apstag.d.ts +1 -0
  2. package/dist/cjs/__vendor/a9-apstag.js +34 -0
  3. package/dist/cjs/__vendor/ipsos-mori.d.ts +1 -0
  4. package/dist/cjs/__vendor/ipsos-mori.js +18 -0
  5. package/dist/cjs/__vendor/launchpad.d.ts +1 -0
  6. package/dist/cjs/__vendor/launchpad.js +25 -0
  7. package/dist/cjs/__vendor/pubmatic.d.ts +1 -0
  8. package/dist/cjs/__vendor/pubmatic.js +49 -0
  9. package/dist/cjs/index.d.ts +4 -0
  10. package/dist/cjs/index.js +10 -1
  11. package/dist/cjs/lib/get-locale.d.ts +8 -0
  12. package/dist/cjs/lib/get-locale.js +43 -0
  13. package/dist/cjs/targeting/build-page-targeting-consentless.d.ts +1 -3
  14. package/dist/cjs/targeting/build-page-targeting-consentless.js +2 -3
  15. package/dist/cjs/targeting/build-page-targeting.d.ts +1 -1
  16. package/dist/cjs/targeting/build-page-targeting.js +3 -2
  17. package/dist/cjs/types.d.ts +2 -1
  18. package/dist/esm/__vendor/a9-apstag.d.ts +1 -0
  19. package/dist/esm/__vendor/a9-apstag.js +30 -0
  20. package/dist/esm/__vendor/ipsos-mori.d.ts +1 -0
  21. package/dist/esm/__vendor/ipsos-mori.js +14 -0
  22. package/dist/esm/__vendor/launchpad.d.ts +1 -0
  23. package/dist/esm/__vendor/launchpad.js +21 -0
  24. package/dist/esm/__vendor/pubmatic.d.ts +1 -0
  25. package/dist/esm/__vendor/pubmatic.js +45 -0
  26. package/dist/esm/index.d.ts +4 -0
  27. package/dist/esm/index.js +5 -0
  28. package/dist/esm/lib/get-locale.d.ts +8 -0
  29. package/dist/esm/lib/get-locale.js +38 -0
  30. package/dist/esm/targeting/build-page-targeting-consentless.d.ts +1 -3
  31. package/dist/esm/targeting/build-page-targeting-consentless.js +2 -3
  32. package/dist/esm/targeting/build-page-targeting.d.ts +1 -1
  33. package/dist/esm/targeting/build-page-targeting.js +3 -2
  34. package/dist/esm/types.d.ts +2 -1
  35. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ export function a9Apstag(): void;
@@ -0,0 +1,34 @@
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;
@@ -0,0 +1 @@
1
+ export function ipsosMoriStub(): void;
@@ -0,0 +1,18 @@
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;
@@ -0,0 +1 @@
1
+ export function launchpad(): void;
@@ -0,0 +1,25 @@
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;
@@ -0,0 +1 @@
1
+ export function pubmatic(bid: any, data: any, acEnabled: any, utils: any, defaultFn: any): void;
@@ -0,0 +1,49 @@
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;
@@ -37,3 +37,7 @@ export { postMessage } from './messenger/post-message';
37
37
  export { buildPageTargeting } from './targeting/build-page-targeting';
38
38
  export { buildPageTargetingConsentless } from './targeting/build-page-targeting-consentless';
39
39
  export type { PageTargeting } from './targeting/build-page-targeting';
40
+ export { a9Apstag } from './__vendor/a9-apstag';
41
+ export { ipsosMoriStub } from './__vendor/ipsos-mori';
42
+ export { launchpad } from './__vendor/launchpad';
43
+ export { pubmatic } from './__vendor/pubmatic';
package/dist/cjs/index.js CHANGED
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  return result;
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.buildPageTargetingConsentless = exports.buildPageTargeting = exports.postMessage = exports.initMessenger = exports.pickTargetingValues = exports.getViewportTargeting = exports.getSharedTargeting = exports.getSessionTargeting = exports.getPersonalisedTargeting = exports.getContentTargeting = exports.constants = exports.concatSizeMappings = exports.createAdSlot = exports.disabledAds = exports.buildAdsConfigWithConsent = exports.initTrackGpcSignal = exports.initTrackLabsContainer = exports.initTrackScrollDepth = exports.getPermutivePFPSegments = exports.getPermutiveSegments = exports.clearPermutiveSegments = exports.isAdBlockInUse = exports.isBreakpoint = exports.standardAdSizes = exports.slotSizeMappings = exports.outstreamSizes = exports.getAdSize = exports.createAdSize = exports.adSizes = exports.initCommercialMetrics = exports.bypassCommercialMetricsSampling = exports.EventTimer = exports.remarketing = exports.inizio = exports.twitter = exports.fbPixel = exports.permutive = exports.ias = void 0;
27
+ exports.pubmatic = exports.launchpad = exports.ipsosMoriStub = exports.a9Apstag = exports.buildPageTargetingConsentless = exports.buildPageTargeting = exports.postMessage = exports.initMessenger = exports.pickTargetingValues = exports.getViewportTargeting = exports.getSharedTargeting = exports.getSessionTargeting = exports.getPersonalisedTargeting = exports.getContentTargeting = exports.constants = exports.concatSizeMappings = exports.createAdSlot = exports.disabledAds = exports.buildAdsConfigWithConsent = exports.initTrackGpcSignal = exports.initTrackLabsContainer = exports.initTrackScrollDepth = exports.getPermutivePFPSegments = exports.getPermutiveSegments = exports.clearPermutiveSegments = exports.isAdBlockInUse = exports.isBreakpoint = exports.standardAdSizes = exports.slotSizeMappings = exports.outstreamSizes = exports.getAdSize = exports.createAdSize = exports.adSizes = exports.initCommercialMetrics = exports.bypassCommercialMetricsSampling = exports.EventTimer = exports.remarketing = exports.inizio = exports.twitter = exports.fbPixel = exports.permutive = exports.ias = void 0;
28
28
  var ias_1 = require("./third-party-tags/ias");
29
29
  Object.defineProperty(exports, "ias", { enumerable: true, get: function () { return ias_1.ias; } });
30
30
  var permutive_1 = require("./third-party-tags/permutive");
@@ -90,3 +90,12 @@ var build_page_targeting_1 = require("./targeting/build-page-targeting");
90
90
  Object.defineProperty(exports, "buildPageTargeting", { enumerable: true, get: function () { return build_page_targeting_1.buildPageTargeting; } });
91
91
  var build_page_targeting_consentless_1 = require("./targeting/build-page-targeting-consentless");
92
92
  Object.defineProperty(exports, "buildPageTargetingConsentless", { enumerable: true, get: function () { return build_page_targeting_consentless_1.buildPageTargetingConsentless; } });
93
+ /* -- Vendor JavaScript -- */
94
+ var a9_apstag_1 = require("./__vendor/a9-apstag");
95
+ Object.defineProperty(exports, "a9Apstag", { enumerable: true, get: function () { return a9_apstag_1.a9Apstag; } });
96
+ var ipsos_mori_1 = require("./__vendor/ipsos-mori");
97
+ Object.defineProperty(exports, "ipsosMoriStub", { enumerable: true, get: function () { return ipsos_mori_1.ipsosMoriStub; } });
98
+ var launchpad_1 = require("./__vendor/launchpad");
99
+ Object.defineProperty(exports, "launchpad", { enumerable: true, get: function () { return launchpad_1.launchpad; } });
100
+ var pubmatic_1 = require("./__vendor/pubmatic");
101
+ Object.defineProperty(exports, "pubmatic", { enumerable: true, get: function () { return pubmatic_1.pubmatic; } });
@@ -0,0 +1,8 @@
1
+ import type { CountryCode } from '@guardian/libs';
2
+ export declare const __resetCachedValue: () => void;
3
+ /**
4
+ * Fetches the user's current location as an ISO 3166-1 alpha-2 string e.g. 'GB', 'AU' etc
5
+ * Note: This has been copied from guardian-libs and made syncronous by ommiting the call to
6
+ * the geolocation API
7
+ */
8
+ export declare const getLocale: () => CountryCode;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLocale = exports.__resetCachedValue = void 0;
4
+ const libs_1 = require("@guardian/libs");
5
+ const KEY = 'GU_geo_country';
6
+ const KEY_OVERRIDE = 'gu.geo.override';
7
+ const COUNTRY_REGEX = /^[A-Z]{2}$/;
8
+ // best guess that we have a valid code, without actually shipping the entire list
9
+ const isValidCountryCode = (country) => (0, libs_1.isString)(country) && COUNTRY_REGEX.test(country);
10
+ // we'll cache any successful lookups so we only have to do this once
11
+ let locale;
12
+ const editionToGeolocationMap = {
13
+ UK: 'GB',
14
+ US: 'US',
15
+ AU: 'AU',
16
+ };
17
+ const editionToGeolocation = (editionKey) => editionToGeolocationMap[editionKey];
18
+ // just used for tests
19
+ const __resetCachedValue = () => (locale = undefined);
20
+ exports.__resetCachedValue = __resetCachedValue;
21
+ /**
22
+ * Fetches the user's current location as an ISO 3166-1 alpha-2 string e.g. 'GB', 'AU' etc
23
+ * Note: This has been copied from guardian-libs and made syncronous by ommiting the call to
24
+ * the geolocation API
25
+ */
26
+ const getLocale = () => {
27
+ if (locale)
28
+ return locale;
29
+ // return overridden geo from localStorage, used for changing geo only for development purposes
30
+ const geoOverride = libs_1.storage.local.get(KEY_OVERRIDE);
31
+ if (isValidCountryCode(geoOverride)) {
32
+ return (locale = geoOverride);
33
+ }
34
+ // return locale from cookie if it exists
35
+ const stored = (0, libs_1.getCookie)({ name: KEY });
36
+ if (stored && isValidCountryCode(stored)) {
37
+ return (locale = stored);
38
+ }
39
+ // return locale from edition
40
+ const editionCountryCode = editionToGeolocation(window.guardian.config.page.edition);
41
+ return (locale = editionCountryCode);
42
+ };
43
+ exports.getLocale = getLocale;
@@ -1,6 +1,5 @@
1
1
  import type { Participations } from '@guardian/ab-core';
2
2
  import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
3
- import type { CountryCode } from '@guardian/libs';
4
3
  import type { PageTargeting } from './build-page-targeting';
5
4
  declare const consentlessTargetingKeys: readonly ["ab", "at", "bl", "bp", "br", "cc", "ct", "dcre", "edition", "k", "rp", "s", "se", "sens", "sh", "si", "skinsize", "su", "tn", "url", "urlkw"];
6
5
  declare type ConsentlessTargetingKeys = typeof consentlessTargetingKeys[number];
@@ -11,9 +10,8 @@ declare type ConsentlessPageTargeting = Partial<Pick<PageTargeting, ConsentlessT
11
10
  *
12
11
  * @param {ConsentState} consentState
13
12
  * @param {boolean} adFree
14
- * @param {CountryCode} countryCode
15
13
  * @param {Participations} clientSideParticipations
16
14
  * @returns ConsentlessPageTargeting
17
15
  */
18
- declare const buildPageTargetingConsentless: (consentState: ConsentState, adFree: boolean, countryCode: CountryCode, clientSideParticipations: Participations) => ConsentlessPageTargeting;
16
+ declare const buildPageTargetingConsentless: (consentState: ConsentState, adFree: boolean, clientSideParticipations: Participations) => ConsentlessPageTargeting;
19
17
  export { buildPageTargetingConsentless };
@@ -32,12 +32,11 @@ const isConsentlessKey = (key) => consentlessTargetingKeys.includes(key);
32
32
  *
33
33
  * @param {ConsentState} consentState
34
34
  * @param {boolean} adFree
35
- * @param {CountryCode} countryCode
36
35
  * @param {Participations} clientSideParticipations
37
36
  * @returns ConsentlessPageTargeting
38
37
  */
39
- const buildPageTargetingConsentless = (consentState, adFree, countryCode, clientSideParticipations) => {
40
- const consentedPageTargeting = (0, build_page_targeting_1.buildPageTargeting)(consentState, adFree, countryCode, clientSideParticipations);
38
+ const buildPageTargetingConsentless = (consentState, adFree, clientSideParticipations) => {
39
+ const consentedPageTargeting = (0, build_page_targeting_1.buildPageTargeting)(consentState, adFree, clientSideParticipations);
41
40
  return Object.fromEntries(Object.entries(consentedPageTargeting).filter(([k]) => isConsentlessKey(k)));
42
41
  };
43
42
  exports.buildPageTargetingConsentless = buildPageTargetingConsentless;
@@ -34,6 +34,6 @@ declare type PageTargeting = PartialWithNulls<{
34
34
  vl: string;
35
35
  [_: string]: string | string[];
36
36
  } & SharedTargeting>;
37
- declare const buildPageTargeting: (consentState: ConsentState, adFree: boolean, countryCode: CountryCode, clientSideParticipations: Participations) => PageTargeting;
37
+ declare const buildPageTargeting: (consentState: ConsentState, adFree: boolean, clientSideParticipations: Participations) => PageTargeting;
38
38
  export { buildPageTargeting };
39
39
  export type { PageTargeting };
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildPageTargeting = void 0;
4
4
  const consent_management_platform_1 = require("@guardian/consent-management-platform");
5
5
  const libs_1 = require("@guardian/libs");
6
+ const get_locale_1 = require("../lib/get-locale");
6
7
  const content_1 = require("./content");
7
8
  const personalised_1 = require("./personalised");
8
9
  const session_1 = require("./session");
@@ -23,7 +24,7 @@ const filterEmptyValues = (pageTargets) => {
23
24
  }
24
25
  return filtered;
25
26
  };
26
- const buildPageTargeting = (consentState, adFree, countryCode, clientSideParticipations) => {
27
+ const buildPageTargeting = (consentState, adFree, clientSideParticipations) => {
27
28
  const { page, isDotcomRendering } = window.guardian.config;
28
29
  const adFreeTargeting = adFree ? { af: 't' } : {};
29
30
  const contentTargeting = (0, content_1.getContentTargeting)({
@@ -39,7 +40,7 @@ const buildPageTargeting = (consentState, adFree, countryCode, clientSidePartici
39
40
  const getReferrer = () => document.referrer || '';
40
41
  const sessionTargeting = (0, session_1.getSessionTargeting)({
41
42
  adTest: (0, libs_1.getCookie)({ name: 'adtest', shouldMemoize: true }),
42
- countryCode,
43
+ countryCode: (0, get_locale_1.getLocale)(),
43
44
  isSignedIn: !!(0, libs_1.getCookie)({ name: 'GU_U' }),
44
45
  pageViewId: window.guardian.config.ophan.pageViewId,
45
46
  participations: {
@@ -21,6 +21,7 @@ export declare type GetThirdPartyTag = (arg0: {
21
21
  export declare type GuardianAnalyticsConfig = {
22
22
  trackers: Record<string, string>;
23
23
  };
24
+ export declare type Edition = 'UK' | 'AU' | 'US';
24
25
  export declare type GuardianWindowConfig = {
25
26
  googleAnalytics?: GuardianAnalyticsConfig;
26
27
  isDotcomRendering: boolean;
@@ -30,11 +31,11 @@ export declare type GuardianWindowConfig = {
30
31
  };
31
32
  page: {
32
33
  sharedAdTargeting?: Record<string, string | string[]>;
33
- pageAdTargeting?: Record<string, string | string[]>;
34
34
  isSensitive: boolean;
35
35
  pageId: string;
36
36
  section: string;
37
37
  videoDuration: number;
38
+ edition: Edition;
38
39
  };
39
40
  tests?: {
40
41
  [key: `${string}Control`]: 'control';
@@ -0,0 +1 @@
1
+ export function a9Apstag(): void;
@@ -0,0 +1,30 @@
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
+ };
@@ -0,0 +1 @@
1
+ export function ipsosMoriStub(): void;
@@ -0,0 +1,14 @@
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
+ };
@@ -0,0 +1 @@
1
+ export function launchpad(): void;
@@ -0,0 +1,21 @@
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
+ };
@@ -0,0 +1 @@
1
+ export function pubmatic(bid: any, data: any, acEnabled: any, utils: any, defaultFn: any): void;
@@ -0,0 +1,45 @@
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
+ };
@@ -37,3 +37,7 @@ export { postMessage } from './messenger/post-message';
37
37
  export { buildPageTargeting } from './targeting/build-page-targeting';
38
38
  export { buildPageTargetingConsentless } from './targeting/build-page-targeting-consentless';
39
39
  export type { PageTargeting } from './targeting/build-page-targeting';
40
+ export { a9Apstag } from './__vendor/a9-apstag';
41
+ export { ipsosMoriStub } from './__vendor/ipsos-mori';
42
+ export { launchpad } from './__vendor/launchpad';
43
+ export { pubmatic } from './__vendor/pubmatic';
package/dist/esm/index.js CHANGED
@@ -28,3 +28,8 @@ export { init as initMessenger } from './messenger';
28
28
  export { postMessage } from './messenger/post-message';
29
29
  export { buildPageTargeting } from './targeting/build-page-targeting';
30
30
  export { buildPageTargetingConsentless } from './targeting/build-page-targeting-consentless';
31
+ /* -- Vendor JavaScript -- */
32
+ export { a9Apstag } from './__vendor/a9-apstag';
33
+ export { ipsosMoriStub } from './__vendor/ipsos-mori';
34
+ export { launchpad } from './__vendor/launchpad';
35
+ export { pubmatic } from './__vendor/pubmatic';
@@ -0,0 +1,8 @@
1
+ import type { CountryCode } from '@guardian/libs';
2
+ export declare const __resetCachedValue: () => void;
3
+ /**
4
+ * Fetches the user's current location as an ISO 3166-1 alpha-2 string e.g. 'GB', 'AU' etc
5
+ * Note: This has been copied from guardian-libs and made syncronous by ommiting the call to
6
+ * the geolocation API
7
+ */
8
+ export declare const getLocale: () => CountryCode;
@@ -0,0 +1,38 @@
1
+ import { getCookie, isString, storage } from '@guardian/libs';
2
+ const KEY = 'GU_geo_country';
3
+ const KEY_OVERRIDE = 'gu.geo.override';
4
+ const COUNTRY_REGEX = /^[A-Z]{2}$/;
5
+ // best guess that we have a valid code, without actually shipping the entire list
6
+ const isValidCountryCode = (country) => isString(country) && COUNTRY_REGEX.test(country);
7
+ // we'll cache any successful lookups so we only have to do this once
8
+ let locale;
9
+ const editionToGeolocationMap = {
10
+ UK: 'GB',
11
+ US: 'US',
12
+ AU: 'AU',
13
+ };
14
+ const editionToGeolocation = (editionKey) => editionToGeolocationMap[editionKey];
15
+ // just used for tests
16
+ export const __resetCachedValue = () => (locale = undefined);
17
+ /**
18
+ * Fetches the user's current location as an ISO 3166-1 alpha-2 string e.g. 'GB', 'AU' etc
19
+ * Note: This has been copied from guardian-libs and made syncronous by ommiting the call to
20
+ * the geolocation API
21
+ */
22
+ export const getLocale = () => {
23
+ if (locale)
24
+ return locale;
25
+ // return overridden geo from localStorage, used for changing geo only for development purposes
26
+ const geoOverride = storage.local.get(KEY_OVERRIDE);
27
+ if (isValidCountryCode(geoOverride)) {
28
+ return (locale = geoOverride);
29
+ }
30
+ // return locale from cookie if it exists
31
+ const stored = getCookie({ name: KEY });
32
+ if (stored && isValidCountryCode(stored)) {
33
+ return (locale = stored);
34
+ }
35
+ // return locale from edition
36
+ const editionCountryCode = editionToGeolocation(window.guardian.config.page.edition);
37
+ return (locale = editionCountryCode);
38
+ };
@@ -1,6 +1,5 @@
1
1
  import type { Participations } from '@guardian/ab-core';
2
2
  import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
3
- import type { CountryCode } from '@guardian/libs';
4
3
  import type { PageTargeting } from './build-page-targeting';
5
4
  declare const consentlessTargetingKeys: readonly ["ab", "at", "bl", "bp", "br", "cc", "ct", "dcre", "edition", "k", "rp", "s", "se", "sens", "sh", "si", "skinsize", "su", "tn", "url", "urlkw"];
6
5
  declare type ConsentlessTargetingKeys = typeof consentlessTargetingKeys[number];
@@ -11,9 +10,8 @@ declare type ConsentlessPageTargeting = Partial<Pick<PageTargeting, ConsentlessT
11
10
  *
12
11
  * @param {ConsentState} consentState
13
12
  * @param {boolean} adFree
14
- * @param {CountryCode} countryCode
15
13
  * @param {Participations} clientSideParticipations
16
14
  * @returns ConsentlessPageTargeting
17
15
  */
18
- declare const buildPageTargetingConsentless: (consentState: ConsentState, adFree: boolean, countryCode: CountryCode, clientSideParticipations: Participations) => ConsentlessPageTargeting;
16
+ declare const buildPageTargetingConsentless: (consentState: ConsentState, adFree: boolean, clientSideParticipations: Participations) => ConsentlessPageTargeting;
19
17
  export { buildPageTargetingConsentless };
@@ -29,12 +29,11 @@ const isConsentlessKey = (key) => consentlessTargetingKeys.includes(key);
29
29
  *
30
30
  * @param {ConsentState} consentState
31
31
  * @param {boolean} adFree
32
- * @param {CountryCode} countryCode
33
32
  * @param {Participations} clientSideParticipations
34
33
  * @returns ConsentlessPageTargeting
35
34
  */
36
- const buildPageTargetingConsentless = (consentState, adFree, countryCode, clientSideParticipations) => {
37
- const consentedPageTargeting = buildPageTargeting(consentState, adFree, countryCode, clientSideParticipations);
35
+ const buildPageTargetingConsentless = (consentState, adFree, clientSideParticipations) => {
36
+ const consentedPageTargeting = buildPageTargeting(consentState, adFree, clientSideParticipations);
38
37
  return Object.fromEntries(Object.entries(consentedPageTargeting).filter(([k]) => isConsentlessKey(k)));
39
38
  };
40
39
  export { buildPageTargetingConsentless };
@@ -34,6 +34,6 @@ declare type PageTargeting = PartialWithNulls<{
34
34
  vl: string;
35
35
  [_: string]: string | string[];
36
36
  } & SharedTargeting>;
37
- declare const buildPageTargeting: (consentState: ConsentState, adFree: boolean, countryCode: CountryCode, clientSideParticipations: Participations) => PageTargeting;
37
+ declare const buildPageTargeting: (consentState: ConsentState, adFree: boolean, clientSideParticipations: Participations) => PageTargeting;
38
38
  export { buildPageTargeting };
39
39
  export type { PageTargeting };
@@ -1,5 +1,6 @@
1
1
  import { cmp } from '@guardian/consent-management-platform';
2
2
  import { getCookie, isString } from '@guardian/libs';
3
+ import { getLocale } from '../lib/get-locale';
3
4
  import { getContentTargeting } from './content';
4
5
  import { getPersonalisedTargeting } from './personalised';
5
6
  import { getSessionTargeting } from './session';
@@ -20,7 +21,7 @@ const filterEmptyValues = (pageTargets) => {
20
21
  }
21
22
  return filtered;
22
23
  };
23
- const buildPageTargeting = (consentState, adFree, countryCode, clientSideParticipations) => {
24
+ const buildPageTargeting = (consentState, adFree, clientSideParticipations) => {
24
25
  const { page, isDotcomRendering } = window.guardian.config;
25
26
  const adFreeTargeting = adFree ? { af: 't' } : {};
26
27
  const contentTargeting = getContentTargeting({
@@ -36,7 +37,7 @@ const buildPageTargeting = (consentState, adFree, countryCode, clientSidePartici
36
37
  const getReferrer = () => document.referrer || '';
37
38
  const sessionTargeting = getSessionTargeting({
38
39
  adTest: getCookie({ name: 'adtest', shouldMemoize: true }),
39
- countryCode,
40
+ countryCode: getLocale(),
40
41
  isSignedIn: !!getCookie({ name: 'GU_U' }),
41
42
  pageViewId: window.guardian.config.ophan.pageViewId,
42
43
  participations: {
@@ -21,6 +21,7 @@ export declare type GetThirdPartyTag = (arg0: {
21
21
  export declare type GuardianAnalyticsConfig = {
22
22
  trackers: Record<string, string>;
23
23
  };
24
+ export declare type Edition = 'UK' | 'AU' | 'US';
24
25
  export declare type GuardianWindowConfig = {
25
26
  googleAnalytics?: GuardianAnalyticsConfig;
26
27
  isDotcomRendering: boolean;
@@ -30,11 +31,11 @@ export declare type GuardianWindowConfig = {
30
31
  };
31
32
  page: {
32
33
  sharedAdTargeting?: Record<string, string | string[]>;
33
- pageAdTargeting?: Record<string, string | string[]>;
34
34
  isSensitive: boolean;
35
35
  pageId: string;
36
36
  section: string;
37
37
  videoDuration: number;
38
+ edition: Edition;
38
39
  };
39
40
  tests?: {
40
41
  [key: `${string}Control`]: 'control';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guardian/commercial-core",
3
- "version": "4.16.0",
3
+ "version": "4.18.0",
4
4
  "description": "Guardian advertising business logic",
5
5
  "homepage": "https://github.com/guardian/commercial-core#readme",
6
6
  "bugs": {