@guardian/commercial-core 4.20.0 → 4.21.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.
@@ -1,6 +1,5 @@
1
1
  import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
2
- import type { AdsConfig, AdsConfigDisabled, MaybeArray } from './types';
3
- declare type CustomParams = Record<string, MaybeArray<string | number | boolean>>;
2
+ import type { AdsConfig, AdsConfigDisabled, CustomParams } from './types';
4
3
  declare const disabledAds: AdsConfigDisabled;
5
4
  declare const buildAdsConfigWithConsent: (isAdFreeUser: boolean, adUnit: string, customParamsToMerge: CustomParams, consentState: ConsentState) => AdsConfig;
6
5
  export { buildAdsConfigWithConsent, disabledAds };
@@ -40,3 +40,4 @@ export { a9Apstag } from './__vendor/a9-apstag';
40
40
  export { ipsosMoriStub } from './__vendor/ipsos-mori';
41
41
  export { launchpad } from './__vendor/launchpad';
42
42
  export { pubmatic } from './__vendor/pubmatic';
43
+ export { buildImaAdTagUrl } from './targeting/youtube-ima';
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.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.permutive = exports.ias = void 0;
27
+ exports.buildImaAdTagUrl = 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.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");
@@ -97,3 +97,5 @@ var launchpad_1 = require("./__vendor/launchpad");
97
97
  Object.defineProperty(exports, "launchpad", { enumerable: true, get: function () { return launchpad_1.launchpad; } });
98
98
  var pubmatic_1 = require("./__vendor/pubmatic");
99
99
  Object.defineProperty(exports, "pubmatic", { enumerable: true, get: function () { return pubmatic_1.pubmatic; } });
100
+ var youtube_ima_1 = require("./targeting/youtube-ima");
101
+ Object.defineProperty(exports, "buildImaAdTagUrl", { enumerable: true, get: function () { return youtube_ima_1.buildImaAdTagUrl; } });
@@ -33,6 +33,7 @@ declare type PageTargeting = PartialWithNulls<{
33
33
  vl: string;
34
34
  [_: string]: string | string[];
35
35
  } & SharedTargeting>;
36
+ declare const filterValues: (pageTargets: Record<string, unknown>) => Record<string, string | string[]>;
36
37
  declare const buildPageTargeting: (consentState: ConsentState, adFree: boolean) => PageTargeting;
37
- export { buildPageTargeting };
38
+ export { buildPageTargeting, filterValues };
38
39
  export type { PageTargeting };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildPageTargeting = void 0;
3
+ exports.filterValues = 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
6
  const ab_localstorage_1 = require("../lib/ab-localstorage");
@@ -10,7 +10,7 @@ const personalised_1 = require("./personalised");
10
10
  const session_1 = require("./session");
11
11
  const shared_1 = require("./shared");
12
12
  const viewport_1 = require("./viewport");
