@guardian/commercial-core 4.14.0 → 4.16.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.
@@ -23,6 +23,7 @@ declare class AdSize extends Array<number> {
23
23
  constructor([width, height]: [number, number]);
24
24
  toString(): AdSizeString;
25
25
  toArray(): number[];
26
+ isProxy(): boolean;
26
27
  get width(): number;
27
28
  get height(): number;
28
29
  }
@@ -39,6 +40,11 @@ declare const standardAdSizes: {
39
40
  '300x1050': AdSize;
40
41
  '160x600': AdSize;
41
42
  };
43
+ declare const outstreamSizes: {
44
+ outstreamDesktop: AdSize;
45
+ outstreamGoogleDesktop: AdSize;
46
+ outstreamMobile: AdSize;
47
+ };
42
48
  declare const adSizes: Record<SizeKeys, AdSize>;
43
49
  /**
44
50
  * mark: 432b3a46-90c1-4573-90d3-2400b51af8d0
@@ -51,4 +57,4 @@ export declare const _: {
51
57
  createAdSize: (width: number, height: number) => AdSize;
52
58
  };
53
59
  export type { AdSizeString, AdSize, SizeKeys, SizeMapping, SlotSizeMappings, SlotName, };
54
- export { adSizes, standardAdSizes, getAdSize, slotSizeMappings, createAdSize };
60
+ export { adSizes, standardAdSizes, outstreamSizes, getAdSize, slotSizeMappings, createAdSize, };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createAdSize = exports.slotSizeMappings = exports.getAdSize = exports.standardAdSizes = exports.adSizes = exports._ = void 0;
3
+ exports.createAdSize = exports.slotSizeMappings = exports.getAdSize = exports.outstreamSizes = exports.standardAdSizes = exports.adSizes = exports._ = void 0;
4
4
  /**
5
5
  * Store ad sizes in a way that is compatible with google-tag but also accessible via
6
6
  * more semantic `width`/`height` properties and keep things readonly.
@@ -32,6 +32,15 @@ class AdSize extends Array {
32
32
  toArray() {
33
33
  return [this[0], this[1]];
34
34
  }
35
+ // The advert size is not reflective of the actual size of the advert.
36
+ // For example, fluid ads and Guardian merch ads are larger than the dimensions
37
+ isProxy() {
38
+ const isOutOfPage = this.width === 1 && this.height === 1;
39
+ const isEmpty = this.width === 2 && this.height === 2;
40
+ const isFluid = this.toString() === 'fluid';
41
+ const isMerch = this.width === 88;
42
+ return isOutOfPage || isEmpty || isFluid || isMerch;
43
+ }
35
44
  get width() {
36
45
  return this[0];
37
46
  }
@@ -51,6 +60,7 @@ const namedStandardAdSizes = {
51
60
  mpu: createAdSize(300, 250),
52
61
  portrait: createAdSize(300, 1050),
53
62
  skyscraper: createAdSize(160, 600),
63
+ cascade: createAdSize(940, 230),
54
64
  };
55
65
  const standardAdSizes = {
56
66
  '970x250': namedStandardAdSizes.billboard,
@@ -61,6 +71,12 @@ const standardAdSizes = {
61
71
  '160x600': namedStandardAdSizes.skyscraper,
62
72
  };
63
73
  exports.standardAdSizes = standardAdSizes;
74
+ const outstreamSizes = {
75
+ outstreamDesktop: createAdSize(620, 350),
76
+ outstreamGoogleDesktop: createAdSize(550, 310),
77
+ outstreamMobile: createAdSize(300, 197),
78
+ };
79
+ exports.outstreamSizes = outstreamSizes;
64
80
  const dfpProprietaryAdSizes = {
65
81
  fluid: createAdSize(0, 0),
66
82
  googleCard: createAdSize(300, 274),
@@ -73,14 +89,11 @@ const guardianProprietaryAdSizes = {
73
89
  merchandising: createAdSize(88, 88),
74
90
  merchandisingHigh: createAdSize(88, 87),
75
91
  merchandisingHighAdFeature: createAdSize(88, 89),
76
- outstreamDesktop: createAdSize(620, 350),
77
- outstreamGoogleDesktop: createAdSize(550, 310),
78
- outstreamMobile: createAdSize(300, 197),
79
- cascade: createAdSize(940, 230),
80
92
  };
81
93
  const adSizes = {
82
94
  ...namedStandardAdSizes,
83
95
  ...standardAdSizes,
96
+ ...outstreamSizes,
84
97
  ...dfpProprietaryAdSizes,
85
98
  ...guardianProprietaryAdSizes,
86
99
  };
@@ -7,7 +7,7 @@ export { remarketing } from './third-party-tags/remarketing';
7
7
  export { EventTimer } from './event-timer';
8
8
  export { bypassCommercialMetricsSampling, initCommercialMetrics, } from './send-commercial-metrics';
9
9
  export type { ThirdPartyTag } from './types';
10
- export { adSizes, standardAdSizes, getAdSize, slotSizeMappings, createAdSize, } from './ad-sizes';
10
+ export { adSizes, createAdSize, getAdSize, outstreamSizes, slotSizeMappings, standardAdSizes, } from './ad-sizes';
11
11
  export { isBreakpoint } from './lib/breakpoint';
12
12
  export type { Breakpoint } from './lib/breakpoint';
13
13
  export type { SizeKeys, AdSizeString, AdSize, SizeMapping, SlotSizeMappings, SlotName, } from './ad-sizes';
@@ -35,4 +35,5 @@ export { init as initMessenger } from './messenger';
35
35
  export type { RegisterListener, RegisterPersistentListener, RespondProxy, } from './messenger';
36
36
  export { postMessage } from './messenger/post-message';
37
37
  export { buildPageTargeting } from './targeting/build-page-targeting';
38
+ export { buildPageTargetingConsentless } from './targeting/build-page-targeting-consentless';
38
39
  export type { PageTargeting } from './targeting/build-page-targeting';
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.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.createAdSize = exports.slotSizeMappings = exports.getAdSize = exports.standardAdSizes = exports.adSizes = exports.initCommercialMetrics = exports.bypassCommercialMetricsSampling = exports.EventTimer = exports.remarketing = exports.inizio = exports.twitter = exports.fbPixel = exports.permutive = exports.ias = void 0;
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;
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");
@@ -44,10 +44,11 @@ Object.defineProperty(exports, "bypassCommercialMetricsSampling", { enumerable:
44
44
  Object.defineProperty(exports, "initCommercialMetrics", { enumerable: true, get: function () { return send_commercial_metrics_1.initCommercialMetrics; } });
45
45
  var ad_sizes_1 = require("./ad-sizes");
46
46
  Object.defineProperty(exports, "adSizes", { enumerable: true, get: function () { return ad_sizes_1.adSizes; } });
47
- Object.defineProperty(exports, "standardAdSizes", { enumerable: true, get: function () { return ad_sizes_1.standardAdSizes; } });
47
+ Object.defineProperty(exports, "createAdSize", { enumerable: true, get: function () { return ad_sizes_1.createAdSize; } });
48
48
  Object.defineProperty(exports, "getAdSize", { enumerable: true, get: function () { return ad_sizes_1.getAdSize; } });
49
+ Object.defineProperty(exports, "outstreamSizes", { enumerable: true, get: function () { return ad_sizes_1.outstreamSizes; } });
49
50
  Object.defineProperty(exports, "slotSizeMappings", { enumerable: true, get: function () { return ad_sizes_1.slotSizeMappings; } });
50
- Object.defineProperty(exports, "createAdSize", { enumerable: true, get: function () { return ad_sizes_1.createAdSize; } });
51
+ Object.defineProperty(exports, "standardAdSizes", { enumerable: true, get: function () { return ad_sizes_1.standardAdSizes; } });
51
52
  var breakpoint_1 = require("./lib/breakpoint");
52
53
  Object.defineProperty(exports, "isBreakpoint", { enumerable: true, get: function () { return breakpoint_1.isBreakpoint; } });
53
54
  var detect_ad_blocker_1 = require("./detect-ad-blocker");
@@ -87,3 +88,5 @@ var post_message_1 = require("./messenger/post-message");
87
88
  Object.defineProperty(exports, "postMessage", { enumerable: true, get: function () { return post_message_1.postMessage; } });
88
89
  var build_page_targeting_1 = require("./targeting/build-page-targeting");
89
90
  Object.defineProperty(exports, "buildPageTargeting", { enumerable: true, get: function () { return build_page_targeting_1.buildPageTargeting; } });
91
+ var build_page_targeting_consentless_1 = require("./targeting/build-page-targeting-consentless");
92
+ Object.defineProperty(exports, "buildPageTargetingConsentless", { enumerable: true, get: function () { return build_page_targeting_consentless_1.buildPageTargetingConsentless; } });
@@ -0,0 +1,19 @@
1
+ import type { Participations } from '@guardian/ab-core';
2
+ import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
3
+ import type { CountryCode } from '@guardian/libs';
4
+ import type { PageTargeting } from './build-page-targeting';
5
+ 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
+ declare type ConsentlessTargetingKeys = typeof consentlessTargetingKeys[number];
7
+ declare type ConsentlessPageTargeting = Partial<Pick<PageTargeting, ConsentlessTargetingKeys>>;
8
+ /**
9
+ * Call buildPageTargeting then filter out the keys that are not needed for
10
+ * consentless targeting.
11
+ *
12
+ * @param {ConsentState} consentState
13
+ * @param {boolean} adFree
14
+ * @param {CountryCode} countryCode
15
+ * @param {Participations} clientSideParticipations
16
+ * @returns ConsentlessPageTargeting
17
+ */
18
+ declare const buildPageTargetingConsentless: (consentState: ConsentState, adFree: boolean, countryCode: CountryCode, clientSideParticipations: Participations) => ConsentlessPageTargeting;
19
+ export { buildPageTargetingConsentless };
@@ -0,0 +1,43 @@
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
+ 'rp',
17
+ 's',
18
+ 'se',
19
+ 'sens',
20
+ 'sh',
21
+ 'si',
22
+ 'skinsize',
23
+ 'su',
24
+ 'tn',
25
+ 'url',
26
+ 'urlkw',
27
+ ];
28
+ const isConsentlessKey = (key) => consentlessTargetingKeys.includes(key);
29
+ /**
30
+ * Call buildPageTargeting then filter out the keys that are not needed for
31
+ * consentless targeting.
32
+ *
33
+ * @param {ConsentState} consentState
34
+ * @param {boolean} adFree
35
+ * @param {CountryCode} countryCode
36
+ * @param {Participations} clientSideParticipations
37
+ * @returns ConsentlessPageTargeting
38
+ */
39
+ const buildPageTargetingConsentless = (consentState, adFree, countryCode, clientSideParticipations) => {
40
+ const consentedPageTargeting = (0, build_page_targeting_1.buildPageTargeting)(consentState, adFree, countryCode, clientSideParticipations);
41
+ return Object.fromEntries(Object.entries(consentedPageTargeting).filter(([k]) => isConsentlessKey(k)));
42
+ };
43
+ exports.buildPageTargetingConsentless = buildPageTargetingConsentless;
@@ -23,6 +23,7 @@ declare class AdSize extends Array<number> {
23
23
  constructor([width, height]: [number, number]);
24
24
  toString(): AdSizeString;
25
25
  toArray(): number[];
26
+ isProxy(): boolean;
26
27
  get width(): number;
27
28
  get height(): number;
28
29
  }
