@guardian/commercial-core 4.19.0 → 4.20.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/README.md +0 -6
- package/dist/cjs/lib/ab-localstorage.d.ts +2 -0
- package/dist/cjs/lib/ab-localstorage.js +14 -0
- package/dist/cjs/targeting/build-page-targeting-consentless.d.ts +1 -3
- package/dist/cjs/targeting/build-page-targeting-consentless.js +2 -3
- package/dist/cjs/targeting/build-page-targeting.d.ts +1 -2
- package/dist/cjs/targeting/build-page-targeting.js +3 -2
- package/dist/esm/lib/ab-localstorage.d.ts +2 -0
- package/dist/esm/lib/ab-localstorage.js +10 -0
- package/dist/esm/targeting/build-page-targeting-consentless.d.ts +1 -3
- package/dist/esm/targeting/build-page-targeting-consentless.js +2 -3
- package/dist/esm/targeting/build-page-targeting.d.ts +1 -2
- package/dist/esm/targeting/build-page-targeting.js +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getParticipationsFromLocalStorage = void 0;
|
|
4
|
+
const libs_1 = require("@guardian/libs");
|
|
5
|
+
const participationsKey = 'gu.ab.participations';
|
|
6
|
+
const isParticipations = (participations) => {
|
|
7
|
+
return ((0, libs_1.isObject)(participations) &&
|
|
8
|
+
Object.values(participations).every((participation) => (0, libs_1.isObject)(participation) && (0, libs_1.isString)(participation.variant)));
|
|
9
|
+
};
|
|
10
|
+
const getParticipationsFromLocalStorage = () => {
|
|
11
|
+
const participations = libs_1.storage.local.get(participationsKey);
|
|
12
|
+
return isParticipations(participations) ? participations : {};
|
|
13
|
+
};
|
|
14
|
+
exports.getParticipationsFromLocalStorage = getParticipationsFromLocalStorage;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Participations } from '@guardian/ab-core';
|
|
2
1
|
import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
|
|
3
2
|
import type { PageTargeting } from './build-page-targeting';
|
|
4
3
|
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"];
|
|
@@ -10,8 +9,7 @@ declare type ConsentlessPageTargeting = Partial<Pick<PageTargeting, ConsentlessT
|
|
|
10
9
|
*
|
|
11
10
|
* @param {ConsentState} consentState
|
|
12
11
|
* @param {boolean} adFree
|
|
13
|
-
* @param {Participations} clientSideParticipations
|
|
14
12
|
* @returns ConsentlessPageTargeting
|
|
15
13
|
*/
|
|
16
|
-
declare const buildPageTargetingConsentless: (consentState: ConsentState, adFree: boolean
|
|
14
|
+
declare const buildPageTargetingConsentless: (consentState: ConsentState, adFree: boolean) => ConsentlessPageTargeting;
|
|
17
15
|
export { buildPageTargetingConsentless };
|
|
@@ -32,11 +32,10 @@ const isConsentlessKey = (key) => consentlessTargetingKeys.includes(key);
|
|
|
32
32
|
*
|
|
33
33
|
* @param {ConsentState} consentState
|
|
34
34
|
* @param {boolean} adFree
|
|
35
|
-
* @param {Participations} clientSideParticipations
|
|
36
35
|
* @returns ConsentlessPageTargeting
|
|
37
36
|
*/
|
|
38
|
-
const buildPageTargetingConsentless = (consentState, adFree
|
|
39
|
-
const consentedPageTargeting = (0, build_page_targeting_1.buildPageTargeting)(consentState, adFree
|
|
37
|
+
const buildPageTargetingConsentless = (consentState, adFree) => {
|
|
38
|
+
const consentedPageTargeting = (0, build_page_targeting_1.buildPageTargeting)(consentState, adFree);
|
|
40
39
|
return Object.fromEntries(Object.entries(consentedPageTargeting).filter(([k]) => isConsentlessKey(k)));
|
|
41
40
|
};
|
|
42
41
|
exports.buildPageTargetingConsentless = buildPageTargetingConsentless;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Participations } from '@guardian/ab-core';
|
|
2
1
|
import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
|
|
3
2
|
import type { CountryCode } from '@guardian/libs';
|
|
4
3
|
import type { False, True } from '../types';
|
|
@@ -34,6 +33,6 @@ declare type PageTargeting = PartialWithNulls<{
|
|
|
34
33
|
vl: string;
|
|
35
34
|
[_: string]: string | string[];
|
|
36
35
|
} & SharedTargeting>;
|
|
37
|
-
declare const buildPageTargeting: (consentState: ConsentState, adFree: boolean
|
|
36
|
+
declare const buildPageTargeting: (consentState: ConsentState, adFree: boolean) => PageTargeting;
|
|
38
37
|
export { buildPageTargeting };
|
|
39
38
|
export type { PageTargeting };
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
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
|
+
const ab_localstorage_1 = require("../lib/ab-localstorage");
|
|
6
7
|
const get_locale_1 = require("../lib/get-locale");
|
|
7
8
|
const content_1 = require("./content");
|
|
8
9
|
const personalised_1 = require("./personalised");
|
|
@@ -24,7 +25,7 @@ const filterEmptyValues = (pageTargets) => {
|
|
|
24
25
|
}
|
|
25
26
|
return filtered;
|
|
26
27
|
};
|
|
27
|
-
const buildPageTargeting = (consentState, adFree
|
|
28
|
+
const buildPageTargeting = (consentState, adFree) => {
|
|
28
29
|
const { page, isDotcomRendering } = window.guardian.config;
|
|
29
30
|
const adFreeTargeting = adFree ? { af: 't' } : {};
|
|
30
31
|
const contentTargeting = (0, content_1.getContentTargeting)({
|
|
@@ -44,7 +45,7 @@ const buildPageTargeting = (consentState, adFree, clientSideParticipations) => {
|
|
|
44
45
|
isSignedIn: !!(0, libs_1.getCookie)({ name: 'GU_U' }),
|
|
45
46
|
pageViewId: window.guardian.config.ophan.pageViewId,
|
|
46
47
|
participations: {
|
|
47
|
-
clientSideParticipations,
|
|
48
|
+
clientSideParticipations: (0, ab_localstorage_1.getParticipationsFromLocalStorage)(),
|
|
48
49
|
serverSideParticipations: window.guardian.config.tests ?? {},
|
|
49
50
|
},
|
|
50
51
|
referrer: getReferrer(),
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isObject, isString, storage } from '@guardian/libs';
|
|
2
|
+
const participationsKey = 'gu.ab.participations';
|
|
3
|
+
const isParticipations = (participations) => {
|
|
4
|
+
return (isObject(participations) &&
|
|
5
|
+
Object.values(participations).every((participation) => isObject(participation) && isString(participation.variant)));
|
|
6
|
+
};
|
|
7
|
+
export const getParticipationsFromLocalStorage = () => {
|
|
8
|
+
const participations = storage.local.get(participationsKey);
|
|
9
|
+
return isParticipations(participations) ? participations : {};
|
|
10
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Participations } from '@guardian/ab-core';
|
|
2
1
|
import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
|
|
3
2
|
import type { PageTargeting } from './build-page-targeting';
|
|
4
3
|
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"];
|
|
@@ -10,8 +9,7 @@ declare type ConsentlessPageTargeting = Partial<Pick<PageTargeting, ConsentlessT
|
|
|
10
9
|
*
|
|
11
10
|
* @param {ConsentState} consentState
|
|
12
11
|
* @param {boolean} adFree
|
|
13
|
-
* @param {Participations} clientSideParticipations
|
|
14
12
|
* @returns ConsentlessPageTargeting
|
|
15
13
|
*/
|
|
16
|
-
declare const buildPageTargetingConsentless: (consentState: ConsentState, adFree: boolean
|
|
14
|
+
declare const buildPageTargetingConsentless: (consentState: ConsentState, adFree: boolean) => ConsentlessPageTargeting;
|
|
17
15
|
export { buildPageTargetingConsentless };
|
|
@@ -29,11 +29,10 @@ const isConsentlessKey = (key) => consentlessTargetingKeys.includes(key);
|
|
|
29
29
|
*
|
|
30
30
|
* @param {ConsentState} consentState
|
|
31
31
|
* @param {boolean} adFree
|
|
32
|
-
* @param {Participations} clientSideParticipations
|
|
33
32
|
* @returns ConsentlessPageTargeting
|
|
34
33
|
*/
|
|
35
|
-
const buildPageTargetingConsentless = (consentState, adFree
|
|
36
|
-
const consentedPageTargeting = buildPageTargeting(consentState, adFree
|
|
34
|
+
const buildPageTargetingConsentless = (consentState, adFree) => {
|
|
35
|
+
const consentedPageTargeting = buildPageTargeting(consentState, adFree);
|
|
37
36
|
return Object.fromEntries(Object.entries(consentedPageTargeting).filter(([k]) => isConsentlessKey(k)));
|
|
38
37
|
};
|
|
39
38
|
export { buildPageTargetingConsentless };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Participations } from '@guardian/ab-core';
|
|
2
1
|
import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
|
|
3
2
|
import type { CountryCode } from '@guardian/libs';
|
|
4
3
|
import type { False, True } from '../types';
|
|
@@ -34,6 +33,6 @@ declare type PageTargeting = PartialWithNulls<{
|
|
|
34
33
|
vl: string;
|
|
35
34
|
[_: string]: string | string[];
|
|
36
35
|
} & SharedTargeting>;
|
|
37
|
-
declare const buildPageTargeting: (consentState: ConsentState, adFree: boolean
|
|
36
|
+
declare const buildPageTargeting: (consentState: ConsentState, adFree: boolean) => PageTargeting;
|
|
38
37
|
export { buildPageTargeting };
|
|
39
38
|
export type { PageTargeting };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cmp } from '@guardian/consent-management-platform';
|
|
2
2
|
import { getCookie, isString } from '@guardian/libs';
|
|
3
|
+
import { getParticipationsFromLocalStorage } from '../lib/ab-localstorage';
|
|
3
4
|
import { getLocale } from '../lib/get-locale';
|
|
4
5
|
import { getContentTargeting } from './content';
|
|
5
6
|
import { getPersonalisedTargeting } from './personalised';
|
|
@@ -21,7 +22,7 @@ const filterEmptyValues = (pageTargets) => {
|
|
|
21
22
|
}
|
|
22
23
|
return filtered;
|
|
23
24
|
};
|
|
24
|
-
const buildPageTargeting = (consentState, adFree
|
|
25
|
+
const buildPageTargeting = (consentState, adFree) => {
|
|
25
26
|
const { page, isDotcomRendering } = window.guardian.config;
|
|
26
27
|
const adFreeTargeting = adFree ? { af: 't' } : {};
|
|
27
28
|
const contentTargeting = getContentTargeting({
|
|
@@ -41,7 +42,7 @@ const buildPageTargeting = (consentState, adFree, clientSideParticipations) => {
|
|
|
41
42
|
isSignedIn: !!getCookie({ name: 'GU_U' }),
|
|
42
43
|
pageViewId: window.guardian.config.ophan.pageViewId,
|
|
43
44
|
participations: {
|
|
44
|
-
clientSideParticipations,
|
|
45
|
+
clientSideParticipations: getParticipationsFromLocalStorage(),
|
|
45
46
|
serverSideParticipations: window.guardian.config.tests ?? {},
|
|
46
47
|
},
|
|
47
48
|
referrer: getReferrer(),
|