@guardian/commercial-core 4.21.0 → 4.23.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/dist/cjs/event-timer.d.ts +2 -2
- package/dist/cjs/global.d.ts +5 -1
- package/dist/cjs/targeting/pick-targeting-values.d.ts +1 -1
- package/dist/cjs/targeting/youtube-ima.d.ts +2 -1
- package/dist/cjs/targeting/youtube-ima.js +30 -15
- package/dist/esm/event-timer.d.ts +2 -2
- package/dist/esm/event-timer.js +2 -1
- package/dist/esm/global.d.ts +5 -1
- package/dist/esm/targeting/pick-targeting-values.d.ts +1 -1
- package/dist/esm/targeting/youtube-ima.d.ts +2 -1
- package/dist/esm/targeting/youtube-ima.js +31 -16
- package/package.json +1 -1
|
@@ -35,7 +35,7 @@ interface EventTimerProperties {
|
|
|
35
35
|
hasLabsContainer?: boolean;
|
|
36
36
|
labsUrl?: string;
|
|
37
37
|
}
|
|
38
|
-
|
|
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 };
|
package/dist/cjs/global.d.ts
CHANGED
|
@@ -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
|
|
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,
|
|
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,33 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildImaAdTagUrl = void 0;
|
|
4
|
+
const libs_1 = require("@guardian/libs");
|
|
4
5
|
const build_page_targeting_1 = require("./build-page-targeting");
|
|
5
6
|
/**
|
|
6
7
|
* @param {Record<string, MaybeArray<string|number|boolean>>
|
|
7
8
|
* Follows https://support.google.com/admanager/answer/1080597
|
|
8
9
|
*/
|
|
9
|
-
const
|
|
10
|
-
const
|
|
10
|
+
const encodeCustomParams = (params) => {
|
|
11
|
+
const encodedParams = Object.entries(params)
|
|
11
12
|
.map(([key, value]) => {
|
|
12
13
|
const queryValue = Array.isArray(value)
|
|
13
14
|
? value.join(',')
|
|
14
15
|
: String(value);
|
|
15
|
-
return `${key}=${queryValue}`;
|
|
16
|
+
return `${key}=${encodeURIComponent(queryValue)}`;
|
|
16
17
|
})
|
|
17
18
|
.join('&');
|
|
18
|
-
return
|
|
19
|
-
.replace(/=/g, '%3D')
|
|
20
|
-
.replace(/&/g, '%26')
|
|
21
|
-
.replace(/,/g, '%2C');
|
|
19
|
+
return encodedParams;
|
|
22
20
|
};
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
const mergeCustomParamsWithTargeting = (customParams, consentState) => {
|
|
22
|
+
let pageTargeting = {};
|
|
23
|
+
try {
|
|
24
|
+
pageTargeting = (0, build_page_targeting_1.buildPageTargeting)(consentState, false);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
/**
|
|
28
|
+
* Defensive error handling in case YoutubeAtom is used in an
|
|
29
|
+
* environment where guardian.config, cookies, localstorage etc
|
|
30
|
+
* are not available
|
|
31
|
+
*/
|
|
32
|
+
(0, libs_1.log)('commercial', 'Error building YouTube IMA custom params', e);
|
|
33
|
+
return customParams;
|
|
34
|
+
}
|
|
35
|
+
const mergedCustomParams = { ...customParams, ...pageTargeting };
|
|
36
|
+
return mergedCustomParams;
|
|
37
|
+
};
|
|
38
|
+
const buildImaAdTagUrl = (adUnit, customParams, consentState) => {
|
|
39
|
+
const mergedCustomParams = mergeCustomParamsWithTargeting(customParams, consentState);
|
|
28
40
|
const queryParams = {
|
|
29
41
|
iu: adUnit,
|
|
30
|
-
description_url: '[placeholder]',
|
|
31
42
|
tfcd: '0',
|
|
32
43
|
npa: '0',
|
|
33
44
|
sz: '480x360|480x361|400x300',
|
|
@@ -36,10 +47,14 @@ const buildImaAdTagUrl = (adUnit, customParams) => {
|
|
|
36
47
|
unviewed_position_start: '1',
|
|
37
48
|
env: 'vp',
|
|
38
49
|
impl: 's',
|
|
39
|
-
correlator: '',
|
|
40
50
|
vad_type: 'linear',
|
|
41
51
|
vpos: 'preroll',
|
|
42
|
-
|
|
52
|
+
/**
|
|
53
|
+
* cust_params string is encoded
|
|
54
|
+
* cust_params values are also encoded so they will get double encoded
|
|
55
|
+
* this ensures any values with separator chars (=&,) do not conflict with the main string
|
|
56
|
+
*/
|
|
57
|
+
cust_params: encodeURIComponent(encodeCustomParams((0, build_page_targeting_1.filterValues)(mergedCustomParams))),
|
|
43
58
|
};
|
|
44
59
|
const queryParamsArray = [];
|
|
45
60
|
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
|
-
|
|
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 };
|
package/dist/esm/event-timer.js
CHANGED
|
@@ -5,7 +5,7 @@ class Event {
|
|
|
5
5
|
this.ts = mark.startTime;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
|
|
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 };
|
package/dist/esm/global.d.ts
CHANGED
|
@@ -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
|
|
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,
|
|
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,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { log } from '@guardian/libs';
|
|
2
|
+
import { buildPageTargeting, filterValues } from './build-page-targeting';
|
|
2
3
|
/**
|
|
3
4
|
* @param {Record<string, MaybeArray<string|number|boolean>>
|
|
4
5
|
* Follows https://support.google.com/admanager/answer/1080597
|
|
5
6
|
*/
|
|
6
|
-
const
|
|
7
|
-
const
|
|
7
|
+
const encodeCustomParams = (params) => {
|
|
8
|
+
const encodedParams = Object.entries(params)
|
|
8
9
|
.map(([key, value]) => {
|
|
9
10
|
const queryValue = Array.isArray(value)
|
|
10
11
|
? value.join(',')
|
|
11
12
|
: String(value);
|
|
12
|
-
return `${key}=${queryValue}`;
|
|
13
|
+
return `${key}=${encodeURIComponent(queryValue)}`;
|
|
13
14
|
})
|
|
14
15
|
.join('&');
|
|
15
|
-
return
|
|
16
|
-
.replace(/=/g, '%3D')
|
|
17
|
-
.replace(/&/g, '%26')
|
|
18
|
-
.replace(/,/g, '%2C');
|
|
16
|
+
return encodedParams;
|
|
19
17
|
};
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
18
|
+
const mergeCustomParamsWithTargeting = (customParams, consentState) => {
|
|
19
|
+
let pageTargeting = {};
|
|
20
|
+
try {
|
|
21
|
+
pageTargeting = buildPageTargeting(consentState, false);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
/**
|
|
25
|
+
* Defensive error handling in case YoutubeAtom is used in an
|
|
26
|
+
* environment where guardian.config, cookies, localstorage etc
|
|
27
|
+
* are not available
|
|
28
|
+
*/
|
|
29
|
+
log('commercial', 'Error building YouTube IMA custom params', e);
|
|
30
|
+
return customParams;
|
|
31
|
+
}
|
|
32
|
+
const mergedCustomParams = { ...customParams, ...pageTargeting };
|
|
33
|
+
return mergedCustomParams;
|
|
34
|
+
};
|
|
35
|
+
const buildImaAdTagUrl = (adUnit, customParams, consentState) => {
|
|
36
|
+
const mergedCustomParams = mergeCustomParamsWithTargeting(customParams, consentState);
|
|
25
37
|
const queryParams = {
|
|
26
38
|
iu: adUnit,
|
|
27
|
-
description_url: '[placeholder]',
|
|
28
39
|
tfcd: '0',
|
|
29
40
|
npa: '0',
|
|
30
41
|
sz: '480x360|480x361|400x300',
|
|
@@ -33,10 +44,14 @@ const buildImaAdTagUrl = (adUnit, customParams) => {
|
|
|
33
44
|
unviewed_position_start: '1',
|
|
34
45
|
env: 'vp',
|
|
35
46
|
impl: 's',
|
|
36
|
-
correlator: '',
|
|
37
47
|
vad_type: 'linear',
|
|
38
48
|
vpos: 'preroll',
|
|
39
|
-
|
|
49
|
+
/**
|
|
50
|
+
* cust_params string is encoded
|
|
51
|
+
* cust_params values are also encoded so they will get double encoded
|
|
52
|
+
* this ensures any values with separator chars (=&,) do not conflict with the main string
|
|
53
|
+
*/
|
|
54
|
+
cust_params: encodeURIComponent(encodeCustomParams(filterValues(mergedCustomParams))),
|
|
40
55
|
};
|
|
41
56
|
const queryParamsArray = [];
|
|
42
57
|
for (const [k, v] of Object.entries(queryParams)) {
|