@@ -39,6 +40,11 @@ declare const standardAdSizes: {
39
40
  '300x1050': AdSize;
40
41
  '160x600': AdSize;
41
42
  };
43
+ declare const outstreamSizes: {
44
+ outstreamDesktop: AdSize;
45
+ outstreamGoogleDesktop: AdSize;
46
+ outstreamMobile: AdSize;
47
+ };
42
48
  declare const adSizes: Record<SizeKeys, AdSize>;
43
49
  /**
44
50
  * mark: 432b3a46-90c1-4573-90d3-2400b51af8d0
@@ -51,4 +57,4 @@ export declare const _: {
51
57
  createAdSize: (width: number, height: number) => AdSize;
52
58
  };
53
59
  export type { AdSizeString, AdSize, SizeKeys, SizeMapping, SlotSizeMappings, SlotName, };
54
- export { adSizes, standardAdSizes, getAdSize, slotSizeMappings, createAdSize };
60
+ export { adSizes, standardAdSizes, outstreamSizes, getAdSize, slotSizeMappings, createAdSize, };
@@ -29,6 +29,15 @@ class AdSize extends Array {
29
29
  toArray() {
30
30
  return [this[0], this[1]];
31
31
  }
32
+ // The advert size is not reflective of the actual size of the advert.
33
+ // For example, fluid ads and Guardian merch ads are larger than the dimensions
34
+ isProxy() {
35
+ const isOutOfPage = this.width === 1 && this.height === 1;
36
+ const isEmpty = this.width === 2 && this.height === 2;
37
+ const isFluid = this.toString() === 'fluid';
38
+ const isMerch = this.width === 88;
39
+ return isOutOfPage || isEmpty || isFluid || isMerch;
40
+ }
32
41
  get width() {
33
42
  return this[0];
34
43
  }
@@ -47,6 +56,7 @@ const namedStandardAdSizes = {
47
56
  mpu: createAdSize(300, 250),
48
57
  portrait: createAdSize(300, 1050),
49
58
  skyscraper: createAdSize(160, 600),
59
+ cascade: createAdSize(940, 230),
50
60
  };
51
61
  const standardAdSizes = {
52
62
  '970x250': namedStandardAdSizes.billboard,
@@ -56,6 +66,11 @@ const standardAdSizes = {
56
66
  '300x1050': namedStandardAdSizes.portrait,
57
67
  '160x600': namedStandardAdSizes.skyscraper,
58
68
  };
69
+ const outstreamSizes = {
70
+ outstreamDesktop: createAdSize(620, 350),
71
+ outstreamGoogleDesktop: createAdSize(550, 310),
72
+ outstreamMobile: createAdSize(300, 197),
73
+ };
59
74
  const dfpProprietaryAdSizes = {
60
75
  fluid: createAdSize(0, 0),
61
76
  googleCard: createAdSize(300, 274),
@@ -68,14 +83,11 @@ const guardianProprietaryAdSizes = {
68
83
  merchandising: createAdSize(88, 88),
69
84
  merchandisingHigh: createAdSize(88, 87),
70
85
  merchandisingHighAdFeature: createAdSize(88, 89),
71
- outstreamDesktop: createAdSize(620, 350),
72
- outstreamGoogleDesktop: createAdSize(550, 310),
73
- outstreamMobile: createAdSize(300, 197),
74
- cascade: createAdSize(940, 230),
75
86
  };
76
87
  const adSizes = {
77
88
  ...namedStandardAdSizes,
78
89
  ...standardAdSizes,
90
+ ...outstreamSizes,
79
91
  ...dfpProprietaryAdSizes,
80
92
  ...guardianProprietaryAdSizes,
81
93
  };
@@ -257,4 +269,4 @@ const slotSizeMappings = {
257
269
  const getAdSize = (size) => adSizes[size];
258
270
  // Export for testing
259
271
  export const _ = { createAdSize };
260
- export { adSizes, standardAdSizes, getAdSize, slotSizeMappings, createAdSize };
272
+ export { adSizes, standardAdSizes, outstreamSizes, getAdSize, slotSizeMappings, createAdSize, };
@@ -7,7 +7,7 @@ export { remarketing } from './third-party-tags/remarketing';
7
7
  export { EventTimer } from './event-timer';
8
8
  export { bypassCommercialMetricsSampling, initCommercialMetrics, } from './send-commercial-metrics';
9
9
  export type { ThirdPartyTag } from './types';
10
- export { adSizes, standardAdSizes, getAdSize, slotSizeMappings, createAdSize, } from './ad-sizes';
10
+ export { adSizes, createAdSize, getAdSize, outstreamSizes, slotSizeMappings, standardAdSizes, } from './ad-sizes';
11
11
  export { isBreakpoint } from './lib/breakpoint';
12
12
  export type { Breakpoint } from './lib/breakpoint';
13
13
  export type { SizeKeys, AdSizeString, AdSize, SizeMapping, SlotSizeMappings, SlotName, } from './ad-sizes';
@@ -35,4 +35,5 @@ export { init as initMessenger } from './messenger';
35
35
  export type { RegisterListener, RegisterPersistentListener, RespondProxy, } from './messenger';
36
36
  export { postMessage } from './messenger/post-message';
37
37
  export { buildPageTargeting } from './targeting/build-page-targeting';
38
+ export { buildPageTargetingConsentless } from './targeting/build-page-targeting-consentless';
38
39
  export type { PageTargeting } from './targeting/build-page-targeting';
package/dist/esm/index.js CHANGED
@@ -7,7 +7,7 @@ export { inizio } from './third-party-tags/inizio';
7
7
  export { remarketing } from './third-party-tags/remarketing';
8
8
  export { EventTimer } from './event-timer';
9
9
  export { bypassCommercialMetricsSampling, initCommercialMetrics, } from './send-commercial-metrics';
10
- export { adSizes, standardAdSizes, getAdSize, slotSizeMappings, createAdSize, } from './ad-sizes';
10
+ export { adSizes, createAdSize, getAdSize, outstreamSizes, slotSizeMappings, standardAdSizes, } from './ad-sizes';
11
11
  export { isBreakpoint } from './lib/breakpoint';
12
12
  export { isAdBlockInUse } from './detect-ad-blocker';
13
13
  export { clearPermutiveSegments, getPermutiveSegments, getPermutivePFPSegments, } from './permutive';
@@ -27,3 +27,4 @@ export { pickTargetingValues } from './targeting/pick-targeting-values';
27
27
  export { init as initMessenger } from './messenger';
28
28
  export { postMessage } from './messenger/post-message';
29
29
  export { buildPageTargeting } from './targeting/build-page-targeting';
30
+ export { buildPageTargetingConsentless } from './targeting/build-page-targeting-consentless';
@@ -0,0 +1,19 @@
1
+ import type { Participations } from '@guardian/ab-core';
2
+ import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
3
+ import type { CountryCode } from '@guardian/libs';
4
+ import type { PageTargeting } from './build-page-targeting';
5
+ 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
+ declare type ConsentlessTargetingKeys = typeof consentlessTargetingKeys[number];
7
+ declare type ConsentlessPageTargeting = Partial<Pick<PageTargeting, ConsentlessTargetingKeys>>;
8
+ /**
9
+ * Call buildPageTargeting then filter out the keys that are not needed for
10
+ * consentless targeting.
11
+ *
12
+ * @param {ConsentState} consentState
13
+ * @param {boolean} adFree
14
+ * @param {CountryCode} countryCode
15
+ * @param {Participations} clientSideParticipations
16
+ * @returns ConsentlessPageTargeting
17
+ */
18
+ declare const buildPageTargetingConsentless: (consentState: ConsentState, adFree: boolean, countryCode: CountryCode, clientSideParticipations: Participations) => ConsentlessPageTargeting;
19
+ export { buildPageTargetingConsentless };
@@ -0,0 +1,40 @@
1
+ import { buildPageTargeting } from './build-page-targeting';
2
+ const consentlessTargetingKeys = [
3
+ 'ab',
4
+ 'at',
5
+ 'bl',
6
+ 'bp',
7
+ 'br',
8
+ 'cc',
9
+ 'ct',
10
+ 'dcre',
11
+ 'edition',
12
+ 'k',
13
+ 'rp',
14
+ 's',
15
+ 'se',
16
+ 'sens',
17
+ 'sh',
18
+ 'si',
19
+ 'skinsize',
20
+ 'su',
21
+ 'tn',
22
+ 'url',
23
+ 'urlkw',
24
+ ];
25
+ const isConsentlessKey = (key) => consentlessTargetingKeys.includes(key);
26
+ /**
27
+ * Call buildPageTargeting then filter out the keys that are not needed for
28
+ * consentless targeting.
29
+ *
30
+ * @param {ConsentState} consentState
31
+ * @param {boolean} adFree
32
+ * @param {CountryCode} countryCode
33
+ * @param {Participations} clientSideParticipations
34
+ * @returns ConsentlessPageTargeting
35
+ */
36
+ const buildPageTargetingConsentless = (consentState, adFree, countryCode, clientSideParticipations) => {
37
+ const consentedPageTargeting = buildPageTargeting(consentState, adFree, countryCode, clientSideParticipations);
38
+ return Object.fromEntries(Object.entries(consentedPageTargeting).filter(([k]) => isConsentlessKey(k)));
39
+ };
40
+ export { buildPageTargetingConsentless };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guardian/commercial-core",
3
- "version": "4.14.0",
3
+ "version": "4.16.0",
4
4
  "description": "Guardian advertising business logic",
5
5
  "homepage": "https://github.com/guardian/commercial-core#readme",
6
6
  "bugs": {