@guardian/commercial-core 4.21.0 → 4.22.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.
@@ -35,7 +35,7 @@ interface EventTimerProperties {
35
35
  hasLabsContainer?: boolean;
36
36
  labsUrl?: string;
37
37
  }
38
- export declare class EventTimer {
38
+ declare class EventTimer {
39
39
  private _events;
40
40
  private static _externallyDefinedEventNames;
41
41
  startTS: DOMHighResTimeStamp;
@@ -87,4 +87,4 @@ export declare class EventTimer {
87
87
  private mark;
88
88
  private trackInGA;
89
89
  }
90
- export {};
90
+ export { EventTimer };
@@ -2,11 +2,15 @@
2
2
  import type { GoogleTagParams, GoogleTrackConversionObject, GuardianWindowConfig } from './types';
3
3
  import type { EventTimer } from '.';
4
4
  declare global {
5
+ type ConnectionType = 'bluetooth' | 'cellular' | 'ethernet' | 'mixed' | 'none' | 'other' | 'unknown' | 'wifi';
5
6
  interface NetworkInformation extends EventTarget {
6
- readonly type: ConnectionType;
7
+ readonly type?: ConnectionType;
7
8
  readonly downlink?: number;
8
9
  readonly effectiveType?: string;
9
10
  }
11
+ interface Navigator {
12
+ readonly connection: NetworkInformation;
13
+ }
10
14
  interface Window {
11
15
  google_trackConversion?: (arg0: GoogleTrackConversionObject) => void;
12
16
  google_tag_params?: GoogleTagParams;
@@ -21,5 +21,5 @@ declare type ValidTargetingObject<Base> = ConditionalExcept<Base, null | undefin
21
21
  * clean.invalid
22
22
  * ```
23
23
  */
24
- export declare const pickTargetingValues: <T extends Record<string, string | readonly string[] | undefined>>(obj: T) => import("type-fest").Except<T, NonNullable<{ [Key in keyof T]: T[Key] extends number | boolean | "" | never[] | readonly [] | readonly [""] | null | undefined ? Key : never; }[keyof T]>>;
24
+ export declare const pickTargetingValues: <T extends Record<string, string | readonly string[] | undefined>>(obj: T) => import("type-fest").Except<T, import("type-fest").ConditionalKeys<T, number | boolean | "" | never[] | readonly [] | readonly [""] | null | undefined>>;
25
25
  export {};
@@ -1,3 +1,4 @@
1
+ import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
1
2
  import type { CustomParams } from '../types';
2
- declare const buildImaAdTagUrl: (adUnit: string, customParams: CustomParams) => string;
3
+ declare const buildImaAdTagUrl: (adUnit: string, customParams: CustomParams, consentState: ConsentState) => string;
3
4
  export { buildImaAdTagUrl };
@@ -6,28 +6,22 @@ const build_page_targeting_1 = require("./build-page-targeting");
6
6
  * @param {Record<string, MaybeArray<string|number|boolean>>
7
7
  * Follows https://support.google.com/admanager/answer/1080597
8
8
  */
9
- const encodeVastTagKeyValues = (query) => {
10
- const unencodedUrl = Object.entries(query)
9
+ const encodeCustomParams = (params) => {
10
+ const encodedParams = Object.entries(params)
11
11
  .map(([key, value]) => {
12
12
  const queryValue = Array.isArray(value)
13
13
  ? value.join(',')
14
14
  : String(value);
15
- return `${key}=${queryValue}`;
15
+ return `${key}=${encodeURIComponent(queryValue)}`;
16
16
  })
17
17
  .join('&');
18
- return unencodedUrl
19
- .replace(/=/g, '%3D')
20
- .replace(/&/g, '%26')
21
- .replace(/,/g, '%2C');
18
+ return encodedParams;
22
19
  };
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' };
20
+ const buildImaAdTagUrl = (adUnit, customParams, consentState) => {
21
+ const pageTargeting = (0, build_page_targeting_1.buildPageTargeting)(consentState, false);
22
+ const mergedCustomParams = { ...customParams, ...pageTargeting };
28
23
  const queryParams = {
29
24
  iu: adUnit,
30
- description_url: '[placeholder]',
31
25
  tfcd: '0',
32
26
  npa: '0',
33
27
  sz: '480x360|480x361|400x300',
@@ -36,10 +30,14 @@ const buildImaAdTagUrl = (adUnit, customParams) => {
36
30
  unviewed_position_start: '1',
37
31
  env: 'vp',
38
32
  impl: 's',
39
- correlator: '',
40
33
  vad_type: 'linear',
41
34
  vpos: 'preroll',
42
- cust_params: encodeVastTagKeyValues((0, build_page_targeting_1.filterValues)(mergedCustomParams)),
35
+ /**
36
+ * cust_params string is encoded
37
+ * cust_params values are also encoded so they will get double encoded
38
+ * this ensures any values with separator chars (=&,) do not conflict with the main string
39
+ */
40
+ cust_params: encodeURIComponent(encodeCustomParams((0, build_page_targeting_1.filterValues)(mergedCustomParams))),
43
41
  };
44
42
  const queryParamsArray = [];
45
43
  for (const [k, v] of Object.entries(queryParams)) {
@@ -35,7 +35,7 @@ interface EventTimerProperties {
35
35
  hasLabsContainer?: boolean;
36
36
  labsUrl?: string;
37
37
  }
38
- export declare class EventTimer {
38
+ declare class EventTimer {
39
39
  private _events;
40
40
  private static _externallyDefinedEventNames;
41
41
  startTS: DOMHighResTimeStamp;
@@ -87,4 +87,4 @@ export declare class EventTimer {
87
87
  private mark;
88
88
  private trackInGA;
89
89
  }
90
- export {};
90
+ export { EventTimer };
@@ -5,7 +5,7 @@ class Event {
5
5
  this.ts = mark.startTime;
6
6
  }
7
7
  }
8
- export class EventTimer {
8
+ class EventTimer {
9
9
  constructor() {
10
10
  this._events = [];
11
11
  this.startTS = window.performance.now();
@@ -177,3 +177,4 @@ EventTimer._externallyDefinedEventNames = [
177
177
  'cmp-aus-ui-displayed',
178
178
  'cmp-aus-got-consent',
179
179
  ];
180
+ export { EventTimer };
@@ -2,11 +2,15 @@
2
2
  import type { GoogleTagParams, GoogleTrackConversionObject, GuardianWindowConfig } from './types';
3
3
  import type { EventTimer } from '.';
4
4
  declare global {
5
+ type ConnectionType = 'bluetooth' | 'cellular' | 'ethernet' | 'mixed' | 'none' | 'other' | 'unknown' | 'wifi';
5
6
  interface NetworkInformation extends EventTarget {
6
- readonly type: ConnectionType;
7
+ readonly type?: ConnectionType;
7
8
  readonly downlink?: number;
8
9
  readonly effectiveType?: string;
9
10
  }
11
+ interface Navigator {
12
+ readonly connection: NetworkInformation;
13
+ }
10
14
  interface Window {
11
15
  google_trackConversion?: (arg0: GoogleTrackConversionObject) => void;
12
16
  google_tag_params?: GoogleTagParams;
@@ -21,5 +21,5 @@ declare type ValidTargetingObject<Base> = ConditionalExcept<Base, null | undefin
21
21
  * clean.invalid
22
22
  * ```
23
23
  */
24
- export declare const pickTargetingValues: <T extends Record<string, string | readonly string[] | undefined>>(obj: T) => import("type-fest").Except<T, NonNullable<{ [Key in keyof T]: T[Key] extends number | boolean | "" | never[] | readonly [] | readonly [""] | null | undefined ? Key : never; }[keyof T]>>;
24
+ export declare const pickTargetingValues: <T extends Record<string, string | readonly string[] | undefined>>(obj: T) => import("type-fest").Except<T, import("type-fest").ConditionalKeys<T, number | boolean | "" | never[] | readonly [] | readonly [""] | null | undefined>>;
25
25
  export {};
@@ -1,3 +1,4 @@
1
+ import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
1
2
  import type { CustomParams } from '../types';
2
- declare const buildImaAdTagUrl: (adUnit: string, customParams: CustomParams) => string;
3
+ declare const buildImaAdTagUrl: (adUnit: string, customParams: CustomParams, consentState: ConsentState) => string;
3
4
  export { buildImaAdTagUrl };
@@ -1,30 +1,24 @@
1
- import { filterValues } from './build-page-targeting';
1
+ import { buildPageTargeting, filterValues } from './build-page-targeting';
2
2
  /**
3
3
  * @param {Record<string, MaybeArray<string|number|boolean>>
4
4
  * Follows https://support.google.com/admanager/answer/1080597
5
5
  */
6
- const encodeVastTagKeyValues = (query) => {
7
- const unencodedUrl = Object.entries(query)
6
+ const encodeCustomParams = (params) => {
7
+ const encodedParams = Object.entries(params)
8
8
  .map(([key, value]) => {
9
9
  const queryValue = Array.isArray(value)
10
10
  ? value.join(',')
11
11
  : String(value);
12
- return `${key}=${queryValue}`;
12
+ return `${key}=${encodeURIComponent(queryValue)}`;
13
13
  })
14
14
  .join('&');
15
- return unencodedUrl
16
- .replace(/=/g, '%3D')
17
- .replace(/&/g, '%26')
18
- .replace(/,/g, '%2C');
15
+ return encodedParams;
19
16
  };
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' };
17
+ const buildImaAdTagUrl = (adUnit, customParams, consentState) => {
18
+ const pageTargeting = buildPageTargeting(consentState, false);
19
+ const mergedCustomParams = { ...customParams, ...pageTargeting };
25
20
  const queryParams = {
26
21
  iu: adUnit,
27
- description_url: '[placeholder]',
28
22
  tfcd: '0',
29
23
  npa: '0',
30
24
  sz: '480x360|480x361|400x300',
@@ -33,10 +27,14 @@ const buildImaAdTagUrl = (adUnit, customParams) => {
33
27
  unviewed_position_start: '1',
34
28
  env: 'vp',
35
29
  impl: 's',
36
- correlator: '',
37
30
  vad_type: 'linear',
38
31
  vpos: 'preroll',
39
- cust_params: encodeVastTagKeyValues(filterValues(mergedCustomParams)),
32
+ /**
33
+ * cust_params string is encoded
34
+ * cust_params values are also encoded so they will get double encoded
35
+ * this ensures any values with separator chars (=&,) do not conflict with the main string
36
+ */
37
+ cust_params: encodeURIComponent(encodeCustomParams(filterValues(mergedCustomParams))),
40
38
  };
41
39
  const queryParamsArray = [];
42
40
  for (const [k, v] of Object.entries(queryParams)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guardian/commercial-core",
3
- "version": "4.21.0",
3
+ "version": "4.22.0",
4
4
  "description": "Guardian advertising business logic",
5
5
  "homepage": "https://github.com/guardian/commercial-core#readme",
6
6
  "bugs": {