@guardian/commercial-core 3.2.1 → 3.5.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 +23 -5
- package/dist/cjs/ad-sizes.js +118 -3
- package/dist/cjs/constants/index.d.ts +2 -2
- package/dist/cjs/constants/index.js +4 -4
- package/dist/cjs/constants/{prebidTimeout.d.ts → prebid-timeout.d.ts} +0 -0
- package/dist/cjs/constants/{prebidTimeout.js → prebid-timeout.js} +0 -0
- package/dist/cjs/constants/{topAboveNavHeight.d.ts → top-above-nav-height.d.ts} +0 -0
- package/dist/cjs/constants/{topAboveNavHeight.js → top-above-nav-height.js} +0 -0
- package/dist/cjs/{detectAdBlocker.d.ts → detect-ad-blocker.d.ts} +2 -1
- package/dist/cjs/{detectAdBlocker.js → detect-ad-blocker.js} +2 -1
- package/dist/cjs/{EventTimer.d.ts → event-timer.d.ts} +2 -1
- package/dist/cjs/{EventTimer.js → event-timer.js} +2 -2
- package/dist/cjs/{GoogleAnalytics.d.ts → google-analytics.d.ts} +0 -0
- package/dist/cjs/{GoogleAnalytics.js → google-analytics.js} +0 -0
- package/dist/cjs/index.d.ts +5 -4
- package/dist/cjs/index.js +16 -9
- package/dist/cjs/permutive.d.ts +4 -3
- package/dist/cjs/permutive.js +1 -1
- package/dist/{esm/sendCommercialMetrics.d.ts → cjs/send-commercial-metrics.d.ts} +3 -3
- package/dist/cjs/{sendCommercialMetrics.js → send-commercial-metrics.js} +33 -16
- package/dist/cjs/targeting/content.d.ts +4 -3
- package/dist/cjs/targeting/personalised.d.ts +2 -1
- package/dist/cjs/targeting/session.d.ts +5 -4
- package/dist/cjs/targeting/shared.d.ts +8 -5
- package/dist/cjs/targeting/shared.js +1 -1
- package/dist/cjs/targeting/viewport.d.ts +4 -3
- package/dist/cjs/track-gpc-signal.d.ts +7 -0
- package/dist/cjs/track-gpc-signal.js +17 -0
- package/dist/cjs/track-scroll-depth.js +2 -2
- package/dist/cjs/types.d.ts +3 -4
- package/dist/esm/ad-sizes.d.ts +23 -5
- package/dist/esm/ad-sizes.js +116 -2
- package/dist/esm/constants/index.d.ts +2 -2
- package/dist/esm/constants/index.js +2 -2
- package/dist/esm/constants/{prebidTimeout.d.ts → prebid-timeout.d.ts} +0 -0
- package/dist/esm/constants/{prebidTimeout.js → prebid-timeout.js} +0 -0
- package/dist/esm/constants/{topAboveNavHeight.d.ts → top-above-nav-height.d.ts} +0 -0
- package/dist/esm/constants/{topAboveNavHeight.js → top-above-nav-height.js} +0 -0
- package/dist/esm/{detectAdBlocker.d.ts → detect-ad-blocker.d.ts} +2 -1
- package/dist/esm/{detectAdBlocker.js → detect-ad-blocker.js} +2 -1
- package/dist/esm/{EventTimer.d.ts → event-timer.d.ts} +2 -1
- package/dist/esm/{EventTimer.js → event-timer.js} +1 -1
- package/dist/esm/{GoogleAnalytics.d.ts → google-analytics.d.ts} +0 -0
- package/dist/esm/{GoogleAnalytics.js → google-analytics.js} +0 -0
- package/dist/esm/index.d.ts +5 -4
- package/dist/esm/index.js +5 -4
- package/dist/esm/permutive.d.ts +4 -3
- package/dist/esm/permutive.js +4 -3
- package/dist/{cjs/sendCommercialMetrics.d.ts → esm/send-commercial-metrics.d.ts} +3 -3
- package/dist/esm/{sendCommercialMetrics.js → send-commercial-metrics.js} +32 -14
- package/dist/esm/targeting/content.d.ts +4 -3
- package/dist/esm/targeting/content.js +2 -1
- package/dist/esm/targeting/personalised.d.ts +2 -1
- package/dist/esm/targeting/session.d.ts +5 -4
- package/dist/esm/targeting/session.js +2 -1
- package/dist/esm/targeting/shared.d.ts +8 -5
- package/dist/esm/targeting/shared.js +2 -1
- package/dist/esm/targeting/viewport.d.ts +4 -3
- package/dist/esm/targeting/viewport.js +2 -1
- package/dist/esm/track-gpc-signal.d.ts +7 -0
- package/dist/esm/track-gpc-signal.js +14 -0
- package/dist/esm/track-scroll-depth.js +1 -1
- package/dist/esm/types.d.ts +3 -4
- package/package.json +9 -9
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initTrackGpcSignal = void 0;
|
|
4
|
+
const libs_1 = require("@guardian/libs");
|
|
5
|
+
const event_timer_1 = require("./event-timer");
|
|
6
|
+
/**
|
|
7
|
+
* Collect metrics on gpcSignal presence and value
|
|
8
|
+
* https://globalprivacycontrol.github.io/gpc-spec/
|
|
9
|
+
*/
|
|
10
|
+
const initTrackGpcSignal = (consentState) => {
|
|
11
|
+
// If undefined we set the property value to -1, false is 0, true is 1
|
|
12
|
+
const gpcSignal = consentState.gpcSignal === undefined ? -1 : +consentState.gpcSignal;
|
|
13
|
+
const eventTimer = event_timer_1.EventTimer.get();
|
|
14
|
+
(0, libs_1.log)('commercial', `gpcSignal ${gpcSignal}`);
|
|
15
|
+
eventTimer.setProperty('gpcSignal', gpcSignal);
|
|
16
|
+
};
|
|
17
|
+
exports.initTrackGpcSignal = initTrackGpcSignal;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initTrackScrollDepth = void 0;
|
|
4
4
|
const libs_1 = require("@guardian/libs");
|
|
5
|
-
const
|
|
5
|
+
const event_timer_1 = require("./event-timer");
|
|
6
6
|
/**
|
|
7
7
|
* Collect commercial metrics on scroll depth
|
|
8
8
|
* Insert hidden elements at intervals of 1 viewport height
|
|
@@ -14,7 +14,7 @@ const initTrackScrollDepth = () => {
|
|
|
14
14
|
const intViewportHeight = window.innerHeight;
|
|
15
15
|
// how many viewports tall is the page?
|
|
16
16
|
const pageHeightVH = Math.floor(pageHeight / intViewportHeight);
|
|
17
|
-
const eventTimer =
|
|
17
|
+
const eventTimer = event_timer_1.EventTimer.get();
|
|
18
18
|
eventTimer.setProperty('pageHeightVH', pageHeightVH);
|
|
19
19
|
const observer = new IntersectionObserver(
|
|
20
20
|
/* istanbul ignore next */
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -55,7 +55,6 @@ export declare type AdsConfigTCFV2 = AdsConfigBasic & {
|
|
|
55
55
|
export declare type AdsConfigEnabled = AdsConfigBasic | AdsConfigCCPAorAus | AdsConfigTCFV2;
|
|
56
56
|
export declare type AdsConfig = AdsConfigEnabled | AdsConfigDisabled;
|
|
57
57
|
export declare type AdTargetingBuilder = () => Promise<AdsConfig>;
|
|
58
|
-
declare type True = 't';
|
|
59
|
-
declare type False = 'f';
|
|
60
|
-
declare type NotApplicable = 'na';
|
|
61
|
-
export type { True, False, NotApplicable };
|
|
58
|
+
export declare type True = 't';
|
|
59
|
+
export declare type False = 'f';
|
|
60
|
+
export declare type NotApplicable = 'na';
|
package/dist/esm/ad-sizes.d.ts
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
declare type AdSizeString = 'fluid' | `${number},${number}`;
|
|
2
|
+
declare type AdSize = Readonly<{
|
|
3
3
|
width: number;
|
|
4
4
|
height: number;
|
|
5
5
|
toString: () => AdSizeString;
|
|
6
6
|
}>;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
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';
|
|
8
|
+
interface SizeMapping {
|
|
9
|
+
mobile?: AdSize[];
|
|
10
|
+
desktop?: AdSize[];
|
|
11
|
+
phablet?: AdSize[];
|
|
12
|
+
tablet?: AdSize[];
|
|
13
|
+
}
|
|
14
|
+
interface SizeMappings {
|
|
15
|
+
right: SizeMapping;
|
|
16
|
+
comments: SizeMapping;
|
|
17
|
+
'top-above-nav': SizeMapping;
|
|
18
|
+
mostpop: SizeMapping;
|
|
19
|
+
'merchandising-high': SizeMapping;
|
|
20
|
+
merchandising: SizeMapping;
|
|
21
|
+
survey: SizeMapping;
|
|
22
|
+
}
|
|
23
|
+
declare const adSizes: Record<SizeKeys, AdSize>;
|
|
24
|
+
declare const sizeMappings: SizeMappings;
|
|
25
|
+
declare const getAdSize: (size: SizeKeys) => AdSize;
|
|
10
26
|
export declare const _: {
|
|
11
27
|
createAdSize: (width: number, height: number) => AdSize;
|
|
12
28
|
};
|
|
29
|
+
export type { AdSizeString, AdSize, SizeKeys };
|
|
30
|
+
export { adSizes, getAdSize, sizeMappings };
|
package/dist/esm/ad-sizes.js
CHANGED
|
@@ -30,7 +30,7 @@ const adSizesPartial = {
|
|
|
30
30
|
outstreamGoogleDesktop: createAdSize(550, 310),
|
|
31
31
|
outstreamMobile: createAdSize(300, 197),
|
|
32
32
|
};
|
|
33
|
-
|
|
33
|
+
const adSizes = {
|
|
34
34
|
...adSizesPartial,
|
|
35
35
|
'970x250': adSizesPartial.billboard,
|
|
36
36
|
'728x90': adSizesPartial.leaderboard,
|
|
@@ -39,6 +39,120 @@ export const adSizes = {
|
|
|
39
39
|
'300x1050': adSizesPartial.portrait,
|
|
40
40
|
'160x600': adSizesPartial.skyscraper,
|
|
41
41
|
};
|
|
42
|
-
|
|
42
|
+
const sizeMappings = {
|
|
43
|
+
right: {
|
|
44
|
+
mobile: [
|
|
45
|
+
adSizes.outOfPage,
|
|
46
|
+
adSizes.empty,
|
|
47
|
+
adSizes.mpu,
|
|
48
|
+
adSizes.googleCard,
|
|
49
|
+
adSizes.halfPage,
|
|
50
|
+
adSizes.fluid,
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
comments: {
|
|
54
|
+
mobile: [
|
|
55
|
+
adSizes.outOfPage,
|
|
56
|
+
adSizes.empty,
|
|
57
|
+
adSizes.halfPage,
|
|
58
|
+
adSizes.outstreamMobile,
|
|
59
|
+
adSizes.mpu,
|
|
60
|
+
adSizes.googleCard,
|
|
61
|
+
adSizes.fluid,
|
|
62
|
+
],
|
|
63
|
+
desktop: [
|
|
64
|
+
adSizes.outOfPage,
|
|
65
|
+
adSizes.empty,
|
|
66
|
+
adSizes.mpu,
|
|
67
|
+
adSizes.googleCard,
|
|
68
|
+
adSizes.fluid,
|
|
69
|
+
adSizes.halfPage,
|
|
70
|
+
adSizes.skyscraper,
|
|
71
|
+
],
|
|
72
|
+
phablet: [
|
|
73
|
+
adSizes.outOfPage,
|
|
74
|
+
adSizes.empty,
|
|
75
|
+
adSizes.outstreamMobile,
|
|
76
|
+
adSizes.mpu,
|
|
77
|
+
adSizes.googleCard,
|
|
78
|
+
adSizes.fluid,
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
'top-above-nav': {
|
|
82
|
+
tablet: [
|
|
83
|
+
adSizes.outOfPage,
|
|
84
|
+
adSizes.empty,
|
|
85
|
+
adSizes.fabric,
|
|
86
|
+
adSizes.fluid,
|
|
87
|
+
adSizes.leaderboard,
|
|
88
|
+
],
|
|
89
|
+
desktop: [
|
|
90
|
+
adSizes.outOfPage,
|
|
91
|
+
adSizes.empty,
|
|
92
|
+
adSizes.leaderboard,
|
|
93
|
+
createAdSize(940, 230),
|
|
94
|
+
createAdSize(900, 250),
|
|
95
|
+
adSizes.billboard,
|
|
96
|
+
adSizes.fabric,
|
|
97
|
+
adSizes.fluid,
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
mostpop: {
|
|
101
|
+
mobile: [
|
|
102
|
+
adSizes.outOfPage,
|
|
103
|
+
adSizes.empty,
|
|
104
|
+
adSizes.mpu,
|
|
105
|
+
adSizes.googleCard,
|
|
106
|
+
adSizes.fluid,
|
|
107
|
+
],
|
|
108
|
+
tablet: [
|
|
109
|
+
adSizes.outOfPage,
|
|
110
|
+
adSizes.empty,
|
|
111
|
+
adSizes.mpu,
|
|
112
|
+
adSizes.googleCard,
|
|
113
|
+
adSizes.halfPage,
|
|
114
|
+
adSizes.leaderboard,
|
|
115
|
+
adSizes.fluid,
|
|
116
|
+
],
|
|
117
|
+
phablet: [
|
|
118
|
+
adSizes.outOfPage,
|
|
119
|
+
adSizes.empty,
|
|
120
|
+
adSizes.outstreamMobile,
|
|
121
|
+
adSizes.mpu,
|
|
122
|
+
adSizes.googleCard,
|
|
123
|
+
adSizes.halfPage,
|
|
124
|
+
adSizes.fluid,
|
|
125
|
+
],
|
|
126
|
+
desktop: [
|
|
127
|
+
adSizes.outOfPage,
|
|
128
|
+
adSizes.empty,
|
|
129
|
+
adSizes.mpu,
|
|
130
|
+
adSizes.googleCard,
|
|
131
|
+
adSizes.halfPage,
|
|
132
|
+
adSizes.fluid,
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
'merchandising-high': {
|
|
136
|
+
mobile: [
|
|
137
|
+
adSizes.outOfPage,
|
|
138
|
+
adSizes.empty,
|
|
139
|
+
adSizes.merchandisingHigh,
|
|
140
|
+
adSizes.fluid,
|
|
141
|
+
],
|
|
142
|
+
},
|
|
143
|
+
merchandising: {
|
|
144
|
+
mobile: [
|
|
145
|
+
adSizes.outOfPage,
|
|
146
|
+
adSizes.empty,
|
|
147
|
+
adSizes.merchandising,
|
|
148
|
+
adSizes.fluid,
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
survey: {
|
|
152
|
+
desktop: [adSizes.outOfPage],
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
const getAdSize = (size) => adSizes[size];
|
|
43
156
|
// Export for testing
|
|
44
157
|
export const _ = { createAdSize };
|
|
158
|
+
export { adSizes, getAdSize, sizeMappings };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { PREBID_TIMEOUT } from './
|
|
2
|
-
export { TOP_ABOVE_NAV_HEIGHT } from './
|
|
1
|
+
export { PREBID_TIMEOUT } from './prebid-timeout';
|
|
2
|
+
export { TOP_ABOVE_NAV_HEIGHT } from './top-above-nav-height';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { PREBID_TIMEOUT } from './
|
|
2
|
-
export { TOP_ABOVE_NAV_HEIGHT } from './
|
|
1
|
+
export { PREBID_TIMEOUT } from './prebid-timeout';
|
|
2
|
+
export { TOP_ABOVE_NAV_HEIGHT } from './top-above-nav-height';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
Detect whether or not the user has an ad blocking extension enabled.
|
|
3
3
|
A few ad blockers are not detectable with this approach e.g. Safari / Adblock
|
|
4
|
-
Code inspired by just-detect-adblock's:
|
|
4
|
+
Code inspired by just-detect-adblock's:
|
|
5
|
+
https://github.com/wmcmurray/just-detect-adblock/blob/master/src/helpers.js
|
|
5
6
|
*/
|
|
6
7
|
/**
|
|
7
8
|
* Determines whether or not the user has an ad blocking extension enabled.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
Detect whether or not the user has an ad blocking extension enabled.
|
|
3
3
|
A few ad blockers are not detectable with this approach e.g. Safari / Adblock
|
|
4
|
-
Code inspired by just-detect-adblock's:
|
|
4
|
+
Code inspired by just-detect-adblock's:
|
|
5
|
+
https://github.com/wmcmurray/just-detect-adblock/blob/master/src/helpers.js
|
|
5
6
|
*/
|
|
6
7
|
/*istanbul ignore file -- adElementBlocked can't be tested without patching each of the properties of
|
|
7
8
|
HTMLElement.prototype that it accesses, defeating the purpose of the test! */
|
|
@@ -30,6 +30,7 @@ interface EventTimerProperties {
|
|
|
30
30
|
adSlotsInline?: number;
|
|
31
31
|
adSlotsTotal?: number;
|
|
32
32
|
pageHeightVH?: number;
|
|
33
|
+
gpcSignal?: number;
|
|
33
34
|
lazyLoadMarginPercent?: number;
|
|
34
35
|
}
|
|
35
36
|
export declare class EventTimer {
|
|
@@ -71,7 +72,7 @@ export declare class EventTimer {
|
|
|
71
72
|
* @param {string} name - the property's name
|
|
72
73
|
* @param {value} number - the property's value
|
|
73
74
|
*/
|
|
74
|
-
setProperty(name: 'adSlotsInline' | 'adSlotsTotal' | 'pageHeightVH' | 'lazyLoadMarginPercent', value: number): void;
|
|
75
|
+
setProperty(name: 'adSlotsInline' | 'adSlotsTotal' | 'pageHeightVH' | 'gpcSignal' | 'lazyLoadMarginPercent', value: number): void;
|
|
75
76
|
/**
|
|
76
77
|
* Creates a new performance mark
|
|
77
78
|
* For slot events also ensures each TYPE of event event is marked only once for 'first'
|
|
File without changes
|
|
File without changes
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -4,14 +4,15 @@ export { fbPixel } from './third-party-tags/facebook-pixel';
|
|
|
4
4
|
export { twitter } from './third-party-tags/twitter-uwt';
|
|
5
5
|
export { inizio } from './third-party-tags/inizio';
|
|
6
6
|
export { remarketing } from './third-party-tags/remarketing';
|
|
7
|
-
export { EventTimer } from './
|
|
8
|
-
export { bypassCommercialMetricsSampling, initCommercialMetrics, } from './
|
|
7
|
+
export { EventTimer } from './event-timer';
|
|
8
|
+
export { bypassCommercialMetricsSampling, initCommercialMetrics, } from './send-commercial-metrics';
|
|
9
9
|
export type { ThirdPartyTag } from './types';
|
|
10
|
-
export { adSizes, getAdSize } from './ad-sizes';
|
|
10
|
+
export { adSizes, getAdSize, sizeMappings } from './ad-sizes';
|
|
11
11
|
export type { SizeKeys, AdSizeString, AdSize } from './ad-sizes';
|
|
12
|
-
export { isAdBlockInUse } from './
|
|
12
|
+
export { isAdBlockInUse } from './detect-ad-blocker';
|
|
13
13
|
export { clearPermutiveSegments, getPermutiveSegments, getPermutivePFPSegments, } from './permutive';
|
|
14
14
|
export { initTrackScrollDepth } from './track-scroll-depth';
|
|
15
|
+
export { initTrackGpcSignal } from './track-gpc-signal';
|
|
15
16
|
export { buildAdsConfigWithConsent, disabledAds } from './ad-targeting-youtube';
|
|
16
17
|
export type { AdsConfig, AdsConfigBasic, AdsConfigDisabled, AdTargetingBuilder, CustomParams, } from './types';
|
|
17
18
|
export * as constants from './constants';
|
package/dist/esm/index.js
CHANGED
|
@@ -5,12 +5,13 @@ export { fbPixel } from './third-party-tags/facebook-pixel';
|
|
|
5
5
|
export { twitter } from './third-party-tags/twitter-uwt';
|
|
6
6
|
export { inizio } from './third-party-tags/inizio';
|
|
7
7
|
export { remarketing } from './third-party-tags/remarketing';
|
|
8
|
-
export { EventTimer } from './
|
|
9
|
-
export { bypassCommercialMetricsSampling, initCommercialMetrics, } from './
|
|
10
|
-
export { adSizes, getAdSize } from './ad-sizes';
|
|
11
|
-
export { isAdBlockInUse } from './
|
|
8
|
+
export { EventTimer } from './event-timer';
|
|
9
|
+
export { bypassCommercialMetricsSampling, initCommercialMetrics, } from './send-commercial-metrics';
|
|
10
|
+
export { adSizes, getAdSize, sizeMappings } from './ad-sizes';
|
|
11
|
+
export { isAdBlockInUse } from './detect-ad-blocker';
|
|
12
12
|
export { clearPermutiveSegments, getPermutiveSegments, getPermutivePFPSegments, } from './permutive';
|
|
13
13
|
export { initTrackScrollDepth } from './track-scroll-depth';
|
|
14
|
+
export { initTrackGpcSignal } from './track-gpc-signal';
|
|
14
15
|
export { buildAdsConfigWithConsent, disabledAds } from './ad-targeting-youtube';
|
|
15
16
|
import * as constants_1 from './constants';
|
|
16
17
|
export { constants_1 as constants };
|
package/dist/esm/permutive.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
declare const getPermutiveSegments: () => string[];
|
|
2
|
+
declare const getPermutivePFPSegments: () => string[];
|
|
3
|
+
declare const clearPermutiveSegments: () => void;
|
|
4
4
|
export declare const _: {
|
|
5
5
|
PERMUTIVE_KEY: string;
|
|
6
6
|
PERMUTIVE_PFP_KEY: string;
|
|
7
7
|
getSegments: (key: string) => string[];
|
|
8
8
|
};
|
|
9
|
+
export { getPermutiveSegments, getPermutivePFPSegments, clearPermutiveSegments, };
|
package/dist/esm/permutive.js
CHANGED
|
@@ -19,9 +19,9 @@ const getSegments = (key) => {
|
|
|
19
19
|
return [];
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const getPermutiveSegments = () => getSegments(PERMUTIVE_KEY);
|
|
23
|
+
const getPermutivePFPSegments = () => getSegments(PERMUTIVE_PFP_KEY);
|
|
24
|
+
const clearPermutiveSegments = () => {
|
|
25
25
|
storage.local.remove(PERMUTIVE_KEY);
|
|
26
26
|
storage.local.remove(PERMUTIVE_PFP_KEY);
|
|
27
27
|
};
|
|
@@ -30,3 +30,4 @@ export const _ = {
|
|
|
30
30
|
PERMUTIVE_PFP_KEY,
|
|
31
31
|
getSegments,
|
|
32
32
|
};
|
|
33
|
+
export { getPermutiveSegments, getPermutivePFPSegments, clearPermutiveSegments, };
|
|
@@ -22,7 +22,7 @@ declare enum Endpoints {
|
|
|
22
22
|
/**
|
|
23
23
|
* A method to asynchronously send metrics after initialization.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
declare function bypassCommercialMetricsSampling(): Promise<void>;
|
|
26
26
|
interface InitCommercialMetricsArgs {
|
|
27
27
|
pageViewId: string;
|
|
28
28
|
browserId: string | undefined;
|
|
@@ -38,14 +38,14 @@ interface InitCommercialMetricsArgs {
|
|
|
38
38
|
* @param init.adBlockerInUse - indicates whether or not an adblocker is being used.
|
|
39
39
|
* @param init.sampling - rate at which to sample commercial metrics - the default is to send for 1% of pageviews
|
|
40
40
|
*/
|
|
41
|
-
|
|
41
|
+
declare function initCommercialMetrics({ pageViewId, browserId, isDev, adBlockerInUse, sampling, }: InitCommercialMetricsArgs): Promise<boolean>;
|
|
42
42
|
export declare const _: {
|
|
43
43
|
Endpoints: typeof Endpoints;
|
|
44
44
|
setEndpoint: (isDev: boolean) => Endpoints;
|
|
45
|
-
filterUndefinedProperties: <T>(transformedProperties: [string, T | undefined][]) => [string, T][];
|
|
46
45
|
mapEventTimerPropertiesToString: (properties: Array<[string, string | number]>) => Property[];
|
|
47
46
|
roundTimeStamp: (events: TimedEvent[]) => Metric[];
|
|
48
47
|
transformToObjectEntries: (eventTimerProperties: EventProperties) => Array<[string, string | number | undefined]>;
|
|
49
48
|
reset: () => void;
|
|
50
49
|
};
|
|
51
50
|
export type { Property, TimedEvent, Metric };
|
|
51
|
+
export { bypassCommercialMetricsSampling, initCommercialMetrics };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { onConsent } from '@guardian/consent-management-platform';
|
|
1
2
|
import { log } from '@guardian/libs';
|
|
2
|
-
import { EventTimer } from './
|
|
3
|
+
import { EventTimer } from './event-timer';
|
|
3
4
|
var Endpoints;
|
|
4
5
|
(function (Endpoints) {
|
|
5
6
|
Endpoints["CODE"] = "//performance-events.code.dev-guardianapis.com/commercial-metrics";
|
|
@@ -35,12 +36,6 @@ const transformToObjectEntries = (eventTimerProperties) => {
|
|
|
35
36
|
// Transforms object {key: value} pairs into an array of [key, value] arrays
|
|
36
37
|
return Object.entries(eventTimerProperties);
|
|
37
38
|
};
|
|
38
|
-
const filterUndefinedProperties = (transformedProperties) => transformedProperties.reduce((acc, [key, value]) => {
|
|
39
|
-
if (typeof value !== 'undefined') {
|
|
40
|
-
acc.push([key, value]);
|
|
41
|
-
}
|
|
42
|
-
return acc;
|
|
43
|
-
}, []);
|
|
44
39
|
const mapEventTimerPropertiesToString = (properties) => {
|
|
45
40
|
return properties.map(([name, value]) => ({
|
|
46
41
|
name: String(name),
|
|
@@ -61,7 +56,7 @@ function gatherMetricsOnPageUnload() {
|
|
|
61
56
|
// Assemble commercial properties and metrics
|
|
62
57
|
const eventTimer = EventTimer.get();
|
|
63
58
|
const transformedEntries = transformToObjectEntries(eventTimer.properties);
|
|
64
|
-
const filteredEventTimerProperties =
|
|
59
|
+
const filteredEventTimerProperties = transformedEntries.filter((item) => typeof item[1] !== 'undefined');
|
|
65
60
|
const mappedEventTimerProperties = mapEventTimerPropertiesToString(filteredEventTimerProperties);
|
|
66
61
|
const properties = mappedEventTimerProperties
|
|
67
62
|
.concat(devProperties)
|
|
@@ -89,15 +84,32 @@ const addVisibilityListeners = () => {
|
|
|
89
84
|
// Safari does not reliably fire the `visibilitychange` on page unload.
|
|
90
85
|
window.addEventListener('pagehide', listener);
|
|
91
86
|
};
|
|
87
|
+
const checkConsent = async () => {
|
|
88
|
+
const consentState = await onConsent();
|
|
89
|
+
if (consentState.tcfv2) {
|
|
90
|
+
// TCFv2 mode - check for consent
|
|
91
|
+
const consents = consentState.tcfv2.consents;
|
|
92
|
+
const REQUIRED_CONSENTS = [7, 8];
|
|
93
|
+
return REQUIRED_CONSENTS.every((consent) => consents[consent]);
|
|
94
|
+
}
|
|
95
|
+
// non-TCFv2 mode - don't check for consent
|
|
96
|
+
return true;
|
|
97
|
+
};
|
|
92
98
|
/**
|
|
93
99
|
* A method to asynchronously send metrics after initialization.
|
|
94
100
|
*/
|
|
95
|
-
|
|
101
|
+
async function bypassCommercialMetricsSampling() {
|
|
96
102
|
if (!initialised) {
|
|
97
103
|
console.warn('initCommercialMetrics not yet initialised');
|
|
98
104
|
return;
|
|
99
105
|
}
|
|
100
|
-
|
|
106
|
+
const consented = await checkConsent();
|
|
107
|
+
if (consented) {
|
|
108
|
+
addVisibilityListeners();
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
log('commercial', "Metrics won't be sent because consent wasn't given");
|
|
112
|
+
}
|
|
101
113
|
}
|
|
102
114
|
/**
|
|
103
115
|
* A method to initialise metrics.
|
|
@@ -107,7 +119,7 @@ export function bypassCommercialMetricsSampling() {
|
|
|
107
119
|
* @param init.adBlockerInUse - indicates whether or not an adblocker is being used.
|
|
108
120
|
* @param init.sampling - rate at which to sample commercial metrics - the default is to send for 1% of pageviews
|
|
109
121
|
*/
|
|
110
|
-
|
|
122
|
+
async function initCommercialMetrics({ pageViewId, browserId, isDev, adBlockerInUse, sampling = 1 / 100, }) {
|
|
111
123
|
commercialMetricsPayload.page_view_id = pageViewId;
|
|
112
124
|
commercialMetricsPayload.browser_id = browserId;
|
|
113
125
|
setEndpoint(isDev);
|
|
@@ -119,15 +131,20 @@ export function initCommercialMetrics({ pageViewId, browserId, isDev, adBlockerI
|
|
|
119
131
|
initialised = true;
|
|
120
132
|
const userIsInSamplingGroup = Math.random() <= sampling;
|
|
121
133
|
if (isDev || userIsInSamplingGroup) {
|
|
122
|
-
|
|
123
|
-
|
|
134
|
+
const consented = await checkConsent();
|
|
135
|
+
if (consented) {
|
|
136
|
+
addVisibilityListeners();
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
log('commercial', "Metrics won't be sent because consent wasn't given");
|
|
141
|
+
}
|
|
124
142
|
}
|
|
125
143
|
return false;
|
|
126
144
|
}
|
|
127
145
|
export const _ = {
|
|
128
146
|
Endpoints,
|
|
129
147
|
setEndpoint,
|
|
130
|
-
filterUndefinedProperties,
|
|
131
148
|
mapEventTimerPropertiesToString,
|
|
132
149
|
roundTimeStamp,
|
|
133
150
|
transformToObjectEntries,
|
|
@@ -144,3 +161,4 @@ export const _ = {
|
|
|
144
161
|
removeEventListener('pagehide', listener);
|
|
145
162
|
},
|
|
146
163
|
};
|
|
164
|
+
export { bypassCommercialMetricsSampling, initCommercialMetrics };
|
|
@@ -12,7 +12,7 @@ declare const videoLengths: readonly ["25", "30", "60", "90", "120", "150", "180
|
|
|
12
12
|
* - a surge in page views per minute
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
declare type ContentTargeting = {
|
|
16
16
|
/**
|
|
17
17
|
* **D**ot**c**om-**r**endering **E**ligible - [see on Ad Manager][gam]
|
|
18
18
|
*
|
|
@@ -66,5 +66,6 @@ declare type Content = {
|
|
|
66
66
|
sensitive: boolean;
|
|
67
67
|
videoLength?: number;
|
|
68
68
|
};
|
|
69
|
-
|
|
70
|
-
export {};
|
|
69
|
+
declare const getContentTargeting: ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, }: Content) => ContentTargeting;
|
|
70
|
+
export { getContentTargeting };
|
|
71
|
+
export type { ContentTargeting };
|
|
@@ -25,7 +25,7 @@ const getUrlKeywords = (url) => {
|
|
|
25
25
|
.slice(-1)[0];
|
|
26
26
|
return isString(lastSegment) ? lastSegment.split('-').filter(Boolean) : [];
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
const getContentTargeting = ({ eligibleForDCR, path, renderingPlatform, section, sensitive, videoLength, }) => {
|
|
29
29
|
return {
|
|
30
30
|
dcre: eligibleForDCR ? 't' : 'f',
|
|
31
31
|
rp: renderingPlatform,
|
|
@@ -35,3 +35,4 @@ export const getContentTargeting = ({ eligibleForDCR, path, renderingPlatform, s
|
|
|
35
35
|
vl: videoLength ? getVideoLength(videoLength) : null,
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
|
+
export { getContentTargeting };
|
|
@@ -10,7 +10,7 @@ declare type AdManagerGroup = typeof adManagerGroups[number];
|
|
|
10
10
|
* It allows or prevents personalised advertising, restrict data processing
|
|
11
11
|
* and handles access to cookies and local storage
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
declare type PersonalisedTargeting = {
|
|
14
14
|
/**
|
|
15
15
|
* **A**d **M**anager **T**argeting **Gr**ou**p** – [see on Ad Manager][gam]
|
|
16
16
|
*
|
|
@@ -76,3 +76,4 @@ export declare type PersonalisedTargeting = {
|
|
|
76
76
|
};
|
|
77
77
|
declare const getPersonalisedTargeting: (state: ConsentState) => PersonalisedTargeting;
|
|
78
78
|
export { getPersonalisedTargeting };
|
|
79
|
+
export type { PersonalisedTargeting };
|
|
@@ -22,7 +22,7 @@ declare const referrers: readonly [{
|
|
|
22
22
|
* These values identify a browser session are either generated client-side,
|
|
23
23
|
* read from a cookie or passed down from the server.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
declare type SessionTargeting = {
|
|
26
26
|
/**
|
|
27
27
|
* **AB** Tests – [see on Ad Manager][gam]
|
|
28
28
|
*
|
|
@@ -90,7 +90,7 @@ export declare type SessionTargeting = {
|
|
|
90
90
|
*/
|
|
91
91
|
si: True | False;
|
|
92
92
|
};
|
|
93
|
-
|
|
93
|
+
declare type AllParticipations = {
|
|
94
94
|
clientSideParticipations: Participations;
|
|
95
95
|
serverSideParticipations: {
|
|
96
96
|
[key: `${string}Control`]: 'control';
|
|
@@ -105,5 +105,6 @@ declare type Session = {
|
|
|
105
105
|
participations: AllParticipations;
|
|
106
106
|
referrer: string;
|
|
107
107
|
};
|
|
108
|
-
|
|
109
|
-
export {};
|
|
108
|
+
declare const getSessionTargeting: ({ adTest, countryCode, isSignedIn, pageViewId, participations, referrer, }: Session) => SessionTargeting;
|
|
109
|
+
export type { SessionTargeting, AllParticipations };
|
|
110
|
+
export { getSessionTargeting };
|
|
@@ -46,7 +46,7 @@ const experimentsTargeting = ({ clientSideParticipations, serverSideParticipatio
|
|
|
46
46
|
}
|
|
47
47
|
return [...clientSideExperiment, ...serverSideExperiments];
|
|
48
48
|
};
|
|
49
|
-
|
|
49
|
+
const getSessionTargeting = ({ adTest, countryCode, isSignedIn, pageViewId, participations, referrer, }) => ({
|
|
50
50
|
ab: experimentsTargeting(participations),
|
|
51
51
|
at: adTest,
|
|
52
52
|
cc: countryCode,
|
|
@@ -54,3 +54,4 @@ export const getSessionTargeting = ({ adTest, countryCode, isSignedIn, pageViewI
|
|
|
54
54
|
ref: getReferrer(referrer),
|
|
55
55
|
si: isSignedIn ? 't' : 'f',
|
|
56
56
|
});
|
|
57
|
+
export { getSessionTargeting };
|
|
@@ -25,14 +25,16 @@ declare const surges: {
|
|
|
25
25
|
readonly 400: "1";
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
|
-
* Shared Targeting is passed by `frontend
|
|
28
|
+
* Shared Targeting is passed by `frontend`:
|
|
29
|
+
* https://github.com/guardian/frontend/blob/5b970cd7308175cfc1bcae2d4fb8c06ee13c5fa0/common/app/common/commercial/EditionAdTargeting.scala
|
|
29
30
|
*
|
|
30
|
-
* It is generated in `commercial-shared
|
|
31
|
+
* It is generated in `commercial-shared`:
|
|
32
|
+
* https://github.com/guardian/commercial-shared/blob/a692e8b2eba6e79eeeb666e5594f2193663f6514/src/main/scala/com/gu/commercial/display/AdTargetParam.scala
|
|
31
33
|
*
|
|
32
34
|
*
|
|
33
35
|
*
|
|
34
36
|
*/
|
|
35
|
-
|
|
37
|
+
declare type SharedTargeting = {
|
|
36
38
|
/**
|
|
37
39
|
* **Bl**og tags – [see on Ad Manager][gam]
|
|
38
40
|
*
|
|
@@ -135,8 +137,9 @@ export declare type SharedTargeting = {
|
|
|
135
137
|
/**
|
|
136
138
|
* What goes in comes out
|
|
137
139
|
*/
|
|
138
|
-
|
|
140
|
+
declare const getSharedTargeting: (shared: Partial<SharedTargeting>) => Partial<SharedTargeting>;
|
|
139
141
|
export declare const _: {
|
|
140
142
|
getSurgingParam: (surging: number) => SharedTargeting['su'];
|
|
141
143
|
};
|
|
142
|
-
export {};
|
|
144
|
+
export type { SharedTargeting };
|
|
145
|
+
export { getSharedTargeting };
|
|
@@ -48,7 +48,8 @@ const getSurgingParam = (surging) => {
|
|
|
48
48
|
/**
|
|
49
49
|
* What goes in comes out
|
|
50
50
|
*/
|
|
51
|
-
|
|
51
|
+
const getSharedTargeting = (shared) => pickTargetingValues(shared);
|
|
52
52
|
export const _ = {
|
|
53
53
|
getSurgingParam,
|
|
54
54
|
};
|
|
55
|
+
export { getSharedTargeting };
|
|
@@ -7,7 +7,7 @@ import type { False, True } from '../types';
|
|
|
7
7
|
* - whether a CMP banner will show
|
|
8
8
|
* - size of page skin
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
declare type ViewportTargeting = {
|
|
11
11
|
/**
|
|
12
12
|
* **B**reak**p**oint – [see on Ad Manager][gam]
|
|
13
13
|
*
|
|
@@ -43,5 +43,6 @@ declare type Viewport = {
|
|
|
43
43
|
viewPortWidth: number;
|
|
44
44
|
cmpBannerWillShow: boolean;
|
|
45
45
|
};
|
|
46
|
-
|
|
47
|
-
export {};
|
|
46
|
+
declare const getViewportTargeting: ({ viewPortWidth, cmpBannerWillShow, }: Viewport) => ViewportTargeting;
|
|
47
|
+
export type { ViewportTargeting };
|
|
48
|
+
export { getViewportTargeting };
|