@guardian/commercial-core 4.2.0 → 4.4.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 +1 -1
- package/dist/cjs/ad-sizes.js +4 -0
- package/dist/cjs/send-commercial-metrics.js +2 -2
- package/dist/cjs/targeting/personalised.js +11 -19
- package/dist/esm/ad-sizes.d.ts +1 -1
- package/dist/esm/ad-sizes.js +4 -0
- package/dist/esm/send-commercial-metrics.js +2 -2
- package/dist/esm/targeting/personalised.js +11 -19
- package/package.json +3 -3
package/dist/cjs/ad-sizes.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ declare class AdSize extends Array<number> {
|
|
|
25
25
|
get height(): number;
|
|
26
26
|
}
|
|
27
27
|
declare type SizeKeys = '160x600' | '300x1050' | '300x250' | '300x600' | '728x90' | '970x250' | 'billboard' | 'empty' | 'fabric' | 'fluid' | 'googleCard' | 'halfPage' | 'inlineMerchandising' | 'leaderboard' | 'merchandising' | 'merchandisingHigh' | 'merchandisingHighAdFeature' | 'mobilesticky' | 'mpu' | 'outOfPage' | 'outstreamDesktop' | 'outstreamGoogleDesktop' | 'outstreamMobile' | 'portrait' | 'skyscraper';
|
|
28
|
-
declare type SlotName = 'right' | 'comments' | 'top-above-nav' | 'mostpop' | 'merchandising' | 'merchandising-high' | 'merchandising-high-lucky' | 'survey' | 'im' | 'inline' | 'mostpop' | 'comments' | 'top-above-nav' | 'carrot' | 'epic' | 'mobile-sticky';
|
|
28
|
+
declare type SlotName = 'right' | 'comments' | 'top-above-nav' | 'mostpop' | 'merchandising' | 'merchandising-high' | 'merchandising-high-lucky' | 'survey' | 'im' | 'inline' | 'mostpop' | 'comments' | 'top-above-nav' | 'carrot' | 'epic' | 'mobile-sticky' | 'crossword-banner';
|
|
29
29
|
declare type Breakpoint = 'mobile' | 'desktop' | 'phablet' | 'tablet';
|
|
30
30
|
declare type SizeMapping = Partial<Record<Breakpoint, AdSize[]>>;
|
|
31
31
|
declare type SlotSizeMappings = Record<SlotName, SizeMapping>;
|
package/dist/cjs/ad-sizes.js
CHANGED
|
@@ -243,6 +243,10 @@ const slotSizeMappings = {
|
|
|
243
243
|
'mobile-sticky': {
|
|
244
244
|
mobile: [adSizes.mobilesticky],
|
|
245
245
|
},
|
|
246
|
+
'crossword-banner': {
|
|
247
|
+
tablet: [adSizes.outOfPage, adSizes.empty, adSizes.leaderboard],
|
|
248
|
+
phablet: [adSizes.outOfPage, adSizes.empty, adSizes.leaderboard],
|
|
249
|
+
},
|
|
246
250
|
};
|
|
247
251
|
exports.slotSizeMappings = slotSizeMappings;
|
|
248
252
|
const getAdSize = (size) => adSizes[size];
|
|
@@ -83,9 +83,9 @@ const listener = (e) => {
|
|
|
83
83
|
};
|
|
84
84
|
const addVisibilityListeners = () => {
|
|
85
85
|
// Report all available metrics when the page is unloaded or in background.
|
|
86
|
-
window.addEventListener('visibilitychange', listener);
|
|
86
|
+
window.addEventListener('visibilitychange', listener, { once: true });
|
|
87
87
|
// Safari does not reliably fire the `visibilitychange` on page unload.
|
|
88
|
-
window.addEventListener('pagehide', listener);
|
|
88
|
+
window.addEventListener('pagehide', listener, { once: true });
|
|
89
89
|
};
|
|
90
90
|
const checkConsent = async () => {
|
|
91
91
|
const consentState = await (0, consent_management_platform_1.onConsent)();
|
|
@@ -73,39 +73,27 @@ const getFrequencyValue = (state) => {
|
|
|
73
73
|
}
|
|
74
74
|
return '0';
|
|
75
75
|
};
|
|
76
|
-
const tcfv2AllPurposesConsented = (consents) => Object.keys(consents).length > 0 && Object.values(consents).every(Boolean);
|
|
77
|
-
const personalisedAdvertising = (state) => {
|
|
78
|
-
if (state.tcfv2)
|
|
79
|
-
return tcfv2AllPurposesConsented(state.tcfv2.consents);
|
|
80
|
-
if (state.ccpa)
|
|
81
|
-
return !state.ccpa.doNotSell;
|
|
82
|
-
if (state.aus)
|
|
83
|
-
return state.aus.personalisedAdvertising;
|
|
84
|
-
return false;
|
|
85
|
-
};
|
|
86
76
|
const getCMPTargeting = (state) => {
|
|
87
77
|
if (state.tcfv2) {
|
|
88
78
|
return {
|
|
89
79
|
cmp_interaction: state.tcfv2.eventStatus,
|
|
90
|
-
pa:
|
|
91
|
-
consent_tcfv2:
|
|
92
|
-
? 't'
|
|
93
|
-
: 'f',
|
|
80
|
+
pa: state.canTarget ? 't' : 'f',
|
|
81
|
+
consent_tcfv2: state.canTarget ? 't' : 'f',
|
|
94
82
|
rdp: 'na',
|
|
95
83
|
};
|
|
96
84
|
}
|
|
97
85
|
if (state.ccpa) {
|
|
98
86
|
return {
|
|
99
87
|
consent_tcfv2: 'na',
|
|
100
|
-
rdp: state.
|
|
101
|
-
pa: state.
|
|
88
|
+
rdp: !state.canTarget ? 't' : 'f',
|
|
89
|
+
pa: state.canTarget ? 't' : 'f',
|
|
102
90
|
};
|
|
103
91
|
}
|
|
104
92
|
if (state.aus) {
|
|
105
93
|
return {
|
|
106
94
|
consent_tcfv2: 'na',
|
|
107
95
|
rdp: 'na',
|
|
108
|
-
pa: state.
|
|
96
|
+
pa: state.canTarget ? 't' : 'f',
|
|
109
97
|
};
|
|
110
98
|
}
|
|
111
99
|
return {
|
|
@@ -123,7 +111,11 @@ const createAdManagerGroup = () => {
|
|
|
123
111
|
return group;
|
|
124
112
|
};
|
|
125
113
|
const getAdManagerGroup = (state) => {
|
|
126
|
-
if (!
|
|
114
|
+
if (!state.framework) {
|
|
115
|
+
libs_1.storage.local.remove(AMTGRP_STORAGE_KEY);
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (state.tcfv2 && !state.canTarget) {
|
|
127
119
|
libs_1.storage.local.remove(AMTGRP_STORAGE_KEY);
|
|
128
120
|
return null;
|
|
129
121
|
}
|
|
@@ -133,7 +125,7 @@ const getAdManagerGroup = (state) => {
|
|
|
133
125
|
: createAdManagerGroup();
|
|
134
126
|
};
|
|
135
127
|
const getPermutiveWithState = (state) => {
|
|
136
|
-
if (
|
|
128
|
+
if (state.canTarget)
|
|
137
129
|
return (0, permutive_1.getPermutiveSegments)();
|
|
138
130
|
(0, permutive_1.clearPermutiveSegments)();
|
|
139
131
|
return [];
|
package/dist/esm/ad-sizes.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ declare class AdSize extends Array<number> {
|
|
|
25
25
|
get height(): number;
|
|
26
26
|
}
|
|
27
27
|
declare type SizeKeys = '160x600' | '300x1050' | '300x250' | '300x600' | '728x90' | '970x250' | 'billboard' | 'empty' | 'fabric' | 'fluid' | 'googleCard' | 'halfPage' | 'inlineMerchandising' | 'leaderboard' | 'merchandising' | 'merchandisingHigh' | 'merchandisingHighAdFeature' | 'mobilesticky' | 'mpu' | 'outOfPage' | 'outstreamDesktop' | 'outstreamGoogleDesktop' | 'outstreamMobile' | 'portrait' | 'skyscraper';
|
|
28
|
-
declare type SlotName = 'right' | 'comments' | 'top-above-nav' | 'mostpop' | 'merchandising' | 'merchandising-high' | 'merchandising-high-lucky' | 'survey' | 'im' | 'inline' | 'mostpop' | 'comments' | 'top-above-nav' | 'carrot' | 'epic' | 'mobile-sticky';
|
|
28
|
+
declare type SlotName = 'right' | 'comments' | 'top-above-nav' | 'mostpop' | 'merchandising' | 'merchandising-high' | 'merchandising-high-lucky' | 'survey' | 'im' | 'inline' | 'mostpop' | 'comments' | 'top-above-nav' | 'carrot' | 'epic' | 'mobile-sticky' | 'crossword-banner';
|
|
29
29
|
declare type Breakpoint = 'mobile' | 'desktop' | 'phablet' | 'tablet';
|
|
30
30
|
declare type SizeMapping = Partial<Record<Breakpoint, AdSize[]>>;
|
|
31
31
|
declare type SlotSizeMappings = Record<SlotName, SizeMapping>;
|
package/dist/esm/ad-sizes.js
CHANGED
|
@@ -238,6 +238,10 @@ const slotSizeMappings = {
|
|
|
238
238
|
'mobile-sticky': {
|
|
239
239
|
mobile: [adSizes.mobilesticky],
|
|
240
240
|
},
|
|
241
|
+
'crossword-banner': {
|
|
242
|
+
tablet: [adSizes.outOfPage, adSizes.empty, adSizes.leaderboard],
|
|
243
|
+
phablet: [adSizes.outOfPage, adSizes.empty, adSizes.leaderboard],
|
|
244
|
+
},
|
|
241
245
|
};
|
|
242
246
|
const getAdSize = (size) => adSizes[size];
|
|
243
247
|
// Export for testing
|
|
@@ -80,9 +80,9 @@ const listener = (e) => {
|
|
|
80
80
|
};
|
|
81
81
|
const addVisibilityListeners = () => {
|
|
82
82
|
// Report all available metrics when the page is unloaded or in background.
|
|
83
|
-
window.addEventListener('visibilitychange', listener);
|
|
83
|
+
window.addEventListener('visibilitychange', listener, { once: true });
|
|
84
84
|
// Safari does not reliably fire the `visibilitychange` on page unload.
|
|
85
|
-
window.addEventListener('pagehide', listener);
|
|
85
|
+
window.addEventListener('pagehide', listener, { once: true });
|
|
86
86
|
};
|
|
87
87
|
const checkConsent = async () => {
|
|
88
88
|
const consentState = await onConsent();
|
|
@@ -70,39 +70,27 @@ const getFrequencyValue = (state) => {
|
|
|
70
70
|
}
|
|
71
71
|
return '0';
|
|
72
72
|
};
|
|
73
|
-
const tcfv2AllPurposesConsented = (consents) => Object.keys(consents).length > 0 && Object.values(consents).every(Boolean);
|
|
74
|
-
const personalisedAdvertising = (state) => {
|
|
75
|
-
if (state.tcfv2)
|
|
76
|
-
return tcfv2AllPurposesConsented(state.tcfv2.consents);
|
|
77
|
-
if (state.ccpa)
|
|
78
|
-
return !state.ccpa.doNotSell;
|
|
79
|
-
if (state.aus)
|
|
80
|
-
return state.aus.personalisedAdvertising;
|
|
81
|
-
return false;
|
|
82
|
-
};
|
|
83
73
|
const getCMPTargeting = (state) => {
|
|
84
74
|
if (state.tcfv2) {
|
|
85
75
|
return {
|
|
86
76
|
cmp_interaction: state.tcfv2.eventStatus,
|
|
87
|
-
pa:
|
|
88
|
-
consent_tcfv2:
|
|
89
|
-
? 't'
|
|
90
|
-
: 'f',
|
|
77
|
+
pa: state.canTarget ? 't' : 'f',
|
|
78
|
+
consent_tcfv2: state.canTarget ? 't' : 'f',
|
|
91
79
|
rdp: 'na',
|
|
92
80
|
};
|
|
93
81
|
}
|
|
94
82
|
if (state.ccpa) {
|
|
95
83
|
return {
|
|
96
84
|
consent_tcfv2: 'na',
|
|
97
|
-
rdp: state.
|
|
98
|
-
pa: state.
|
|
85
|
+
rdp: !state.canTarget ? 't' : 'f',
|
|
86
|
+
pa: state.canTarget ? 't' : 'f',
|
|
99
87
|
};
|
|
100
88
|
}
|
|
101
89
|
if (state.aus) {
|
|
102
90
|
return {
|
|
103
91
|
consent_tcfv2: 'na',
|
|
104
92
|
rdp: 'na',
|
|
105
|
-
pa: state.
|
|
93
|
+
pa: state.canTarget ? 't' : 'f',
|
|
106
94
|
};
|
|
107
95
|
}
|
|
108
96
|
return {
|
|
@@ -120,7 +108,11 @@ const createAdManagerGroup = () => {
|
|
|
120
108
|
return group;
|
|
121
109
|
};
|
|
122
110
|
const getAdManagerGroup = (state) => {
|
|
123
|
-
if (!
|
|
111
|
+
if (!state.framework) {
|
|
112
|
+
storage.local.remove(AMTGRP_STORAGE_KEY);
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (state.tcfv2 && !state.canTarget) {
|
|
124
116
|
storage.local.remove(AMTGRP_STORAGE_KEY);
|
|
125
117
|
return null;
|
|
126
118
|
}
|
|
@@ -130,7 +122,7 @@ const getAdManagerGroup = (state) => {
|
|
|
130
122
|
: createAdManagerGroup();
|
|
131
123
|
};
|
|
132
124
|
const getPermutiveWithState = (state) => {
|
|
133
|
-
if (
|
|
125
|
+
if (state.canTarget)
|
|
134
126
|
return getPermutiveSegments();
|
|
135
127
|
clearPermutiveSegments();
|
|
136
128
|
return [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guardian/commercial-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "Guardian advertising business logic",
|
|
5
5
|
"homepage": "https://github.com/guardian/commercial-core#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"prettier": "@guardian/prettier",
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@commitlint/cli": "^
|
|
45
|
+
"@commitlint/cli": "^17.0.3",
|
|
46
46
|
"@commitlint/config-conventional": "^17.0.0",
|
|
47
47
|
"@guardian/ab-core": "^2.0.0",
|
|
48
48
|
"@guardian/consent-management-platform": "^10.6.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"eslint-plugin-prettier": "^4.0.0",
|
|
68
68
|
"husky": "^8.0.1",
|
|
69
69
|
"jest": "^27.4.1",
|
|
70
|
-
"lint-staged": "^
|
|
70
|
+
"lint-staged": "^13.0.3",
|
|
71
71
|
"mockdate": "^3.0.5",
|
|
72
72
|
"npm-run-all": "^4.1.5",
|
|
73
73
|
"prettier": "^2.5.0",
|