@guardian/commercial-core 0.34.0 → 0.37.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/ad-sizes.d.ts +2 -1
- package/dist/cjs/ad-sizes.js +25 -23
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/targeting/content.d.ts +4 -3
- package/dist/cjs/targeting/content.js +0 -1
- package/dist/cjs/targeting/pick-targeting-values.d.ts +3 -6
- package/dist/cjs/targeting/pick-targeting-values.js +3 -1
- package/dist/cjs/targeting/session.d.ts +13 -2
- package/dist/cjs/targeting/session.js +6 -4
- package/dist/esm/ad-sizes.d.ts +2 -1
- package/dist/esm/ad-sizes.js +23 -22
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/targeting/content.d.ts +4 -3
- package/dist/esm/targeting/content.js +0 -1
- package/dist/esm/targeting/pick-targeting-values.d.ts +3 -6
- package/dist/esm/targeting/pick-targeting-values.js +3 -1
- package/dist/esm/targeting/session.d.ts +13 -2
- package/dist/esm/targeting/session.js +6 -4
- package/package.json +2 -1
package/dist/cjs/ad-sizes.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare type AdSize = Readonly<{
|
|
|
6
6
|
}>;
|
|
7
7
|
export declare type SizeKeys = 'billboard' | 'leaderboard' | 'mpu' | 'halfPage' | 'portrait' | 'skyscraper' | 'mobilesticky' | 'fluid' | 'outOfPage' | 'googleCard' | 'video' | 'outstreamDesktop' | 'outstreamGoogleDesktop' | 'outstreamMobile' | 'merchandisingHighAdFeature' | 'merchandisingHigh' | 'merchandising' | 'inlineMerchandising' | 'fabric' | 'empty' | '970x250' | '728x90' | '300x250' | '300x600' | '300x1050' | '160x600';
|
|
8
8
|
export declare const adSizes: Record<SizeKeys, AdSize>;
|
|
9
|
+
export declare const getAdSize: (size: SizeKeys) => AdSize;
|
|
9
10
|
export declare const _: {
|
|
10
|
-
|
|
11
|
+
createAdSize: (width: number, height: number) => AdSize;
|
|
11
12
|
};
|
package/dist/cjs/ad-sizes.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._ = exports.adSizes = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports._ = exports.getAdSize = exports.adSizes = void 0;
|
|
4
|
+
const createAdSize = (width, height) => {
|
|
5
5
|
const toString = () => width === 0 && height === 0 ? 'fluid' : `${width},${height}`;
|
|
6
6
|
return Object.freeze({
|
|
7
7
|
width,
|
|
@@ -11,28 +11,28 @@ const getAdSize = (width, height) => {
|
|
|
11
11
|
};
|
|
12
12
|
const adSizesPartial = {
|
|
13
13
|
// standard ad sizes
|
|
14
|
-
billboard:
|
|
15
|
-
leaderboard:
|
|
16
|
-
mpu:
|
|
17
|
-
halfPage:
|
|
18
|
-
portrait:
|
|
19
|
-
skyscraper:
|
|
20
|
-
mobilesticky:
|
|
14
|
+
billboard: createAdSize(970, 250),
|
|
15
|
+
leaderboard: createAdSize(728, 90),
|
|
16
|
+
mpu: createAdSize(300, 250),
|
|
17
|
+
halfPage: createAdSize(300, 600),
|
|
18
|
+
portrait: createAdSize(300, 1050),
|
|
19
|
+
skyscraper: createAdSize(160, 600),
|
|
20
|
+
mobilesticky: createAdSize(320, 50),
|
|
21
21
|
// dfp proprietary ad sizes
|
|
22
|
-
fluid:
|
|
23
|
-
outOfPage:
|
|
24
|
-
googleCard:
|
|
22
|
+
fluid: createAdSize(0, 0),
|
|
23
|
+
outOfPage: createAdSize(1, 1),
|
|
24
|
+
googleCard: createAdSize(300, 274),
|
|
25
25
|
// guardian proprietary ad sizes
|
|
26
|
-
video:
|
|
27
|
-
outstreamDesktop:
|
|
28
|
-
outstreamGoogleDesktop:
|
|
29
|
-
outstreamMobile:
|
|
30
|
-
merchandisingHighAdFeature:
|
|
31
|
-
merchandisingHigh:
|
|
32
|
-
merchandising:
|
|
33
|
-
inlineMerchandising:
|
|
34
|
-
fabric:
|
|
35
|
-
empty:
|
|
26
|
+
video: createAdSize(620, 1),
|
|
27
|
+
outstreamDesktop: createAdSize(620, 350),
|
|
28
|
+
outstreamGoogleDesktop: createAdSize(550, 310),
|
|
29
|
+
outstreamMobile: createAdSize(300, 197),
|
|
30
|
+
merchandisingHighAdFeature: createAdSize(88, 89),
|
|
31
|
+
merchandisingHigh: createAdSize(88, 87),
|
|
32
|
+
merchandising: createAdSize(88, 88),
|
|
33
|
+
inlineMerchandising: createAdSize(88, 85),
|
|
34
|
+
fabric: createAdSize(88, 71),
|
|
35
|
+
empty: createAdSize(2, 2),
|
|
36
36
|
};
|
|
37
37
|
exports.adSizes = {
|
|
38
38
|
...adSizesPartial,
|
|
@@ -43,5 +43,7 @@ exports.adSizes = {
|
|
|
43
43
|
'300x1050': adSizesPartial.portrait,
|
|
44
44
|
'160x600': adSizesPartial.skyscraper,
|
|
45
45
|
};
|
|
46
|
+
const getAdSize = (size) => exports.adSizes[size];
|
|
47
|
+
exports.getAdSize = getAdSize;
|
|
46
48
|
// Export for testing
|
|
47
|
-
exports._ = {
|
|
49
|
+
exports._ = { createAdSize };
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { remarketing } from './third-party-tags/remarketing';
|
|
|
7
7
|
export { EventTimer } from './EventTimer';
|
|
8
8
|
export { sendCommercialMetrics } from './sendCommercialMetrics';
|
|
9
9
|
export type { ThirdPartyTag } from './types';
|
|
10
|
-
export { adSizes } from './ad-sizes';
|
|
10
|
+
export { adSizes, getAdSize } from './ad-sizes';
|
|
11
11
|
export type { SizeKeys, AdSizeString, AdSize } from './ad-sizes';
|
|
12
12
|
export { isAdBlockInUse } from './detectAdBlocker';
|
|
13
13
|
export { clearPermutiveSegments, getPermutiveSegments, getPermutivePFPSegments, } from './permutive';
|
package/dist/cjs/index.js
CHANGED
|
@@ -20,7 +20,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
20
|
return result;
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.constants = exports.disabledAds = exports.buildAdsConfigWithConsent = exports.getPermutivePFPSegments = exports.getPermutiveSegments = exports.clearPermutiveSegments = exports.isAdBlockInUse = exports.adSizes = exports.sendCommercialMetrics = exports.EventTimer = exports.remarketing = exports.inizio = exports.twitter = exports.fbPixel = exports.permutive = exports.ias = void 0;
|
|
23
|
+
exports.constants = exports.disabledAds = exports.buildAdsConfigWithConsent = exports.getPermutivePFPSegments = exports.getPermutiveSegments = exports.clearPermutiveSegments = exports.isAdBlockInUse = exports.getAdSize = exports.adSizes = exports.sendCommercialMetrics = exports.EventTimer = exports.remarketing = exports.inizio = exports.twitter = exports.fbPixel = exports.permutive = exports.ias = void 0;
|
|
24
24
|
var ias_1 = require("./third-party-tags/ias");
|
|
25
25
|
Object.defineProperty(exports, "ias", { enumerable: true, get: function () { return ias_1.ias; } });
|
|
26
26
|
var permutive_1 = require("./third-party-tags/permutive");
|
|
@@ -39,6 +39,7 @@ var sendCommercialMetrics_1 = require("./sendCommercialMetrics");
|
|
|
39
39
|
Object.defineProperty(exports, "sendCommercialMetrics", { enumerable: true, get: function () { return sendCommercialMetrics_1.sendCommercialMetrics; } });
|
|
40
40
|
var ad_sizes_1 = require("./ad-sizes");
|
|
41
41
|
Object.defineProperty(exports, "adSizes", { enumerable: true, get: function () { return ad_sizes_1.adSizes; } });
|
|
42
|
+
Object.defineProperty(exports, "getAdSize", { enumerable: true, get: function () { return ad_sizes_1.getAdSize; } });
|
|
42
43
|
var detectAdBlocker_1 = require("./detectAdBlocker");
|
|
43
44
|
Object.defineProperty(exports, "isAdBlockInUse", { enumerable: true, get: function () { return detectAdBlocker_1.isAdBlockInUse; } });
|
|
44
45
|
var permutive_2 = require("./permutive");
|
|
@@ -58,12 +58,13 @@ export declare type ContentTargeting = {
|
|
|
58
58
|
*/
|
|
59
59
|
vl: null | typeof videoLengths[number];
|
|
60
60
|
};
|
|
61
|
-
|
|
61
|
+
declare type Content = {
|
|
62
62
|
eligibleForDCR: boolean;
|
|
63
63
|
path: SharedTargeting['url'];
|
|
64
64
|
renderingPlatform: ContentTargeting['rp'];
|
|
65
65
|
section: ContentTargeting['s'];
|
|
66
66
|
sensitive: boolean;
|
|
67
|
-
videoLength?: number
|
|
68
|
-
}
|
|
67
|
+
videoLength?: number;
|
|
68
|
+
};
|
|
69
|
+
export declare const getContentTargeting: ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, }: Content) => ContentTargeting;
|
|
69
70
|
export {};
|
|
@@ -28,7 +28,6 @@ const getUrlKeywords = (url) => {
|
|
|
28
28
|
.slice(-1)[0];
|
|
29
29
|
return (0, libs_1.isString)(lastSegment) ? lastSegment.split('-').filter(Boolean) : [];
|
|
30
30
|
};
|
|
31
|
-
/* -- Targeting -- */
|
|
32
31
|
const getContentTargeting = ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, }) => {
|
|
33
32
|
return {
|
|
34
33
|
dcre: eligibleForDCR ? 't' : 'f',
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
declare type
|
|
3
|
-
[K in keyof T]-?: ValidTargeting<T[K], K>;
|
|
4
|
-
}[keyof T];
|
|
5
|
-
declare type ObjectWithDefinedValues<T> = Pick<T, DefinedKeys<T>>;
|
|
1
|
+
import type { ConditionalExcept } from 'type-fest';
|
|
2
|
+
declare type ValidTargetingObject<Base> = ConditionalExcept<Base, null | undefined | '' | readonly [] | readonly [''] | boolean | number>;
|
|
6
3
|
/**
|
|
7
4
|
* Picks only keys with targeting values from an object.
|
|
8
5
|
* A targeting values is defined as either:
|
|
@@ -24,5 +21,5 @@ declare type ObjectWithDefinedValues<T> = Pick<T, DefinedKeys<T>>;
|
|
|
24
21
|
* clean.invalid
|
|
25
22
|
* ```
|
|
26
23
|
*/
|
|
27
|
-
export declare const pickTargetingValues: <T extends Record<string, string | readonly string[] | undefined>>(obj: T) =>
|
|
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 | "" | readonly [] | readonly [""] | null | undefined ? Key : never; }[keyof T]>>;
|
|
28
25
|
export {};
|
|
@@ -37,7 +37,9 @@ const pickTargetingValues = (obj) => {
|
|
|
37
37
|
return Object.entries(obj).reduce((valid, [key, value]) => {
|
|
38
38
|
if (isValidTargeting(value)) {
|
|
39
39
|
// @ts-expect-error -- isValidTargeting checks this
|
|
40
|
-
valid[key] = value
|
|
40
|
+
valid[key] = Array.isArray(value)
|
|
41
|
+
? value.filter(isTargetingString)
|
|
42
|
+
: value;
|
|
41
43
|
}
|
|
42
44
|
return valid;
|
|
43
45
|
}, initialValue);
|
|
@@ -92,7 +92,18 @@ export declare type SessionTargeting = {
|
|
|
92
92
|
};
|
|
93
93
|
export declare type AllParticipations = {
|
|
94
94
|
clientSideParticipations: Participations;
|
|
95
|
-
serverSideParticipations:
|
|
95
|
+
serverSideParticipations: {
|
|
96
|
+
[key: `${string}Control`]: 'control';
|
|
97
|
+
[key: `${string}Variant`]: 'variant';
|
|
98
|
+
};
|
|
96
99
|
};
|
|
97
|
-
|
|
100
|
+
declare type Session = {
|
|
101
|
+
adTest: SessionTargeting['at'];
|
|
102
|
+
countryCode: CountryCode;
|
|
103
|
+
isSignedIn: boolean;
|
|
104
|
+
pageViewId: SessionTargeting['pv'];
|
|
105
|
+
participations: AllParticipations;
|
|
106
|
+
referrer: string;
|
|
107
|
+
};
|
|
108
|
+
export declare const getSessionTargeting: ({ adTest, countryCode, isSignedIn, pageViewId, participations, referrer, }: Session) => SessionTargeting;
|
|
98
109
|
export {};
|
|
@@ -49,10 +49,12 @@ const experimentsTargeting = ({ clientSideParticipations, serverSideParticipatio
|
|
|
49
49
|
}
|
|
50
50
|
return [...clientSideExperiment, ...serverSideExperiments];
|
|
51
51
|
};
|
|
52
|
-
|
|
53
|
-
const getSessionTargeting = (referrer, participations, targeting) => ({
|
|
54
|
-
ref: getReferrer(referrer),
|
|
52
|
+
const getSessionTargeting = ({ adTest, countryCode, isSignedIn, pageViewId, participations, referrer, }) => ({
|
|
55
53
|
ab: experimentsTargeting(participations),
|
|
56
|
-
|
|
54
|
+
at: adTest,
|
|
55
|
+
cc: countryCode,
|
|
56
|
+
pv: pageViewId,
|
|
57
|
+
ref: getReferrer(referrer),
|
|
58
|
+
si: isSignedIn ? 't' : 'f',
|
|
57
59
|
});
|
|
58
60
|
exports.getSessionTargeting = getSessionTargeting;
|
package/dist/esm/ad-sizes.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare type AdSize = Readonly<{
|
|
|
6
6
|
}>;
|
|
7
7
|
export declare type SizeKeys = 'billboard' | 'leaderboard' | 'mpu' | 'halfPage' | 'portrait' | 'skyscraper' | 'mobilesticky' | 'fluid' | 'outOfPage' | 'googleCard' | 'video' | 'outstreamDesktop' | 'outstreamGoogleDesktop' | 'outstreamMobile' | 'merchandisingHighAdFeature' | 'merchandisingHigh' | 'merchandising' | 'inlineMerchandising' | 'fabric' | 'empty' | '970x250' | '728x90' | '300x250' | '300x600' | '300x1050' | '160x600';
|
|
8
8
|
export declare const adSizes: Record<SizeKeys, AdSize>;
|
|
9
|
+
export declare const getAdSize: (size: SizeKeys) => AdSize;
|
|
9
10
|
export declare const _: {
|
|
10
|
-
|
|
11
|
+
createAdSize: (width: number, height: number) => AdSize;
|
|
11
12
|
};
|
package/dist/esm/ad-sizes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const createAdSize = (width, height) => {
|
|
2
2
|
const toString = () => width === 0 && height === 0 ? 'fluid' : `${width},${height}`;
|
|
3
3
|
return Object.freeze({
|
|
4
4
|
width,
|
|
@@ -8,28 +8,28 @@ const getAdSize = (width, height) => {
|
|
|
8
8
|
};
|
|
9
9
|
const adSizesPartial = {
|
|
10
10
|
// standard ad sizes
|
|
11
|
-
billboard:
|
|
12
|
-
leaderboard:
|
|
13
|
-
mpu:
|
|
14
|
-
halfPage:
|
|
15
|
-
portrait:
|
|
16
|
-
skyscraper:
|
|
17
|
-
mobilesticky:
|
|
11
|
+
billboard: createAdSize(970, 250),
|
|
12
|
+
leaderboard: createAdSize(728, 90),
|
|
13
|
+
mpu: createAdSize(300, 250),
|
|
14
|
+
halfPage: createAdSize(300, 600),
|
|
15
|
+
portrait: createAdSize(300, 1050),
|
|
16
|
+
skyscraper: createAdSize(160, 600),
|
|
17
|
+
mobilesticky: createAdSize(320, 50),
|
|
18
18
|
// dfp proprietary ad sizes
|
|
19
|
-
fluid:
|
|
20
|
-
outOfPage:
|
|
21
|
-
googleCard:
|
|
19
|
+
fluid: createAdSize(0, 0),
|
|
20
|
+
outOfPage: createAdSize(1, 1),
|
|
21
|
+
googleCard: createAdSize(300, 274),
|
|
22
22
|
// guardian proprietary ad sizes
|
|
23
|
-
video:
|
|
24
|
-
outstreamDesktop:
|
|
25
|
-
outstreamGoogleDesktop:
|
|
26
|
-
outstreamMobile:
|
|
27
|
-
merchandisingHighAdFeature:
|
|
28
|
-
merchandisingHigh:
|
|
29
|
-
merchandising:
|
|
30
|
-
inlineMerchandising:
|
|
31
|
-
fabric:
|
|
32
|
-
empty:
|
|
23
|
+
video: createAdSize(620, 1),
|
|
24
|
+
outstreamDesktop: createAdSize(620, 350),
|
|
25
|
+
outstreamGoogleDesktop: createAdSize(550, 310),
|
|
26
|
+
outstreamMobile: createAdSize(300, 197),
|
|
27
|
+
merchandisingHighAdFeature: createAdSize(88, 89),
|
|
28
|
+
merchandisingHigh: createAdSize(88, 87),
|
|
29
|
+
merchandising: createAdSize(88, 88),
|
|
30
|
+
inlineMerchandising: createAdSize(88, 85),
|
|
31
|
+
fabric: createAdSize(88, 71),
|
|
32
|
+
empty: createAdSize(2, 2),
|
|
33
33
|
};
|
|
34
34
|
export const adSizes = {
|
|
35
35
|
...adSizesPartial,
|
|
@@ -40,5 +40,6 @@ export const adSizes = {
|
|
|
40
40
|
'300x1050': adSizesPartial.portrait,
|
|
41
41
|
'160x600': adSizesPartial.skyscraper,
|
|
42
42
|
};
|
|
43
|
+
export const getAdSize = (size) => adSizes[size];
|
|
43
44
|
// Export for testing
|
|
44
|
-
export const _ = {
|
|
45
|
+
export const _ = { createAdSize };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { remarketing } from './third-party-tags/remarketing';
|
|
|
7
7
|
export { EventTimer } from './EventTimer';
|
|
8
8
|
export { sendCommercialMetrics } from './sendCommercialMetrics';
|
|
9
9
|
export type { ThirdPartyTag } from './types';
|
|
10
|
-
export { adSizes } from './ad-sizes';
|
|
10
|
+
export { adSizes, getAdSize } from './ad-sizes';
|
|
11
11
|
export type { SizeKeys, AdSizeString, AdSize } from './ad-sizes';
|
|
12
12
|
export { isAdBlockInUse } from './detectAdBlocker';
|
|
13
13
|
export { clearPermutiveSegments, getPermutiveSegments, getPermutivePFPSegments, } from './permutive';
|
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 './EventTimer';
|
|
9
9
|
export { sendCommercialMetrics } from './sendCommercialMetrics';
|
|
10
|
-
export { adSizes } from './ad-sizes';
|
|
10
|
+
export { adSizes, getAdSize } from './ad-sizes';
|
|
11
11
|
export { isAdBlockInUse } from './detectAdBlocker';
|
|
12
12
|
export { clearPermutiveSegments, getPermutiveSegments, getPermutivePFPSegments, } from './permutive';
|
|
13
13
|
export { buildAdsConfigWithConsent, disabledAds } from './ad-targeting-youtube';
|
|
@@ -58,12 +58,13 @@ export declare type ContentTargeting = {
|
|
|
58
58
|
*/
|
|
59
59
|
vl: null | typeof videoLengths[number];
|
|
60
60
|
};
|
|
61
|
-
|
|
61
|
+
declare type Content = {
|
|
62
62
|
eligibleForDCR: boolean;
|
|
63
63
|
path: SharedTargeting['url'];
|
|
64
64
|
renderingPlatform: ContentTargeting['rp'];
|
|
65
65
|
section: ContentTargeting['s'];
|
|
66
66
|
sensitive: boolean;
|
|
67
|
-
videoLength?: number
|
|
68
|
-
}
|
|
67
|
+
videoLength?: number;
|
|
68
|
+
};
|
|
69
|
+
export declare const getContentTargeting: ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, }: Content) => ContentTargeting;
|
|
69
70
|
export {};
|
|
@@ -25,7 +25,6 @@ const getUrlKeywords = (url) => {
|
|
|
25
25
|
.slice(-1)[0];
|
|
26
26
|
return isString(lastSegment) ? lastSegment.split('-').filter(Boolean) : [];
|
|
27
27
|
};
|
|
28
|
-
/* -- Targeting -- */
|
|
29
28
|
export const getContentTargeting = ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, }) => {
|
|
30
29
|
return {
|
|
31
30
|
dcre: eligibleForDCR ? 't' : 'f',
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
declare type
|
|
3
|
-
[K in keyof T]-?: ValidTargeting<T[K], K>;
|
|
4
|
-
}[keyof T];
|
|
5
|
-
declare type ObjectWithDefinedValues<T> = Pick<T, DefinedKeys<T>>;
|
|
1
|
+
import type { ConditionalExcept } from 'type-fest';
|
|
2
|
+
declare type ValidTargetingObject<Base> = ConditionalExcept<Base, null | undefined | '' | readonly [] | readonly [''] | boolean | number>;
|
|
6
3
|
/**
|
|
7
4
|
* Picks only keys with targeting values from an object.
|
|
8
5
|
* A targeting values is defined as either:
|
|
@@ -24,5 +21,5 @@ declare type ObjectWithDefinedValues<T> = Pick<T, DefinedKeys<T>>;
|
|
|
24
21
|
* clean.invalid
|
|
25
22
|
* ```
|
|
26
23
|
*/
|
|
27
|
-
export declare const pickTargetingValues: <T extends Record<string, string | readonly string[] | undefined>>(obj: T) =>
|
|
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 | "" | readonly [] | readonly [""] | null | undefined ? Key : never; }[keyof T]>>;
|
|
28
25
|
export {};
|
|
@@ -34,7 +34,9 @@ export const pickTargetingValues = (obj) => {
|
|
|
34
34
|
return Object.entries(obj).reduce((valid, [key, value]) => {
|
|
35
35
|
if (isValidTargeting(value)) {
|
|
36
36
|
// @ts-expect-error -- isValidTargeting checks this
|
|
37
|
-
valid[key] = value
|
|
37
|
+
valid[key] = Array.isArray(value)
|
|
38
|
+
? value.filter(isTargetingString)
|
|
39
|
+
: value;
|
|
38
40
|
}
|
|
39
41
|
return valid;
|
|
40
42
|
}, initialValue);
|
|
@@ -92,7 +92,18 @@ export declare type SessionTargeting = {
|
|
|
92
92
|
};
|
|
93
93
|
export declare type AllParticipations = {
|
|
94
94
|
clientSideParticipations: Participations;
|
|
95
|
-
serverSideParticipations:
|
|
95
|
+
serverSideParticipations: {
|
|
96
|
+
[key: `${string}Control`]: 'control';
|
|
97
|
+
[key: `${string}Variant`]: 'variant';
|
|
98
|
+
};
|
|
96
99
|
};
|
|
97
|
-
|
|
100
|
+
declare type Session = {
|
|
101
|
+
adTest: SessionTargeting['at'];
|
|
102
|
+
countryCode: CountryCode;
|
|
103
|
+
isSignedIn: boolean;
|
|
104
|
+
pageViewId: SessionTargeting['pv'];
|
|
105
|
+
participations: AllParticipations;
|
|
106
|
+
referrer: string;
|
|
107
|
+
};
|
|
108
|
+
export declare const getSessionTargeting: ({ adTest, countryCode, isSignedIn, pageViewId, participations, referrer, }: Session) => SessionTargeting;
|
|
98
109
|
export {};
|
|
@@ -46,9 +46,11 @@ const experimentsTargeting = ({ clientSideParticipations, serverSideParticipatio
|
|
|
46
46
|
}
|
|
47
47
|
return [...clientSideExperiment, ...serverSideExperiments];
|
|
48
48
|
};
|
|
49
|
-
|
|
50
|
-
export const getSessionTargeting = (referrer, participations, targeting) => ({
|
|
51
|
-
ref: getReferrer(referrer),
|
|
49
|
+
export const getSessionTargeting = ({ adTest, countryCode, isSignedIn, pageViewId, participations, referrer, }) => ({
|
|
52
50
|
ab: experimentsTargeting(participations),
|
|
53
|
-
|
|
51
|
+
at: adTest,
|
|
52
|
+
cc: countryCode,
|
|
53
|
+
pv: pageViewId,
|
|
54
|
+
ref: getReferrer(referrer),
|
|
55
|
+
si: isSignedIn ? 't' : 'f',
|
|
54
56
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guardian/commercial-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "Guardian advertising business logic",
|
|
5
5
|
"homepage": "https://github.com/guardian/commercial-core#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
"prettier": "^2.5.0",
|
|
72
72
|
"semantic-release": "^18.0.1",
|
|
73
73
|
"ts-jest": "^27.0.7",
|
|
74
|
+
"type-fest": "^2.8.0",
|
|
74
75
|
"typescript": "^4.5.2",
|
|
75
76
|
"web-vitals": "^2.1.2"
|
|
76
77
|
},
|