13
- const filterEmptyValues = (pageTargets) => {
13
+ const filterValues = (pageTargets) => {
14
14
  const filtered = {};
15
15
  for (const key in pageTargets) {
16
16
  const value = pageTargets[key];
@@ -25,6 +25,7 @@ const filterEmptyValues = (pageTargets) => {
25
25
  }
26
26
  return filtered;
27
27
  };
28
+ exports.filterValues = filterValues;
28
29
  const buildPageTargeting = (consentState, adFree) => {
29
30
  const { page, isDotcomRendering } = window.guardian.config;
30
31
  const adFreeTargeting = adFree ? { af: 't' } : {};
@@ -72,8 +73,8 @@ const buildPageTargeting = (consentState, adFree) => {
72
73
  ...sessionTargeting,
73
74
  ...viewportTargeting,
74
75
  };
75
- // filter out empty values
76
- const pageTargeting = filterEmptyValues(pageTargets);
76
+ // filter !(string | string[]) and empty values
77
+ const pageTargeting = filterValues(pageTargets);
77
78
  return pageTargeting;
78
79
  };
79
80
  exports.buildPageTargeting = buildPageTargeting;
@@ -97,6 +97,7 @@ declare type AllParticipations = {
97
97
  [key: `${string}Variant`]: 'variant';
98
98
  };
99
99
  };
100
+ declare const experimentsTargeting: ({ clientSideParticipations, serverSideParticipations, }: AllParticipations) => SessionTargeting['ab'];
100
101
  declare type Session = {
101
102
  adTest: SessionTargeting['at'];
102
103
  countryCode: CountryCode;
@@ -107,4 +108,4 @@ declare type Session = {
107
108
  };
108
109
  declare const getSessionTargeting: ({ adTest, countryCode, isSignedIn, pageViewId, participations, referrer, }: Session) => SessionTargeting;
109
110
  export type { SessionTargeting, AllParticipations };
110
- export { getSessionTargeting };
111
+ export { getSessionTargeting, experimentsTargeting };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSessionTargeting = void 0;
3
+ exports.experimentsTargeting = exports.getSessionTargeting = void 0;
4
4
  const libs_1 = require("@guardian/libs");
5
5
  /* -- Types -- */
6
6
  const referrers = [
@@ -49,6 +49,7 @@ const experimentsTargeting = ({ clientSideParticipations, serverSideParticipatio
49
49
  }
50
50
  return [...clientSideExperiment, ...serverSideExperiments];
51
51
  };
52
+ exports.experimentsTargeting = experimentsTargeting;
52
53
  const getSessionTargeting = ({ adTest, countryCode, isSignedIn, pageViewId, participations, referrer, }) => ({
53
54
  ab: experimentsTargeting(participations),
54
55
  at: adTest,
@@ -0,0 +1,3 @@
1
+ import type { CustomParams } from '../types';
2
+ declare const buildImaAdTagUrl: (adUnit: string, customParams: CustomParams) => string;
3
+ export { buildImaAdTagUrl };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildImaAdTagUrl = void 0;
4
+ const build_page_targeting_1 = require("./build-page-targeting");
5
+ /**
6
+ * @param {Record<string, MaybeArray<string|number|boolean>>
7
+ * Follows https://support.google.com/admanager/answer/1080597
8
+ */
9
+ const encodeVastTagKeyValues = (query) => {
10
+ const unencodedUrl = Object.entries(query)
11
+ .map(([key, value]) => {
12
+ const queryValue = Array.isArray(value)
13
+ ? value.join(',')
14
+ : String(value);
15
+ return `${key}=${queryValue}`;
16
+ })
17
+ .join('&');
18
+ return unencodedUrl
19
+ .replace(/=/g, '%3D')
20
+ .replace(/&/g, '%26')
21
+ .replace(/,/g, '%2C');
22
+ };
23
+ const buildImaAdTagUrl = (adUnit, customParams) => {
24
+ // TODO: Add regular build-page-targeting to
25
+ // get all targeting including ab participations.
26
+ // For now hardcode adtest (at)
27
+ const mergedCustomParams = { ...customParams, at: 'fixed-puppies' };
28
+ const queryParams = {
29
+ iu: adUnit,
30
+ description_url: '[placeholder]',
31
+ tfcd: '0',
32
+ npa: '0',
33
+ sz: '480x360|480x361|400x300',
34
+ gdfp_req: '1',
35
+ output: 'vast',
36
+ unviewed_position_start: '1',
37
+ env: 'vp',
38
+ impl: 's',
39
+ correlator: '',
40
+ vad_type: 'linear',
41
+ vpos: 'preroll',
42
+ cust_params: encodeVastTagKeyValues((0, build_page_targeting_1.filterValues)(mergedCustomParams)),
43
+ };
44
+ const queryParamsArray = [];
45
+ for (const [k, v] of Object.entries(queryParams)) {
46
+ queryParamsArray.push(`${k}=${v}`);
47
+ }
48
+ return ('https://pubads.g.doubleclick.net/gampad/ads?' +
49
+ queryParamsArray.join('&'));
50
+ };
51
+ exports.buildImaAdTagUrl = buildImaAdTagUrl;
@@ -1,6 +1,5 @@
1
1
  import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
2
- import type { AdsConfig, AdsConfigDisabled, MaybeArray } from './types';
3
- declare type CustomParams = Record<string, MaybeArray<string | number | boolean>>;
2
+ import type { AdsConfig, AdsConfigDisabled, CustomParams } from './types';
4
3
  declare const disabledAds: AdsConfigDisabled;
5
4
  declare const buildAdsConfigWithConsent: (isAdFreeUser: boolean, adUnit: string, customParamsToMerge: CustomParams, consentState: ConsentState) => AdsConfig;
6
5
  export { buildAdsConfigWithConsent, disabledAds };
@@ -40,3 +40,4 @@ export { a9Apstag } from './__vendor/a9-apstag';
40
40
  export { ipsosMoriStub } from './__vendor/ipsos-mori';
41
41
  export { launchpad } from './__vendor/launchpad';
42
42
  export { pubmatic } from './__vendor/pubmatic';
43
+ export { buildImaAdTagUrl } from './targeting/youtube-ima';
package/dist/esm/index.js CHANGED
@@ -32,3 +32,4 @@ export { a9Apstag } from './__vendor/a9-apstag';
32
32
  export { ipsosMoriStub } from './__vendor/ipsos-mori';
33
33
  export { launchpad } from './__vendor/launchpad';
34
34
  export { pubmatic } from './__vendor/pubmatic';
35
+ export { buildImaAdTagUrl } from './targeting/youtube-ima';
@@ -33,6 +33,7 @@ declare type PageTargeting = PartialWithNulls<{
33
33
  vl: string;
34
34
  [_: string]: string | string[];
35
35
  } & SharedTargeting>;
36
+ declare const filterValues: (pageTargets: Record<string, unknown>) => Record<string, string | string[]>;
36
37
  declare const buildPageTargeting: (consentState: ConsentState, adFree: boolean) => PageTargeting;
37
- export { buildPageTargeting };
38
+ export { buildPageTargeting, filterValues };
38
39
  export type { PageTargeting };
@@ -7,7 +7,7 @@ import { getPersonalisedTargeting } from './personalised';
7
7
  import { getSessionTargeting } from './session';
8
8
  import { getSharedTargeting } from './shared';
9
9
  import { getViewportTargeting } from './viewport';
10
- const filterEmptyValues = (pageTargets) => {
10
+ const filterValues = (pageTargets) => {
11
11
  const filtered = {};
12
12
  for (const key in pageTargets) {
13
13
  const value = pageTargets[key];
@@ -69,8 +69,8 @@ const buildPageTargeting = (consentState, adFree) => {
69
69
  ...sessionTargeting,
70
70
  ...viewportTargeting,
71
71
  };
72
- // filter out empty values
73
- const pageTargeting = filterEmptyValues(pageTargets);
72
+ // filter !(string | string[]) and empty values
73
+ const pageTargeting = filterValues(pageTargets);
74
74
  return pageTargeting;
75
75
  };
76
- export { buildPageTargeting };
76
+ export { buildPageTargeting, filterValues };
@@ -97,6 +97,7 @@ declare type AllParticipations = {
97
97
  [key: `${string}Variant`]: 'variant';
98
98
  };
99
99
  };
100
+ declare const experimentsTargeting: ({ clientSideParticipations, serverSideParticipations, }: AllParticipations) => SessionTargeting['ab'];
100
101
  declare type Session = {
101
102
  adTest: SessionTargeting['at'];
102
103
  countryCode: CountryCode;
@@ -107,4 +108,4 @@ declare type Session = {
107
108
  };
108
109
  declare const getSessionTargeting: ({ adTest, countryCode, isSignedIn, pageViewId, participations, referrer, }: Session) => SessionTargeting;
109
110
  export type { SessionTargeting, AllParticipations };
110
- export { getSessionTargeting };
111
+ export { getSessionTargeting, experimentsTargeting };
@@ -54,4 +54,4 @@ const getSessionTargeting = ({ adTest, countryCode, isSignedIn, pageViewId, part
54
54
  ref: getReferrer(referrer),
55
55
  si: isSignedIn ? 't' : 'f',
56
56
  });
57
- export { getSessionTargeting };
57
+ export { getSessionTargeting, experimentsTargeting };
@@ -0,0 +1,3 @@
1
+ import type { CustomParams } from '../types';
2
+ declare const buildImaAdTagUrl: (adUnit: string, customParams: CustomParams) => string;
3
+ export { buildImaAdTagUrl };
@@ -0,0 +1,48 @@
1
+ import { filterValues } from './build-page-targeting';
2
+ /**
3
+ * @param {Record<string, MaybeArray<string|number|boolean>>
4
+ * Follows https://support.google.com/admanager/answer/1080597
5
+ */
6
+ const encodeVastTagKeyValues = (query) => {
7
+ const unencodedUrl = Object.entries(query)
8
+ .map(([key, value]) => {
9
+ const queryValue = Array.isArray(value)
10
+ ? value.join(',')
11
+ : String(value);
12
+ return `${key}=${queryValue}`;
13
+ })
14
+ .join('&');
15
+ return unencodedUrl
16
+ .replace(/=/g, '%3D')
17
+ .replace(/&/g, '%26')
18
+ .replace(/,/g, '%2C');
19
+ };
20
+ const buildImaAdTagUrl = (adUnit, customParams) => {
21
+ // TODO: Add regular build-page-targeting to
22
+ // get all targeting including ab participations.
23
+ // For now hardcode adtest (at)
24
+ const mergedCustomParams = { ...customParams, at: 'fixed-puppies' };
25
+ const queryParams = {
26
+ iu: adUnit,
27
+ description_url: '[placeholder]',
28
+ tfcd: '0',
29
+ npa: '0',
30
+ sz: '480x360|480x361|400x300',
31
+ gdfp_req: '1',
32
+ output: 'vast',
33
+ unviewed_position_start: '1',
34
+ env: 'vp',
35
+ impl: 's',
36
+ correlator: '',
37
+ vad_type: 'linear',
38
+ vpos: 'preroll',
39
+ cust_params: encodeVastTagKeyValues(filterValues(mergedCustomParams)),
40
+ };
41
+ const queryParamsArray = [];
42
+ for (const [k, v] of Object.entries(queryParams)) {
43
+ queryParamsArray.push(`${k}=${v}`);
44
+ }
45
+ return ('https://pubads.g.doubleclick.net/gampad/ads?' +
46
+ queryParamsArray.join('&'));
47
+ };
48
+ export { buildImaAdTagUrl };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guardian/commercial-core",
3
- "version": "4.20.0",
3
+ "version": "4.21.0",
4
4
  "description": "Guardian advertising business logic",
5
5
  "homepage": "https://github.com/guardian/commercial-core#readme",
6
6
  "bugs": {