@guardian/commercial-core 0.27.0 → 0.31.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/EventTimer.d.ts +2 -2
- package/dist/cjs/EventTimer.js +10 -7
- package/dist/cjs/ad-targeting-youtube.js +2 -2
- package/dist/cjs/targeting/content.d.ts +189 -0
- package/dist/cjs/targeting/content.js +90 -0
- package/dist/cjs/targeting/personalised.d.ts +78 -0
- package/dist/cjs/targeting/personalised.js +148 -0
- package/dist/cjs/targeting/session.d.ts +98 -0
- package/dist/cjs/targeting/session.js +57 -0
- package/dist/cjs/types.d.ts +5 -5
- package/dist/esm/EventTimer.d.ts +2 -2
- package/dist/esm/EventTimer.js +10 -7
- package/dist/esm/ad-targeting-youtube.js +1 -1
- package/dist/esm/targeting/content.d.ts +189 -0
- package/dist/esm/targeting/content.js +86 -0
- package/dist/esm/targeting/personalised.d.ts +78 -0
- package/dist/esm/targeting/personalised.js +145 -0
- package/dist/esm/targeting/session.d.ts +98 -0
- package/dist/esm/targeting/session.js +53 -0
- package/dist/esm/types.d.ts +5 -5
- package/package.json +23 -21
package/dist/cjs/EventTimer.d.ts
CHANGED
|
@@ -37,10 +37,10 @@ export declare class EventTimer {
|
|
|
37
37
|
effectiveType?: string;
|
|
38
38
|
};
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* Initialise the EventTimer class on page.
|
|
41
41
|
* Returns the singleton instance of the EventTimer class and binds
|
|
42
42
|
* to window.guardian.commercialTimer. If it's been previously
|
|
43
|
-
*
|
|
43
|
+
* initialised and bound it returns the original instance
|
|
44
44
|
* Note: We save to window.guardian.commercialTimer because
|
|
45
45
|
* different bundles (DCR / DCP) can use commercial core, and we want
|
|
46
46
|
* all timer events saved to a single instance per-page
|
package/dist/cjs/EventTimer.js
CHANGED
|
@@ -66,10 +66,10 @@ class EventTimer {
|
|
|
66
66
|
: {};
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
69
|
+
* Initialise the EventTimer class on page.
|
|
70
70
|
* Returns the singleton instance of the EventTimer class and binds
|
|
71
71
|
* to window.guardian.commercialTimer. If it's been previously
|
|
72
|
-
*
|
|
72
|
+
* initialised and bound it returns the original instance
|
|
73
73
|
* Note: We save to window.guardian.commercialTimer because
|
|
74
74
|
* different bundles (DCR / DCP) can use commercial core, and we want
|
|
75
75
|
* all timer events saved to a single instance per-page
|
|
@@ -125,7 +125,7 @@ class EventTimer {
|
|
|
125
125
|
* @param {origin} [origin=page] - Either 'page' (default) or the name of the slot
|
|
126
126
|
*/
|
|
127
127
|
trigger(eventName, origin = 'page') {
|
|
128
|
-
const
|
|
128
|
+
const TRACKED_SLOT_NAME = 'top-above-nav';
|
|
129
129
|
if (origin === 'page' &&
|
|
130
130
|
!this.triggers.page[eventName]) {
|
|
131
131
|
this.mark(eventName);
|
|
@@ -139,12 +139,12 @@ class EventTimer {
|
|
|
139
139
|
this.trackInGA(eventName, trackLabel);
|
|
140
140
|
this.triggers.first[eventName] = true;
|
|
141
141
|
}
|
|
142
|
-
if (origin ===
|
|
143
|
-
if (!this.triggers[
|
|
144
|
-
const trackLabel = `${
|
|
142
|
+
if (origin === TRACKED_SLOT_NAME) {
|
|
143
|
+
if (!this.triggers[TRACKED_SLOT_NAME][eventName]) {
|
|
144
|
+
const trackLabel = `${TRACKED_SLOT_NAME}-${eventName}`;
|
|
145
145
|
this.mark(trackLabel);
|
|
146
146
|
this.trackInGA(eventName, trackLabel);
|
|
147
|
-
this.triggers[
|
|
147
|
+
this.triggers[TRACKED_SLOT_NAME][eventName] = true;
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
}
|
|
@@ -159,9 +159,12 @@ class EventTimer {
|
|
|
159
159
|
exports.EventTimer = EventTimer;
|
|
160
160
|
EventTimer._externallyDefinedEventNames = [
|
|
161
161
|
'cmp-tcfv2-init',
|
|
162
|
+
'cmp-tcfv2-ui-displayed',
|
|
162
163
|
'cmp-tcfv2-got-consent',
|
|
163
164
|
'cmp-ccpa-init',
|
|
165
|
+
'cmp-ccpa-ui-displayed',
|
|
164
166
|
'cmp-ccpa-got-consent',
|
|
165
167
|
'cmp-aus-init',
|
|
168
|
+
'cmp-aus-ui-displayed',
|
|
166
169
|
'cmp-aus-got-consent',
|
|
167
170
|
];
|
|
@@ -5,6 +5,8 @@ const libs_1 = require("@guardian/libs");
|
|
|
5
5
|
const can_use_dom_1 = require("./lib/can-use-dom");
|
|
6
6
|
const construct_query_1 = require("./lib/construct-query");
|
|
7
7
|
const permutive_1 = require("./permutive");
|
|
8
|
+
const disabledAds = { disableAds: true };
|
|
9
|
+
exports.disabledAds = disabledAds;
|
|
8
10
|
const buildCustomParamsFromCookies = () => (0, can_use_dom_1.canUseDom)()
|
|
9
11
|
? {
|
|
10
12
|
permutive: (0, permutive_1.getPermutivePFPSegments)(),
|
|
@@ -54,8 +56,6 @@ const buildAdsConfig = (cmpConsent, adUnit, customParams) => {
|
|
|
54
56
|
// Shouldn't happen but handle if no matching framework
|
|
55
57
|
return disabledAds;
|
|
56
58
|
};
|
|
57
|
-
const disabledAds = { disableAds: true };
|
|
58
|
-
exports.disabledAds = disabledAds;
|
|
59
59
|
const buildAdsConfigWithConsent = (isAdFreeUser, adUnit, customParamsToMerge, consentState) => {
|
|
60
60
|
if (isAdFreeUser) {
|
|
61
61
|
return disabledAds;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { False, True } from '../types';
|
|
2
|
+
declare const brands: {
|
|
3
|
+
readonly Foundation: "f";
|
|
4
|
+
readonly Paid: "p";
|
|
5
|
+
readonly Sponsored: "s";
|
|
6
|
+
};
|
|
7
|
+
declare const editions: {
|
|
8
|
+
readonly UnitedKingdom: "uk";
|
|
9
|
+
readonly UnitedStates: "us";
|
|
10
|
+
readonly Australia: "au";
|
|
11
|
+
readonly International: "int";
|
|
12
|
+
};
|
|
13
|
+
declare const videoLengths: readonly ["25", "30", "60", "90", "120", "150", "180", "210", "240", "270", "300"];
|
|
14
|
+
declare const surges: {
|
|
15
|
+
readonly 0: "0";
|
|
16
|
+
readonly 50: "5";
|
|
17
|
+
readonly 100: "4";
|
|
18
|
+
readonly 200: "3";
|
|
19
|
+
readonly 300: "2";
|
|
20
|
+
readonly 400: "1";
|
|
21
|
+
};
|
|
22
|
+
declare const platforms: {
|
|
23
|
+
readonly R2: "r2";
|
|
24
|
+
readonly NextGen: "ng";
|
|
25
|
+
readonly MobileApp: "app";
|
|
26
|
+
readonly AcceleratedMobilePages: "amp";
|
|
27
|
+
};
|
|
28
|
+
declare const contentTypes: readonly ["article", "audio", "crossword", "gallery", "interactive", "liveblog", "network-front", "section", "tag", "video"];
|
|
29
|
+
/**
|
|
30
|
+
* Content Targeting comes from the server
|
|
31
|
+
*
|
|
32
|
+
* For a specific URL, it will only change on
|
|
33
|
+
* - a Composer/CAPI update
|
|
34
|
+
* - a rendering platform capability update
|
|
35
|
+
* - a main media update
|
|
36
|
+
* - a series tag update
|
|
37
|
+
* - a surge in page views per minute
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
40
|
+
export declare type ContentTargeting = {
|
|
41
|
+
/**
|
|
42
|
+
* **Bl**og tags – [see on Ad Manager][gam]
|
|
43
|
+
*
|
|
44
|
+
* Type: _Dynamic_
|
|
45
|
+
*
|
|
46
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=186687
|
|
47
|
+
*/
|
|
48
|
+
bl: string[];
|
|
49
|
+
/**
|
|
50
|
+
* **Br**anding - [see on Ad Manager][gam]
|
|
51
|
+
*
|
|
52
|
+
* Type: _Predefined_
|
|
53
|
+
*
|
|
54
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=259767
|
|
55
|
+
*/
|
|
56
|
+
br: typeof brands[keyof typeof brands] | null;
|
|
57
|
+
/**
|
|
58
|
+
* **Co**ntributor - [see on Ad Manager][gam]
|
|
59
|
+
*
|
|
60
|
+
* Array of all contributors to the content on the page
|
|
61
|
+
*
|
|
62
|
+
* Type: _Dynamic_
|
|
63
|
+
*
|
|
64
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=186207
|
|
65
|
+
*/
|
|
66
|
+
co: string[];
|
|
67
|
+
/**
|
|
68
|
+
* **C**ontent **T**ype - [see on Ad Manager][gam]
|
|
69
|
+
*
|
|
70
|
+
* Type: _Predefined_
|
|
71
|
+
*
|
|
72
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=177807
|
|
73
|
+
*/
|
|
74
|
+
ct: typeof contentTypes[number];
|
|
75
|
+
/**
|
|
76
|
+
* **D**ot**c**om-**r**endering **E**ligible - [see on Ad Manager][gam]
|
|
77
|
+
*
|
|
78
|
+
* Type: _Predefined_
|
|
79
|
+
*
|
|
80
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=11958028
|
|
81
|
+
*/
|
|
82
|
+
dcre: True | False;
|
|
83
|
+
/**
|
|
84
|
+
* **Edition** - [see on Ad Manager][gam]
|
|
85
|
+
*
|
|
86
|
+
* Type: _Predefined_
|
|
87
|
+
*
|
|
88
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=174207
|
|
89
|
+
*/
|
|
90
|
+
edition: typeof editions[keyof typeof editions];
|
|
91
|
+
/**
|
|
92
|
+
* **K**eywords - [see on Ad Manager][gam]
|
|
93
|
+
*
|
|
94
|
+
* Type: _Dynamic_
|
|
95
|
+
*
|
|
96
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=177687
|
|
97
|
+
*/
|
|
98
|
+
k: string[];
|
|
99
|
+
/**
|
|
100
|
+
* **Ob**server Content - [see on Ad Manager][gam]
|
|
101
|
+
*
|
|
102
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=256887
|
|
103
|
+
*/
|
|
104
|
+
ob: 't' | null;
|
|
105
|
+
/**
|
|
106
|
+
* **P**latform - [see on Ad Manager][gam]
|
|
107
|
+
*
|
|
108
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=180207
|
|
109
|
+
*/
|
|
110
|
+
p: typeof platforms[keyof typeof platforms];
|
|
111
|
+
/**
|
|
112
|
+
* Rendering Platform - [see on Ad Manager][gam]
|
|
113
|
+
*
|
|
114
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=11881005
|
|
115
|
+
*/
|
|
116
|
+
rp: 'dotcom-rendering' | 'dotcom-platform';
|
|
117
|
+
/**
|
|
118
|
+
* Site **S**ection - [see on Ad Manager][gam]
|
|
119
|
+
*
|
|
120
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=173967
|
|
121
|
+
*/
|
|
122
|
+
s: string;
|
|
123
|
+
/**
|
|
124
|
+
* **Se**ries - [see on Ad Manager][gam]
|
|
125
|
+
*
|
|
126
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=180447
|
|
127
|
+
*/
|
|
128
|
+
se: string[];
|
|
129
|
+
/**
|
|
130
|
+
* **Sens**itive - [see on Ad Manager][gam]
|
|
131
|
+
*
|
|
132
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=11654206
|
|
133
|
+
*/
|
|
134
|
+
sens: True | False;
|
|
135
|
+
/**
|
|
136
|
+
* **Su**rging Article - [see on Ad Manager][gam]
|
|
137
|
+
*
|
|
138
|
+
* Type: _Predefined_
|
|
139
|
+
*
|
|
140
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=185007
|
|
141
|
+
*/
|
|
142
|
+
su: Array<typeof surges[keyof typeof surges]>;
|
|
143
|
+
/**
|
|
144
|
+
* **T**o**n**es - [see on Ad Manager][gam]
|
|
145
|
+
*
|
|
146
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=191487
|
|
147
|
+
*/
|
|
148
|
+
tn: string[];
|
|
149
|
+
/**
|
|
150
|
+
* **U**niform **R**esource **L**ocator - [see on Ad Manager][gam]
|
|
151
|
+
*
|
|
152
|
+
* Relative to `www.theguardian.com`, starts with `/`
|
|
153
|
+
*
|
|
154
|
+
* Type: _Dynamic_
|
|
155
|
+
*
|
|
156
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=174327
|
|
157
|
+
*/
|
|
158
|
+
url: `/${string}`;
|
|
159
|
+
/**
|
|
160
|
+
* URL Keywords - [see on Ad Manager][gam]
|
|
161
|
+
*
|
|
162
|
+
* Type: _Dynamic_
|
|
163
|
+
*
|
|
164
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=12058265
|
|
165
|
+
*/
|
|
166
|
+
urlkw: string[];
|
|
167
|
+
/**
|
|
168
|
+
* **V**ideo **L**ength - [see on Ad Manager][gam]
|
|
169
|
+
*
|
|
170
|
+
* Video.JS only (?)
|
|
171
|
+
*
|
|
172
|
+
* Type: _Predefined_
|
|
173
|
+
*
|
|
174
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=195087
|
|
175
|
+
*/
|
|
176
|
+
vl: null | typeof videoLengths[number];
|
|
177
|
+
};
|
|
178
|
+
export declare const getContentTargeting: ({ branding, contentType, contributors, platform, sensitive, tones, path, videoLength, surging, }: {
|
|
179
|
+
branding?: "Foundation" | "Paid" | "Sponsored" | undefined;
|
|
180
|
+
contentType: typeof contentTypes[number];
|
|
181
|
+
contributors: string[];
|
|
182
|
+
platform: keyof typeof platforms;
|
|
183
|
+
sensitive: boolean;
|
|
184
|
+
tones: ContentTargeting['tn'];
|
|
185
|
+
path: ContentTargeting['url'];
|
|
186
|
+
videoLength?: number | undefined;
|
|
187
|
+
surging: number;
|
|
188
|
+
}, targeting: Omit<ContentTargeting, 'br' | 'ct' | 'co' | 'p' | 'sens' | 'tn' | 'url' | 'urlkw' | 'vl' | 'su'>) => ContentTargeting;
|
|
189
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContentTargeting = void 0;
|
|
4
|
+
const libs_1 = require("@guardian/libs");
|
|
5
|
+
/* -- Types -- */
|
|
6
|
+
const brands = {
|
|
7
|
+
Foundation: 'f',
|
|
8
|
+
Paid: 'p',
|
|
9
|
+
Sponsored: 's',
|
|
10
|
+
};
|
|
11
|
+
const editions = {
|
|
12
|
+
UnitedKingdom: 'uk',
|
|
13
|
+
UnitedStates: 'us',
|
|
14
|
+
Australia: 'au',
|
|
15
|
+
International: 'int',
|
|
16
|
+
};
|
|
17
|
+
const videoLengths = [
|
|
18
|
+
'25',
|
|
19
|
+
'30',
|
|
20
|
+
'60',
|
|
21
|
+
'90',
|
|
22
|
+
'120',
|
|
23
|
+
'150',
|
|
24
|
+
'180',
|
|
25
|
+
'210',
|
|
26
|
+
'240',
|
|
27
|
+
'270',
|
|
28
|
+
'300',
|
|
29
|
+
];
|
|
30
|
+
const surges = {
|
|
31
|
+
0: '0',
|
|
32
|
+
50: '5',
|
|
33
|
+
100: '4',
|
|
34
|
+
200: '3',
|
|
35
|
+
300: '2',
|
|
36
|
+
400: '1',
|
|
37
|
+
};
|
|
38
|
+
const platforms = {
|
|
39
|
+
R2: 'r2',
|
|
40
|
+
NextGen: 'ng',
|
|
41
|
+
MobileApp: 'app',
|
|
42
|
+
AcceleratedMobilePages: 'amp',
|
|
43
|
+
};
|
|
44
|
+
const contentTypes = [
|
|
45
|
+
'article',
|
|
46
|
+
'audio',
|
|
47
|
+
'crossword',
|
|
48
|
+
'gallery',
|
|
49
|
+
'interactive',
|
|
50
|
+
'liveblog',
|
|
51
|
+
'network-front',
|
|
52
|
+
'section',
|
|
53
|
+
'tag',
|
|
54
|
+
'video',
|
|
55
|
+
];
|
|
56
|
+
/* -- Methods -- */
|
|
57
|
+
const getVideoLength = (videoLength) => {
|
|
58
|
+
const index = Math.min(Math.ceil(videoLength / 30), 10);
|
|
59
|
+
return videoLengths[index] ?? null;
|
|
60
|
+
};
|
|
61
|
+
const getUrlKeywords = (url) => {
|
|
62
|
+
const lastSegment = url
|
|
63
|
+
.split('/')
|
|
64
|
+
.filter(Boolean) // This handles a trailing slash
|
|
65
|
+
.slice(-1)[0];
|
|
66
|
+
return (0, libs_1.isString)(lastSegment) ? lastSegment.split('-').filter(Boolean) : [];
|
|
67
|
+
};
|
|
68
|
+
const getSurgingParam = (surging) => {
|
|
69
|
+
if (surging < 50 || isNaN(surging))
|
|
70
|
+
return ['0'];
|
|
71
|
+
const thresholds = [400, 300, 200, 100, 50];
|
|
72
|
+
return thresholds.filter((n) => n <= surging).map((s) => surges[s]);
|
|
73
|
+
};
|
|
74
|
+
/* -- Targeting -- */
|
|
75
|
+
const getContentTargeting = ({ branding, contentType, contributors, platform, sensitive, tones, path, videoLength, surging, }, targeting) => {
|
|
76
|
+
return {
|
|
77
|
+
...targeting,
|
|
78
|
+
br: branding ? brands[branding] : null,
|
|
79
|
+
co: contributors,
|
|
80
|
+
ct: contentType,
|
|
81
|
+
p: platforms[platform],
|
|
82
|
+
sens: sensitive ? 't' : 'f',
|
|
83
|
+
tn: tones,
|
|
84
|
+
su: getSurgingParam(surging),
|
|
85
|
+
url: path,
|
|
86
|
+
urlkw: getUrlKeywords(path),
|
|
87
|
+
vl: videoLength ? getVideoLength(videoLength) : null,
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
exports.getContentTargeting = getContentTargeting;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ConsentState } from '@guardian/consent-management-platform/dist/types';
|
|
2
|
+
import type { TCEventStatusCode } from '@guardian/consent-management-platform/dist/types/tcfv2';
|
|
3
|
+
import type { False, NotApplicable, True } from '../types';
|
|
4
|
+
declare const frequency: readonly ["0", "1", "2", "3", "4", "5", "6-9", "10-15", "16-19", "20-29", "30plus"];
|
|
5
|
+
declare const adManagerGroups: readonly ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
|
|
6
|
+
declare type AdManagerGroup = typeof adManagerGroups[number];
|
|
7
|
+
/**
|
|
8
|
+
* Personalised Targeting requires user consent
|
|
9
|
+
*
|
|
10
|
+
* It allows or prevents personalised advertising, restrict data processing
|
|
11
|
+
* and handles access to cookies and local storage
|
|
12
|
+
*/
|
|
13
|
+
export declare type PersonalisedTargeting = {
|
|
14
|
+
/**
|
|
15
|
+
* **A**d **M**anager **T**argeting **Gr**ou**p** – [see on Ad Manager][gam]
|
|
16
|
+
*
|
|
17
|
+
* Type: _Predefined_
|
|
18
|
+
*
|
|
19
|
+
* Sample values:
|
|
20
|
+
* -
|
|
21
|
+
*
|
|
22
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=12318099
|
|
23
|
+
* */
|
|
24
|
+
amtgrp: AdManagerGroup | null;
|
|
25
|
+
/**
|
|
26
|
+
* Interaction with TCFv2 banner – [see on Ad Manager][gam]
|
|
27
|
+
*
|
|
28
|
+
* Type: _Predefined_
|
|
29
|
+
*
|
|
30
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=12083384
|
|
31
|
+
*/
|
|
32
|
+
cmp_interaction?: TCEventStatusCode | NotApplicable;
|
|
33
|
+
/**
|
|
34
|
+
* **TCFv2 Consent** to [all purposes] – [see on Ad Manager][gam]
|
|
35
|
+
*
|
|
36
|
+
* Type: _Predefined_
|
|
37
|
+
*
|
|
38
|
+
* [all purposes]: https://vendor-list.consensu.org/v2/vendor-list.json
|
|
39
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=12080297
|
|
40
|
+
* */
|
|
41
|
+
consent_tcfv2: True | False | NotApplicable;
|
|
42
|
+
/**
|
|
43
|
+
* **Fr**equency – [see on Ad Manager][gam]
|
|
44
|
+
*
|
|
45
|
+
* Type: _Predefined_
|
|
46
|
+
*
|
|
47
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=214647
|
|
48
|
+
*/
|
|
49
|
+
fr: typeof frequency[number];
|
|
50
|
+
/**
|
|
51
|
+
* **P**ersonalised **A**ds Consent – [see on Ad Manager][gam]
|
|
52
|
+
*
|
|
53
|
+
* Type: _Predefined_
|
|
54
|
+
*
|
|
55
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=11701767
|
|
56
|
+
*/
|
|
57
|
+
pa: True | False;
|
|
58
|
+
/**
|
|
59
|
+
* **Permutive** user segments – [see on Ad Manager][gam]
|
|
60
|
+
*
|
|
61
|
+
* Type: _Predefined_
|
|
62
|
+
*
|
|
63
|
+
* Values: 900+ number IDs
|
|
64
|
+
*
|
|
65
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=11958727
|
|
66
|
+
*/
|
|
67
|
+
permutive: string[];
|
|
68
|
+
/**
|
|
69
|
+
* **R**estrict **D**ata **P**rocessing Flag – [see on Ad Manager][gam]
|
|
70
|
+
*
|
|
71
|
+
* Type: _Predefined_
|
|
72
|
+
*
|
|
73
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=11701767
|
|
74
|
+
*/
|
|
75
|
+
rdp: True | False | NotApplicable;
|
|
76
|
+
};
|
|
77
|
+
declare const getPersonalisedTargeting: (state: ConsentState) => PersonalisedTargeting;
|
|
78
|
+
export { getPersonalisedTargeting };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPersonalisedTargeting = void 0;
|
|
4
|
+
const libs_1 = require("@guardian/libs");
|
|
5
|
+
const permutive_1 = require("../permutive");
|
|
6
|
+
/* -- Types -- */
|
|
7
|
+
const frequency = [
|
|
8
|
+
'0',
|
|
9
|
+
'1',
|
|
10
|
+
'2',
|
|
11
|
+
'3',
|
|
12
|
+
'4',
|
|
13
|
+
'5',
|
|
14
|
+
'6-9',
|
|
15
|
+
'10-15',
|
|
16
|
+
'16-19',
|
|
17
|
+
'20-29',
|
|
18
|
+
'30plus',
|
|
19
|
+
];
|
|
20
|
+
const AMTGRP_STORAGE_KEY = 'gu.adManagerGroup';
|
|
21
|
+
const adManagerGroups = [
|
|
22
|
+
'1',
|
|
23
|
+
'2',
|
|
24
|
+
'3',
|
|
25
|
+
'4',
|
|
26
|
+
'5',
|
|
27
|
+
'6',
|
|
28
|
+
'7',
|
|
29
|
+
'8',
|
|
30
|
+
'9',
|
|
31
|
+
'10',
|
|
32
|
+
'11',
|
|
33
|
+
'12',
|
|
34
|
+
];
|
|
35
|
+
/* -- Methods -- */
|
|
36
|
+
const getRawWithConsent = (key, state) => {
|
|
37
|
+
if (state.tcfv2) {
|
|
38
|
+
if (state.tcfv2.consents['1'])
|
|
39
|
+
return libs_1.storage.local.getRaw(key);
|
|
40
|
+
}
|
|
41
|
+
if (state.ccpa) {
|
|
42
|
+
if (!state.ccpa.doNotSell)
|
|
43
|
+
return libs_1.storage.local.getRaw(key);
|
|
44
|
+
}
|
|
45
|
+
if (state.aus) {
|
|
46
|
+
if (state.aus.personalisedAdvertising)
|
|
47
|
+
return libs_1.storage.local.getRaw(key);
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
const getFrequencyValue = (state) => {
|
|
52
|
+
const rawValue = getRawWithConsent('gu.alreadyVisited', state);
|
|
53
|
+
if (!rawValue)
|
|
54
|
+
return '0';
|
|
55
|
+
const visitCount = parseInt(rawValue, 10);
|
|
56
|
+
if (visitCount <= 5) {
|
|
57
|
+
return frequency[visitCount] ?? '0';
|
|
58
|
+
}
|
|
59
|
+
else if (visitCount >= 6 && visitCount <= 9) {
|
|
60
|
+
return '6-9';
|
|
61
|
+
}
|
|
62
|
+
else if (visitCount >= 10 && visitCount <= 15) {
|
|
63
|
+
return '10-15';
|
|
64
|
+
}
|
|
65
|
+
else if (visitCount >= 16 && visitCount <= 19) {
|
|
66
|
+
return '16-19';
|
|
67
|
+
}
|
|
68
|
+
else if (visitCount >= 20 && visitCount <= 29) {
|
|
69
|
+
return '20-29';
|
|
70
|
+
}
|
|
71
|
+
else if (visitCount >= 30) {
|
|
72
|
+
return '30plus';
|
|
73
|
+
}
|
|
74
|
+
return '0';
|
|
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
|
+
const getCMPTargeting = (state) => {
|
|
87
|
+
if (state.tcfv2) {
|
|
88
|
+
return {
|
|
89
|
+
cmp_interaction: state.tcfv2.eventStatus,
|
|
90
|
+
pa: tcfv2AllPurposesConsented(state.tcfv2.consents) ? 't' : 'f',
|
|
91
|
+
consent_tcfv2: tcfv2AllPurposesConsented(state.tcfv2.consents)
|
|
92
|
+
? 't'
|
|
93
|
+
: 'f',
|
|
94
|
+
rdp: 'na',
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (state.ccpa) {
|
|
98
|
+
return {
|
|
99
|
+
consent_tcfv2: 'na',
|
|
100
|
+
rdp: state.ccpa.doNotSell ? 't' : 'f',
|
|
101
|
+
pa: state.ccpa.doNotSell ? 'f' : 't',
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (state.aus) {
|
|
105
|
+
return {
|
|
106
|
+
consent_tcfv2: 'na',
|
|
107
|
+
rdp: 'na',
|
|
108
|
+
pa: state.aus.personalisedAdvertising ? 't' : 'f',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
cmp_interaction: 'na',
|
|
113
|
+
consent_tcfv2: 'na',
|
|
114
|
+
rdp: 'na',
|
|
115
|
+
pa: 'f',
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
const isAdManagerGroup = (s) => adManagerGroups.some((g) => g === s);
|
|
119
|
+
const createAdManagerGroup = () => {
|
|
120
|
+
const index = Math.floor(Math.random() * adManagerGroups.length);
|
|
121
|
+
const group = adManagerGroups[index] ?? '12';
|
|
122
|
+
libs_1.storage.local.setRaw(AMTGRP_STORAGE_KEY, group);
|
|
123
|
+
return group;
|
|
124
|
+
};
|
|
125
|
+
const getAdManagerGroup = (state) => {
|
|
126
|
+
if (!personalisedAdvertising(state)) {
|
|
127
|
+
libs_1.storage.local.remove(AMTGRP_STORAGE_KEY);
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
const existingGroup = libs_1.storage.local.getRaw(AMTGRP_STORAGE_KEY);
|
|
131
|
+
return isAdManagerGroup(existingGroup)
|
|
132
|
+
? existingGroup
|
|
133
|
+
: createAdManagerGroup();
|
|
134
|
+
};
|
|
135
|
+
const getPermutiveWithState = (state) => {
|
|
136
|
+
if (personalisedAdvertising(state))
|
|
137
|
+
return (0, permutive_1.getPermutiveSegments)();
|
|
138
|
+
(0, permutive_1.clearPermutiveSegments)();
|
|
139
|
+
return [];
|
|
140
|
+
};
|
|
141
|
+
/* -- Targeting -- */
|
|
142
|
+
const getPersonalisedTargeting = (state) => ({
|
|
143
|
+
amtgrp: getAdManagerGroup(state),
|
|
144
|
+
fr: getFrequencyValue(state),
|
|
145
|
+
permutive: getPermutiveWithState(state),
|
|
146
|
+
...getCMPTargeting(state),
|
|
147
|
+
});
|
|
148
|
+
exports.getPersonalisedTargeting = getPersonalisedTargeting;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Participations } from '@guardian/ab-core';
|
|
2
|
+
import type { CountryCode } from '@guardian/libs';
|
|
3
|
+
import type { False, True } from '../types';
|
|
4
|
+
declare const referrers: readonly [{
|
|
5
|
+
readonly id: "facebook";
|
|
6
|
+
readonly match: "facebook.com";
|
|
7
|
+
}, {
|
|
8
|
+
readonly id: "google";
|
|
9
|
+
readonly match: "www.google";
|
|
10
|
+
}, {
|
|
11
|
+
readonly id: "twitter";
|
|
12
|
+
readonly match: "/t.co/";
|
|
13
|
+
}, {
|
|
14
|
+
readonly id: "reddit";
|
|
15
|
+
readonly match: "reddit.com";
|
|
16
|
+
}];
|
|
17
|
+
/**
|
|
18
|
+
* Session Targeting is based on the browser session
|
|
19
|
+
*
|
|
20
|
+
* Includes information such as the country of origin, referrer, page view ID.
|
|
21
|
+
*
|
|
22
|
+
* These values identify a browser session are either generated client-side,
|
|
23
|
+
* read from a cookie or passed down from the server.
|
|
24
|
+
*/
|
|
25
|
+
export declare type SessionTargeting = {
|
|
26
|
+
/**
|
|
27
|
+
* **AB** Tests – [see on Ad Manager][gam]
|
|
28
|
+
*
|
|
29
|
+
* Type: _Dynamic_
|
|
30
|
+
*
|
|
31
|
+
* Values: typically start with `ab`
|
|
32
|
+
*
|
|
33
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=186327
|
|
34
|
+
*/
|
|
35
|
+
ab: string[] | null;
|
|
36
|
+
/**
|
|
37
|
+
* **A**d **T**est – [see on Ad Manager][gam]
|
|
38
|
+
*
|
|
39
|
+
* Used for testing purposes, based on query param and/or cookie.
|
|
40
|
+
*
|
|
41
|
+
* Type: _Dynamic_
|
|
42
|
+
*
|
|
43
|
+
* [See Current values](https://frontend.gutools.co.uk/commercial/adtests)
|
|
44
|
+
*
|
|
45
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=177567
|
|
46
|
+
*/
|
|
47
|
+
at: string | null;
|
|
48
|
+
/**
|
|
49
|
+
* **C**ountry **C**ode – [see on Ad Manager][gam]
|
|
50
|
+
*
|
|
51
|
+
* Type: _Dynamic_
|
|
52
|
+
*
|
|
53
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=11703293
|
|
54
|
+
*/
|
|
55
|
+
cc: CountryCode;
|
|
56
|
+
/**
|
|
57
|
+
* Ophan **P**age **V**iew id – [see on Ad Manager][gam]
|
|
58
|
+
*
|
|
59
|
+
* ID Generated client-side, usually available on
|
|
60
|
+
* `guardian.config.ophan.pageViewId`
|
|
61
|
+
*
|
|
62
|
+
* Used mainly for internal reporting
|
|
63
|
+
*
|
|
64
|
+
* Type: _Dynamic_
|
|
65
|
+
*
|
|
66
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=206127
|
|
67
|
+
*/
|
|
68
|
+
pv: string;
|
|
69
|
+
/**
|
|
70
|
+
* **Ref**errer – [see on Ad Manager][gam]
|
|
71
|
+
*
|
|
72
|
+
* Type: _Dynamic_
|
|
73
|
+
*
|
|
74
|
+
* Sample values:
|
|
75
|
+
* - `facebook`
|
|
76
|
+
* - `google`
|
|
77
|
+
* - `googleplus`
|
|
78
|
+
* - `reddit`
|
|
79
|
+
* - `twitter`
|
|
80
|
+
*
|
|
81
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=228567
|
|
82
|
+
*/
|
|
83
|
+
ref: typeof referrers[number]['id'] | null;
|
|
84
|
+
/**
|
|
85
|
+
* **S**igned **I**n – [see on Ad Manager][gam]
|
|
86
|
+
*
|
|
87
|
+
*Whether a user is signed in. Based on presence of a cookie.
|
|
88
|
+
*
|
|
89
|
+
* [gam]: https://admanager.google.com/59666047#inventory/custom_targeting/detail/custom_key_id=215727
|
|
90
|
+
*/
|
|
91
|
+
si: True | False;
|
|
92
|
+
};
|
|
93
|
+
export declare type AllParticipations = {
|
|
94
|
+
clientSideParticipations: Participations;
|
|
95
|
+
serverSideParticipations: Record<string, 'control' | 'variant'>;
|
|
96
|
+
};
|
|
97
|
+
export declare const getSessionTargeting: (referrer: string, participations: AllParticipations, targeting: Omit<SessionTargeting, 'ab' | 'ref'>) => SessionTargeting;
|
|
98
|
+
export {};
|