@guardian/commercial-core 0.39.0 → 1.0.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 +3 -1
- package/dist/cjs/EventTimer.js +4 -2
- package/dist/cjs/ad-sizes.d.ts +1 -1
- package/dist/cjs/ad-sizes.js +10 -10
- package/dist/cjs/index.d.ts +12 -1
- package/dist/cjs/index.js +15 -2
- package/dist/cjs/sendCommercialMetrics.d.ts +43 -1
- package/dist/cjs/sendCommercialMetrics.js +142 -36
- package/dist/cjs/targeting/viewport.d.ts +6 -1
- package/dist/cjs/targeting/viewport.js +2 -3
- package/dist/cjs/third-party-tags/facebook-pixel.d.ts +5 -0
- package/dist/cjs/third-party-tags/facebook-pixel.js +5 -0
- package/dist/cjs/third-party-tags/ias.d.ts +5 -0
- package/dist/cjs/third-party-tags/ias.js +5 -0
- package/dist/cjs/third-party-tags/inizio.d.ts +5 -0
- package/dist/cjs/third-party-tags/inizio.js +5 -0
- package/dist/cjs/third-party-tags/permutive.d.ts +4 -0
- package/dist/cjs/third-party-tags/permutive.js +4 -0
- package/dist/cjs/third-party-tags/remarketing.d.ts +5 -0
- package/dist/cjs/third-party-tags/remarketing.js +5 -0
- package/dist/cjs/third-party-tags/twitter-uwt.d.ts +5 -0
- package/dist/cjs/third-party-tags/twitter-uwt.js +5 -0
- package/dist/esm/EventTimer.d.ts +3 -1
- package/dist/esm/EventTimer.js +4 -2
- package/dist/esm/ad-sizes.d.ts +1 -1
- package/dist/esm/ad-sizes.js +10 -10
- package/dist/esm/index.d.ts +12 -1
- package/dist/esm/index.js +7 -1
- package/dist/esm/sendCommercialMetrics.d.ts +43 -1
- package/dist/esm/sendCommercialMetrics.js +139 -34
- package/dist/esm/targeting/viewport.d.ts +6 -1
- package/dist/esm/targeting/viewport.js +2 -3
- package/dist/esm/third-party-tags/facebook-pixel.d.ts +5 -0
- package/dist/esm/third-party-tags/facebook-pixel.js +5 -0
- package/dist/esm/third-party-tags/ias.d.ts +5 -0
- package/dist/esm/third-party-tags/ias.js +5 -0
- package/dist/esm/third-party-tags/inizio.d.ts +5 -0
- package/dist/esm/third-party-tags/inizio.js +5 -0
- package/dist/esm/third-party-tags/permutive.d.ts +4 -0
- package/dist/esm/third-party-tags/permutive.js +4 -0
- package/dist/esm/third-party-tags/remarketing.d.ts +5 -0
- package/dist/esm/third-party-tags/remarketing.js +5 -0
- package/dist/esm/third-party-tags/twitter-uwt.d.ts +5 -0
- package/dist/esm/third-party-tags/twitter-uwt.js +5 -0
- package/package.json +6 -5
package/dist/cjs/EventTimer.d.ts
CHANGED
|
@@ -19,7 +19,9 @@ interface SlotEventStatus {
|
|
|
19
19
|
}
|
|
20
20
|
interface PageEventStatus {
|
|
21
21
|
commercialStart: boolean;
|
|
22
|
-
|
|
22
|
+
commercialExtraModulesLoaded: boolean;
|
|
23
|
+
commercialBaseModulesLoaded: boolean;
|
|
24
|
+
commercialModulesLoaded: boolean;
|
|
23
25
|
}
|
|
24
26
|
export declare class EventTimer {
|
|
25
27
|
private _events;
|
package/dist/cjs/EventTimer.js
CHANGED
|
@@ -29,7 +29,9 @@ class EventTimer {
|
|
|
29
29
|
},
|
|
30
30
|
page: {
|
|
31
31
|
commercialStart: false,
|
|
32
|
-
|
|
32
|
+
commercialExtraModulesLoaded: false,
|
|
33
|
+
commercialBaseModulesLoaded: false,
|
|
34
|
+
commercialModulesLoaded: false,
|
|
33
35
|
},
|
|
34
36
|
};
|
|
35
37
|
this.gaConfig = {
|
|
@@ -45,7 +47,7 @@ class EventTimer {
|
|
|
45
47
|
timingLabel: 'Commercial start parse time',
|
|
46
48
|
},
|
|
47
49
|
{
|
|
48
|
-
timingVariable: '
|
|
50
|
+
timingVariable: 'commercialModulesLoaded',
|
|
49
51
|
timingLabel: 'Commercial end parse time',
|
|
50
52
|
},
|
|
51
53
|
],
|
package/dist/cjs/ad-sizes.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare type AdSize = Readonly<{
|
|
|
4
4
|
height: number;
|
|
5
5
|
toString: () => AdSizeString;
|
|
6
6
|
}>;
|
|
7
|
-
export declare type SizeKeys = '
|
|
7
|
+
export 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' | 'video';
|
|
8
8
|
export declare const adSizes: Record<SizeKeys, AdSize>;
|
|
9
9
|
export declare const getAdSize: (size: SizeKeys) => AdSize;
|
|
10
10
|
export declare const _: {
|
package/dist/cjs/ad-sizes.js
CHANGED
|
@@ -12,27 +12,27 @@ const createAdSize = (width, height) => {
|
|
|
12
12
|
const adSizesPartial = {
|
|
13
13
|
// standard ad sizes
|
|
14
14
|
billboard: createAdSize(970, 250),
|
|
15
|
+
halfPage: createAdSize(300, 600),
|
|
15
16
|
leaderboard: createAdSize(728, 90),
|
|
17
|
+
mobilesticky: createAdSize(320, 50),
|
|
16
18
|
mpu: createAdSize(300, 250),
|
|
17
|
-
halfPage: createAdSize(300, 600),
|
|
18
19
|
portrait: createAdSize(300, 1050),
|
|
19
20
|
skyscraper: createAdSize(160, 600),
|
|
20
|
-
mobilesticky: createAdSize(320, 50),
|
|
21
21
|
// dfp proprietary ad sizes
|
|
22
22
|
fluid: createAdSize(0, 0),
|
|
23
|
-
outOfPage: createAdSize(1, 1),
|
|
24
23
|
googleCard: createAdSize(300, 274),
|
|
24
|
+
outOfPage: createAdSize(1, 1),
|
|
25
25
|
// guardian proprietary ad sizes
|
|
26
|
-
|
|
26
|
+
empty: createAdSize(2, 2),
|
|
27
|
+
fabric: createAdSize(88, 71),
|
|
28
|
+
inlineMerchandising: createAdSize(88, 85),
|
|
29
|
+
merchandising: createAdSize(88, 88),
|
|
30
|
+
merchandisingHigh: createAdSize(88, 87),
|
|
31
|
+
merchandisingHighAdFeature: createAdSize(88, 89),
|
|
27
32
|
outstreamDesktop: createAdSize(620, 350),
|
|
28
33
|
outstreamGoogleDesktop: createAdSize(550, 310),
|
|
29
34
|
outstreamMobile: createAdSize(300, 197),
|
|
30
|
-
|
|
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),
|
|
35
|
+
video: createAdSize(620, 1),
|
|
36
36
|
};
|
|
37
37
|
exports.adSizes = {
|
|
38
38
|
...adSizesPartial,
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ 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
7
|
export { EventTimer } from './EventTimer';
|
|
8
|
-
export {
|
|
8
|
+
export { bypassCommercialMetricsSampling, initCommercialMetrics, } from './sendCommercialMetrics';
|
|
9
9
|
export type { ThirdPartyTag } from './types';
|
|
10
10
|
export { adSizes, getAdSize } from './ad-sizes';
|
|
11
11
|
export type { SizeKeys, AdSizeString, AdSize } from './ad-sizes';
|
|
@@ -14,3 +14,14 @@ export { clearPermutiveSegments, getPermutiveSegments, getPermutivePFPSegments,
|
|
|
14
14
|
export { buildAdsConfigWithConsent, disabledAds } from './ad-targeting-youtube';
|
|
15
15
|
export type { AdsConfig, AdsConfigBasic, AdsConfigDisabled, AdTargetingBuilder, CustomParams, } from './types';
|
|
16
16
|
export * as constants from './constants';
|
|
17
|
+
export type { ContentTargeting } from './targeting/content';
|
|
18
|
+
export { getContentTargeting } from './targeting/content';
|
|
19
|
+
export type { PersonalisedTargeting } from './targeting/personalised';
|
|
20
|
+
export { getPersonalisedTargeting } from './targeting/personalised';
|
|
21
|
+
export type { SessionTargeting } from './targeting/session';
|
|
22
|
+
export { getSessionTargeting } from './targeting/session';
|
|
23
|
+
export type { SharedTargeting } from './targeting/shared';
|
|
24
|
+
export { getSharedTargeting } from './targeting/shared';
|
|
25
|
+
export type { ViewportTargeting } from './targeting/viewport';
|
|
26
|
+
export { getViewportTargeting } from './targeting/viewport';
|
|
27
|
+
export { pickTargetingValues } from './targeting/pick-targeting-values';
|
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.getAdSize = exports.adSizes = exports.
|
|
23
|
+
exports.pickTargetingValues = exports.getViewportTargeting = exports.getSharedTargeting = exports.getSessionTargeting = exports.getPersonalisedTargeting = exports.getContentTargeting = exports.constants = exports.disabledAds = exports.buildAdsConfigWithConsent = exports.getPermutivePFPSegments = exports.getPermutiveSegments = exports.clearPermutiveSegments = exports.isAdBlockInUse = exports.getAdSize = exports.adSizes = exports.initCommercialMetrics = exports.bypassCommercialMetricsSampling = 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");
|
|
@@ -36,7 +36,8 @@ Object.defineProperty(exports, "remarketing", { enumerable: true, get: function
|
|
|
36
36
|
var EventTimer_1 = require("./EventTimer");
|
|
37
37
|
Object.defineProperty(exports, "EventTimer", { enumerable: true, get: function () { return EventTimer_1.EventTimer; } });
|
|
38
38
|
var sendCommercialMetrics_1 = require("./sendCommercialMetrics");
|
|
39
|
-
Object.defineProperty(exports, "
|
|
39
|
+
Object.defineProperty(exports, "bypassCommercialMetricsSampling", { enumerable: true, get: function () { return sendCommercialMetrics_1.bypassCommercialMetricsSampling; } });
|
|
40
|
+
Object.defineProperty(exports, "initCommercialMetrics", { enumerable: true, get: function () { return sendCommercialMetrics_1.initCommercialMetrics; } });
|
|
40
41
|
var ad_sizes_1 = require("./ad-sizes");
|
|
41
42
|
Object.defineProperty(exports, "adSizes", { enumerable: true, get: function () { return ad_sizes_1.adSizes; } });
|
|
42
43
|
Object.defineProperty(exports, "getAdSize", { enumerable: true, get: function () { return ad_sizes_1.getAdSize; } });
|
|
@@ -50,3 +51,15 @@ var ad_targeting_youtube_1 = require("./ad-targeting-youtube");
|
|
|
50
51
|
Object.defineProperty(exports, "buildAdsConfigWithConsent", { enumerable: true, get: function () { return ad_targeting_youtube_1.buildAdsConfigWithConsent; } });
|
|
51
52
|
Object.defineProperty(exports, "disabledAds", { enumerable: true, get: function () { return ad_targeting_youtube_1.disabledAds; } });
|
|
52
53
|
exports.constants = __importStar(require("./constants"));
|
|
54
|
+
var content_1 = require("./targeting/content");
|
|
55
|
+
Object.defineProperty(exports, "getContentTargeting", { enumerable: true, get: function () { return content_1.getContentTargeting; } });
|
|
56
|
+
var personalised_1 = require("./targeting/personalised");
|
|
57
|
+
Object.defineProperty(exports, "getPersonalisedTargeting", { enumerable: true, get: function () { return personalised_1.getPersonalisedTargeting; } });
|
|
58
|
+
var session_1 = require("./targeting/session");
|
|
59
|
+
Object.defineProperty(exports, "getSessionTargeting", { enumerable: true, get: function () { return session_1.getSessionTargeting; } });
|
|
60
|
+
var shared_1 = require("./targeting/shared");
|
|
61
|
+
Object.defineProperty(exports, "getSharedTargeting", { enumerable: true, get: function () { return shared_1.getSharedTargeting; } });
|
|
62
|
+
var viewport_1 = require("./targeting/viewport");
|
|
63
|
+
Object.defineProperty(exports, "getViewportTargeting", { enumerable: true, get: function () { return viewport_1.getViewportTargeting; } });
|
|
64
|
+
var pick_targeting_values_1 = require("./targeting/pick-targeting-values");
|
|
65
|
+
Object.defineProperty(exports, "pickTargetingValues", { enumerable: true, get: function () { return pick_targeting_values_1.pickTargetingValues; } });
|
|
@@ -1 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
declare type Metric = {
|
|
2
|
+
name: string;
|
|
3
|
+
value: number;
|
|
4
|
+
};
|
|
5
|
+
declare type Property = {
|
|
6
|
+
name: string;
|
|
7
|
+
value: string;
|
|
8
|
+
};
|
|
9
|
+
declare type TimedEvent = {
|
|
10
|
+
name: string;
|
|
11
|
+
ts: number;
|
|
12
|
+
};
|
|
13
|
+
declare type EventProperties = {
|
|
14
|
+
type?: ConnectionType;
|
|
15
|
+
downlink?: number;
|
|
16
|
+
effectiveType?: string;
|
|
17
|
+
};
|
|
18
|
+
declare enum Endpoints {
|
|
19
|
+
CODE = "//performance-events.code.dev-guardianapis.com/commercial-metrics",
|
|
20
|
+
PROD = "//performance-events.guardianapis.com/commercial-metrics"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A method to asynchronously send metrics after initialization.
|
|
24
|
+
*/
|
|
25
|
+
export declare function bypassCommercialMetricsSampling(): void;
|
|
26
|
+
/**
|
|
27
|
+
* A method to initialise metrics.
|
|
28
|
+
* @param init.pageViewId - identifies the page view. Usually available on `guardian.config.ophan.pageViewId`. Defaults to `null`
|
|
29
|
+
* @param init.browserId - identifies the browser. Usually available via `getCookie({ name: 'bwid' })`. Defaults to `null`
|
|
30
|
+
* @param init.isDev - used to determine whether to use CODE or PROD endpoints.
|
|
31
|
+
* @param init.adBlockerInUse - indicates whether or not ann adblocker is being used.
|
|
32
|
+
*/
|
|
33
|
+
export declare function initCommercialMetrics(pageViewId: string, browserId: string | undefined, isDev: boolean, adBlockerInUse?: boolean, sampling?: number): boolean;
|
|
34
|
+
export declare const _: {
|
|
35
|
+
Endpoints: typeof Endpoints;
|
|
36
|
+
setEndpoint: (isDev: boolean) => Endpoints;
|
|
37
|
+
filterUndefinedProperties: <T>(transformedProperties: [string, T | undefined][]) => [string, T][];
|
|
38
|
+
mapEventTimerPropertiesToString: (properties: Array<[string, string | number]>) => Property[];
|
|
39
|
+
roundTimeStamp: (events: TimedEvent[]) => Metric[];
|
|
40
|
+
transformToObjectEntries: (eventTimerProperties: EventProperties) => Array<[string, string | number | undefined]>;
|
|
41
|
+
reset: () => void;
|
|
42
|
+
};
|
|
43
|
+
export type { Property, TimedEvent, Metric };
|
|
@@ -1,44 +1,150 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports._ = exports.initCommercialMetrics = exports.bypassCommercialMetricsSampling = void 0;
|
|
4
4
|
const libs_1 = require("@guardian/libs");
|
|
5
5
|
const EventTimer_1 = require("./EventTimer");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
6
|
+
var Endpoints;
|
|
7
|
+
(function (Endpoints) {
|
|
8
|
+
Endpoints["CODE"] = "//performance-events.code.dev-guardianapis.com/commercial-metrics";
|
|
9
|
+
Endpoints["PROD"] = "//performance-events.guardianapis.com/commercial-metrics";
|
|
10
|
+
})(Endpoints || (Endpoints = {}));
|
|
11
|
+
let commercialMetricsPayload = {
|
|
12
|
+
page_view_id: undefined,
|
|
13
|
+
browser_id: undefined,
|
|
14
|
+
platform: 'NEXT_GEN',
|
|
15
|
+
metrics: [],
|
|
16
|
+
properties: [],
|
|
17
|
+
};
|
|
18
|
+
let devProperties = [];
|
|
19
|
+
let adBlockerProperties = [];
|
|
20
|
+
let initialised = false;
|
|
21
|
+
let endpoint;
|
|
22
|
+
const setEndpoint = (isDev) => (endpoint = isDev ? Endpoints.CODE : Endpoints.PROD);
|
|
23
|
+
const setDevProperties = (isDev) => (devProperties = isDev
|
|
24
|
+
? [{ name: 'isDev', value: window.location.hostname }]
|
|
25
|
+
: []);
|
|
26
|
+
const setAdBlockerProperties = (adBlockerInUse) => {
|
|
27
|
+
adBlockerProperties =
|
|
28
|
+
adBlockerInUse !== undefined
|
|
29
|
+
? [
|
|
30
|
+
{
|
|
31
|
+
name: 'adBlockerInUse',
|
|
32
|
+
value: adBlockerInUse.toString(),
|
|
33
|
+
},
|
|
34
|
+
]
|
|
35
|
+
: [];
|
|
36
|
+
};
|
|
37
|
+
const transformToObjectEntries = (eventTimerProperties) => {
|
|
38
|
+
// Transforms object {key: value} pairs into an array of [key, value] arrays
|
|
39
|
+
return Object.entries(eventTimerProperties);
|
|
40
|
+
};
|
|
41
|
+
const filterUndefinedProperties = (transformedProperties) => transformedProperties.reduce((acc, [key, value]) => {
|
|
42
|
+
if (typeof value !== 'undefined') {
|
|
43
|
+
acc.push([key, value]);
|
|
44
|
+
}
|
|
45
|
+
return acc;
|
|
46
|
+
}, []);
|
|
47
|
+
const mapEventTimerPropertiesToString = (properties) => {
|
|
48
|
+
return properties.map(([name, value]) => ({
|
|
49
|
+
name: String(name),
|
|
50
|
+
value: String(value),
|
|
51
|
+
}));
|
|
52
|
+
};
|
|
53
|
+
const roundTimeStamp = (events) => {
|
|
54
|
+
return events.map(({ name, ts }) => ({
|
|
31
55
|
name,
|
|
32
56
|
value: Math.ceil(ts),
|
|
33
57
|
}));
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
};
|
|
59
|
+
function sendMetrics() {
|
|
60
|
+
(0, libs_1.log)('commercial', 'About to send commercial metrics', commercialMetricsPayload);
|
|
61
|
+
return navigator.sendBeacon(endpoint, JSON.stringify(commercialMetricsPayload));
|
|
62
|
+
}
|
|
63
|
+
function gatherMetricsOnPageUnload() {
|
|
64
|
+
// Assemble commercial properties and metrics
|
|
65
|
+
const eventTimer = EventTimer_1.EventTimer.get();
|
|
66
|
+
const transformedEntries = transformToObjectEntries(eventTimer.properties);
|
|
67
|
+
const filteredEventTimerProperties = filterUndefinedProperties(transformedEntries);
|
|
68
|
+
const mappedEventTimerProperties = mapEventTimerPropertiesToString(filteredEventTimerProperties);
|
|
69
|
+
const properties = mappedEventTimerProperties
|
|
70
|
+
.concat(devProperties)
|
|
71
|
+
.concat(adBlockerProperties);
|
|
72
|
+
commercialMetricsPayload.properties = properties;
|
|
73
|
+
const metrics = roundTimeStamp(eventTimer.events);
|
|
74
|
+
commercialMetricsPayload.metrics = metrics;
|
|
75
|
+
sendMetrics();
|
|
76
|
+
}
|
|
77
|
+
const listener = (e) => {
|
|
78
|
+
switch (e.type) {
|
|
79
|
+
case 'visibilitychange':
|
|
80
|
+
if (document.visibilityState === 'hidden') {
|
|
81
|
+
gatherMetricsOnPageUnload();
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
case 'pagehide':
|
|
85
|
+
gatherMetricsOnPageUnload();
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const addVisibilityListeners = () => {
|
|
90
|
+
// Report all available metrics when the page is unloaded or in background.
|
|
91
|
+
window.addEventListener('visibilitychange', listener);
|
|
92
|
+
// Safari does not reliably fire the `visibilitychange` on page unload.
|
|
93
|
+
window.addEventListener('pagehide', listener);
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* A method to asynchronously send metrics after initialization.
|
|
97
|
+
*/
|
|
98
|
+
function bypassCommercialMetricsSampling() {
|
|
99
|
+
if (!initialised) {
|
|
100
|
+
console.warn('initCommercialMetrics not yet initialised');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
addVisibilityListeners();
|
|
104
|
+
}
|
|
105
|
+
exports.bypassCommercialMetricsSampling = bypassCommercialMetricsSampling;
|
|
106
|
+
/**
|
|
107
|
+
* A method to initialise metrics.
|
|
108
|
+
* @param init.pageViewId - identifies the page view. Usually available on `guardian.config.ophan.pageViewId`. Defaults to `null`
|
|
109
|
+
* @param init.browserId - identifies the browser. Usually available via `getCookie({ name: 'bwid' })`. Defaults to `null`
|
|
110
|
+
* @param init.isDev - used to determine whether to use CODE or PROD endpoints.
|
|
111
|
+
* @param init.adBlockerInUse - indicates whether or not ann adblocker is being used.
|
|
112
|
+
*/
|
|
113
|
+
function initCommercialMetrics(pageViewId, browserId, isDev, adBlockerInUse, sampling = 1 / 100) {
|
|
114
|
+
commercialMetricsPayload.page_view_id = pageViewId;
|
|
115
|
+
commercialMetricsPayload.browser_id = browserId;
|
|
116
|
+
setEndpoint(isDev);
|
|
117
|
+
setDevProperties(isDev);
|
|
118
|
+
setAdBlockerProperties(adBlockerInUse);
|
|
119
|
+
if (initialised) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
initialised = true;
|
|
123
|
+
const userIsInSamplingGroup = Math.random() <= sampling;
|
|
124
|
+
if (isDev || userIsInSamplingGroup) {
|
|
125
|
+
addVisibilityListeners();
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
43
129
|
}
|
|
44
|
-
exports.
|
|
130
|
+
exports.initCommercialMetrics = initCommercialMetrics;
|
|
131
|
+
exports._ = {
|
|
132
|
+
Endpoints,
|
|
133
|
+
setEndpoint,
|
|
134
|
+
filterUndefinedProperties,
|
|
135
|
+
mapEventTimerPropertiesToString,
|
|
136
|
+
roundTimeStamp,
|
|
137
|
+
transformToObjectEntries,
|
|
138
|
+
reset: () => {
|
|
139
|
+
initialised = false;
|
|
140
|
+
commercialMetricsPayload = {
|
|
141
|
+
page_view_id: undefined,
|
|
142
|
+
browser_id: undefined,
|
|
143
|
+
platform: 'NEXT_GEN',
|
|
144
|
+
metrics: [],
|
|
145
|
+
properties: [],
|
|
146
|
+
};
|
|
147
|
+
removeEventListener('visibilitychange', listener);
|
|
148
|
+
removeEventListener('pagehide', listener);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
@@ -39,4 +39,9 @@ export declare type ViewportTargeting = {
|
|
|
39
39
|
*/
|
|
40
40
|
skinsize: 'l' | 's';
|
|
41
41
|
};
|
|
42
|
-
|
|
42
|
+
declare type Viewport = {
|
|
43
|
+
viewPortWidth: number;
|
|
44
|
+
cmpBannerWillShow: boolean;
|
|
45
|
+
};
|
|
46
|
+
export declare const getViewportTargeting: ({ viewPortWidth, cmpBannerWillShow, }: Viewport) => ViewportTargeting;
|
|
47
|
+
export {};
|
|
@@ -5,12 +5,11 @@ exports.getViewportTargeting = void 0;
|
|
|
5
5
|
const findBreakpoint = (width) => {
|
|
6
6
|
if (width >= 980)
|
|
7
7
|
return 'desktop';
|
|
8
|
-
if (width >=
|
|
8
|
+
if (width >= 660)
|
|
9
9
|
return 'tablet';
|
|
10
10
|
return 'mobile';
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
const getViewportTargeting = (viewPortWidth, cmpBannerWillShow) => {
|
|
12
|
+
const getViewportTargeting = ({ viewPortWidth, cmpBannerWillShow, }) => {
|
|
14
13
|
// Don’t show inskin if if a privacy message will be shown
|
|
15
14
|
const inskin = cmpBannerWillShow ? 'f' : 't';
|
|
16
15
|
return {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fbPixel = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* tracking pixel
|
|
6
|
+
* https://en-gb.facebook.com/business/learn/facebook-ads-pixel
|
|
7
|
+
* @param {} {shouldRun}
|
|
8
|
+
*/
|
|
4
9
|
const fbPixel = ({ shouldRun }) => ({
|
|
5
10
|
shouldRun,
|
|
6
11
|
url: `https://www.facebook.com/tr?id=279880532344561&ev=PageView&noscript=1`,
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ias = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* IAS script filters bad ads
|
|
6
|
+
* https://integralads.com/uk/
|
|
7
|
+
* @param {} {shouldRun}
|
|
8
|
+
*/
|
|
4
9
|
const ias = ({ shouldRun }) => ({
|
|
5
10
|
shouldRun,
|
|
6
11
|
url: '//cdn.adsafeprotected.com/iasPET.1.js',
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { GetThirdPartyTag } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Allows creatives to show survey
|
|
4
|
+
* https://trello.com/c/wHffHVF1/171-integrate-and-test-inizio
|
|
5
|
+
* @param {} {shouldRun}
|
|
6
|
+
*/
|
|
2
7
|
export declare const inizio: GetThirdPartyTag;
|
|
3
8
|
export declare const _: {
|
|
4
9
|
onLoad: () => void;
|
|
@@ -21,6 +21,11 @@ const onLoad = () => {
|
|
|
21
21
|
},
|
|
22
22
|
});
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Allows creatives to show survey
|
|
26
|
+
* https://trello.com/c/wHffHVF1/171-integrate-and-test-inizio
|
|
27
|
+
* @param {} {shouldRun}
|
|
28
|
+
*/
|
|
24
29
|
const inizio = ({ shouldRun }) => ({
|
|
25
30
|
shouldRun,
|
|
26
31
|
url: '//cdn.brandmetrics.com/survey/script/e96d04c832084488a841a06b49b8fb2d.js',
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.permutive = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Permutive script updates local user segmentation data
|
|
6
|
+
* @param {} {shouldRun}
|
|
7
|
+
*/
|
|
4
8
|
const permutive = ({ shouldRun }) => ({
|
|
5
9
|
shouldRun,
|
|
6
10
|
url: '//cdn.permutive.com/d6691a17-6fdb-4d26-85d6-b3dd27f55f08-web.js',
|
|
@@ -8,6 +8,11 @@ const onLoad = () => {
|
|
|
8
8
|
google_remarketing_only: true,
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Google conversion tracking
|
|
13
|
+
* https://support.google.com/google-ads/answer/6095821
|
|
14
|
+
* @param {} {shouldRun}
|
|
15
|
+
*/
|
|
11
16
|
const remarketing = ({ shouldRun }) => ({
|
|
12
17
|
shouldRun,
|
|
13
18
|
url: '//www.googleadservices.com/pagead/conversion_async.js',
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import type { GetThirdPartyTag } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* tracking pixel
|
|
4
|
+
* https://business.twitter.com/en/help/campaign-measurement-and-analytics/conversion-tracking-for-websites.html
|
|
5
|
+
* @param {} {shouldRun}
|
|
6
|
+
*/
|
|
2
7
|
export declare const twitter: GetThirdPartyTag;
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.twitter = void 0;
|
|
4
4
|
const twitter_script_1 = require("../__vendor/twitter-script");
|
|
5
|
+
/**
|
|
6
|
+
* tracking pixel
|
|
7
|
+
* https://business.twitter.com/en/help/campaign-measurement-and-analytics/conversion-tracking-for-websites.html
|
|
8
|
+
* @param {} {shouldRun}
|
|
9
|
+
*/
|
|
5
10
|
const twitter = ({ shouldRun }) => ({
|
|
6
11
|
shouldRun,
|
|
7
12
|
name: 'twitter',
|
package/dist/esm/EventTimer.d.ts
CHANGED
|
@@ -19,7 +19,9 @@ interface SlotEventStatus {
|
|
|
19
19
|
}
|
|
20
20
|
interface PageEventStatus {
|
|
21
21
|
commercialStart: boolean;
|
|
22
|
-
|
|
22
|
+
commercialExtraModulesLoaded: boolean;
|
|
23
|
+
commercialBaseModulesLoaded: boolean;
|
|
24
|
+
commercialModulesLoaded: boolean;
|
|
23
25
|
}
|
|
24
26
|
export declare class EventTimer {
|
|
25
27
|
private _events;
|
package/dist/esm/EventTimer.js
CHANGED
|
@@ -26,7 +26,9 @@ export class EventTimer {
|
|
|
26
26
|
},
|
|
27
27
|
page: {
|
|
28
28
|
commercialStart: false,
|
|
29
|
-
|
|
29
|
+
commercialExtraModulesLoaded: false,
|
|
30
|
+
commercialBaseModulesLoaded: false,
|
|
31
|
+
commercialModulesLoaded: false,
|
|
30
32
|
},
|
|
31
33
|
};
|
|
32
34
|
this.gaConfig = {
|
|
@@ -42,7 +44,7 @@ export class EventTimer {
|
|
|
42
44
|
timingLabel: 'Commercial start parse time',
|
|
43
45
|
},
|
|
44
46
|
{
|
|
45
|
-
timingVariable: '
|
|
47
|
+
timingVariable: 'commercialModulesLoaded',
|
|
46
48
|
timingLabel: 'Commercial end parse time',
|
|
47
49
|
},
|
|
48
50
|
],
|
package/dist/esm/ad-sizes.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare type AdSize = Readonly<{
|
|
|
4
4
|
height: number;
|
|
5
5
|
toString: () => AdSizeString;
|
|
6
6
|
}>;
|
|
7
|
-
export declare type SizeKeys = '
|
|
7
|
+
export 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' | 'video';
|
|
8
8
|
export declare const adSizes: Record<SizeKeys, AdSize>;
|
|
9
9
|
export declare const getAdSize: (size: SizeKeys) => AdSize;
|
|
10
10
|
export declare const _: {
|
package/dist/esm/ad-sizes.js
CHANGED
|
@@ -9,27 +9,27 @@ const createAdSize = (width, height) => {
|
|
|
9
9
|
const adSizesPartial = {
|
|
10
10
|
// standard ad sizes
|
|
11
11
|
billboard: createAdSize(970, 250),
|
|
12
|
+
halfPage: createAdSize(300, 600),
|
|
12
13
|
leaderboard: createAdSize(728, 90),
|
|
14
|
+
mobilesticky: createAdSize(320, 50),
|
|
13
15
|
mpu: createAdSize(300, 250),
|
|
14
|
-
halfPage: createAdSize(300, 600),
|
|
15
16
|
portrait: createAdSize(300, 1050),
|
|
16
17
|
skyscraper: createAdSize(160, 600),
|
|
17
|
-
mobilesticky: createAdSize(320, 50),
|
|
18
18
|
// dfp proprietary ad sizes
|
|
19
19
|
fluid: createAdSize(0, 0),
|
|
20
|
-
outOfPage: createAdSize(1, 1),
|
|
21
20
|
googleCard: createAdSize(300, 274),
|
|
21
|
+
outOfPage: createAdSize(1, 1),
|
|
22
22
|
// guardian proprietary ad sizes
|
|
23
|
-
|
|
23
|
+
empty: createAdSize(2, 2),
|
|
24
|
+
fabric: createAdSize(88, 71),
|
|
25
|
+
inlineMerchandising: createAdSize(88, 85),
|
|
26
|
+
merchandising: createAdSize(88, 88),
|
|
27
|
+
merchandisingHigh: createAdSize(88, 87),
|
|
28
|
+
merchandisingHighAdFeature: createAdSize(88, 89),
|
|
24
29
|
outstreamDesktop: createAdSize(620, 350),
|
|
25
30
|
outstreamGoogleDesktop: createAdSize(550, 310),
|
|
26
31
|
outstreamMobile: createAdSize(300, 197),
|
|
27
|
-
|
|
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),
|
|
32
|
+
video: createAdSize(620, 1),
|
|
33
33
|
};
|
|
34
34
|
export const adSizes = {
|
|
35
35
|
...adSizesPartial,
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ 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
7
|
export { EventTimer } from './EventTimer';
|
|
8
|
-
export {
|
|
8
|
+
export { bypassCommercialMetricsSampling, initCommercialMetrics, } from './sendCommercialMetrics';
|
|
9
9
|
export type { ThirdPartyTag } from './types';
|
|
10
10
|
export { adSizes, getAdSize } from './ad-sizes';
|
|
11
11
|
export type { SizeKeys, AdSizeString, AdSize } from './ad-sizes';
|
|
@@ -14,3 +14,14 @@ export { clearPermutiveSegments, getPermutiveSegments, getPermutivePFPSegments,
|
|
|
14
14
|
export { buildAdsConfigWithConsent, disabledAds } from './ad-targeting-youtube';
|
|
15
15
|
export type { AdsConfig, AdsConfigBasic, AdsConfigDisabled, AdTargetingBuilder, CustomParams, } from './types';
|
|
16
16
|
export * as constants from './constants';
|
|
17
|
+
export type { ContentTargeting } from './targeting/content';
|
|
18
|
+
export { getContentTargeting } from './targeting/content';
|
|
19
|
+
export type { PersonalisedTargeting } from './targeting/personalised';
|
|
20
|
+
export { getPersonalisedTargeting } from './targeting/personalised';
|
|
21
|
+
export type { SessionTargeting } from './targeting/session';
|
|
22
|
+
export { getSessionTargeting } from './targeting/session';
|
|
23
|
+
export type { SharedTargeting } from './targeting/shared';
|
|
24
|
+
export { getSharedTargeting } from './targeting/shared';
|
|
25
|
+
export type { ViewportTargeting } from './targeting/viewport';
|
|
26
|
+
export { getViewportTargeting } from './targeting/viewport';
|
|
27
|
+
export { pickTargetingValues } from './targeting/pick-targeting-values';
|
package/dist/esm/index.js
CHANGED
|
@@ -6,10 +6,16 @@ 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
8
|
export { EventTimer } from './EventTimer';
|
|
9
|
-
export {
|
|
9
|
+
export { bypassCommercialMetricsSampling, initCommercialMetrics, } from './sendCommercialMetrics';
|
|
10
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';
|
|
14
14
|
import * as constants_1 from './constants';
|
|
15
15
|
export { constants_1 as constants };
|
|
16
|
+
export { getContentTargeting } from './targeting/content';
|
|
17
|
+
export { getPersonalisedTargeting } from './targeting/personalised';
|
|
18
|
+
export { getSessionTargeting } from './targeting/session';
|
|
19
|
+
export { getSharedTargeting } from './targeting/shared';
|
|
20
|
+
export { getViewportTargeting } from './targeting/viewport';
|
|
21
|
+
export { pickTargetingValues } from './targeting/pick-targeting-values';
|
|
@@ -1 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
declare type Metric = {
|
|
2
|
+
name: string;
|
|
3
|
+
value: number;
|
|
4
|
+
};
|
|
5
|
+
declare type Property = {
|
|
6
|
+
name: string;
|
|
7
|
+
value: string;
|
|
8
|
+
};
|
|
9
|
+
declare type TimedEvent = {
|
|
10
|
+
name: string;
|
|
11
|
+
ts: number;
|
|
12
|
+
};
|
|
13
|
+
declare type EventProperties = {
|
|
14
|
+
type?: ConnectionType;
|
|
15
|
+
downlink?: number;
|
|
16
|
+
effectiveType?: string;
|
|
17
|
+
};
|
|
18
|
+
declare enum Endpoints {
|
|
19
|
+
CODE = "//performance-events.code.dev-guardianapis.com/commercial-metrics",
|
|
20
|
+
PROD = "//performance-events.guardianapis.com/commercial-metrics"
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A method to asynchronously send metrics after initialization.
|
|
24
|
+
*/
|
|
25
|
+
export declare function bypassCommercialMetricsSampling(): void;
|
|
26
|
+
/**
|
|
27
|
+
* A method to initialise metrics.
|
|
28
|
+
* @param init.pageViewId - identifies the page view. Usually available on `guardian.config.ophan.pageViewId`. Defaults to `null`
|
|
29
|
+
* @param init.browserId - identifies the browser. Usually available via `getCookie({ name: 'bwid' })`. Defaults to `null`
|
|
30
|
+
* @param init.isDev - used to determine whether to use CODE or PROD endpoints.
|
|
31
|
+
* @param init.adBlockerInUse - indicates whether or not ann adblocker is being used.
|
|
32
|
+
*/
|
|
33
|
+
export declare function initCommercialMetrics(pageViewId: string, browserId: string | undefined, isDev: boolean, adBlockerInUse?: boolean, sampling?: number): boolean;
|
|
34
|
+
export declare const _: {
|
|
35
|
+
Endpoints: typeof Endpoints;
|
|
36
|
+
setEndpoint: (isDev: boolean) => Endpoints;
|
|
37
|
+
filterUndefinedProperties: <T>(transformedProperties: [string, T | undefined][]) => [string, T][];
|
|
38
|
+
mapEventTimerPropertiesToString: (properties: Array<[string, string | number]>) => Property[];
|
|
39
|
+
roundTimeStamp: (events: TimedEvent[]) => Metric[];
|
|
40
|
+
transformToObjectEntries: (eventTimerProperties: EventProperties) => Array<[string, string | number | undefined]>;
|
|
41
|
+
reset: () => void;
|
|
42
|
+
};
|
|
43
|
+
export type { Property, TimedEvent, Metric };
|
|
@@ -1,40 +1,145 @@
|
|
|
1
1
|
import { log } from '@guardian/libs';
|
|
2
2
|
import { EventTimer } from './EventTimer';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
3
|
+
var Endpoints;
|
|
4
|
+
(function (Endpoints) {
|
|
5
|
+
Endpoints["CODE"] = "//performance-events.code.dev-guardianapis.com/commercial-metrics";
|
|
6
|
+
Endpoints["PROD"] = "//performance-events.guardianapis.com/commercial-metrics";
|
|
7
|
+
})(Endpoints || (Endpoints = {}));
|
|
8
|
+
let commercialMetricsPayload = {
|
|
9
|
+
page_view_id: undefined,
|
|
10
|
+
browser_id: undefined,
|
|
11
|
+
platform: 'NEXT_GEN',
|
|
12
|
+
metrics: [],
|
|
13
|
+
properties: [],
|
|
14
|
+
};
|
|
15
|
+
let devProperties = [];
|
|
16
|
+
let adBlockerProperties = [];
|
|
17
|
+
let initialised = false;
|
|
18
|
+
let endpoint;
|
|
19
|
+
const setEndpoint = (isDev) => (endpoint = isDev ? Endpoints.CODE : Endpoints.PROD);
|
|
20
|
+
const setDevProperties = (isDev) => (devProperties = isDev
|
|
21
|
+
? [{ name: 'isDev', value: window.location.hostname }]
|
|
22
|
+
: []);
|
|
23
|
+
const setAdBlockerProperties = (adBlockerInUse) => {
|
|
24
|
+
adBlockerProperties =
|
|
25
|
+
adBlockerInUse !== undefined
|
|
26
|
+
? [
|
|
27
|
+
{
|
|
28
|
+
name: 'adBlockerInUse',
|
|
29
|
+
value: adBlockerInUse.toString(),
|
|
30
|
+
},
|
|
31
|
+
]
|
|
32
|
+
: [];
|
|
33
|
+
};
|
|
34
|
+
const transformToObjectEntries = (eventTimerProperties) => {
|
|
35
|
+
// Transforms object {key: value} pairs into an array of [key, value] arrays
|
|
36
|
+
return Object.entries(eventTimerProperties);
|
|
37
|
+
};
|
|
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
|
+
const mapEventTimerPropertiesToString = (properties) => {
|
|
45
|
+
return properties.map(([name, value]) => ({
|
|
46
|
+
name: String(name),
|
|
47
|
+
value: String(value),
|
|
48
|
+
}));
|
|
49
|
+
};
|
|
50
|
+
const roundTimeStamp = (events) => {
|
|
51
|
+
return events.map(({ name, ts }) => ({
|
|
28
52
|
name,
|
|
29
53
|
value: Math.ceil(ts),
|
|
30
54
|
}));
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
55
|
+
};
|
|
56
|
+
function sendMetrics() {
|
|
57
|
+
log('commercial', 'About to send commercial metrics', commercialMetricsPayload);
|
|
58
|
+
return navigator.sendBeacon(endpoint, JSON.stringify(commercialMetricsPayload));
|
|
59
|
+
}
|
|
60
|
+
function gatherMetricsOnPageUnload() {
|
|
61
|
+
// Assemble commercial properties and metrics
|
|
62
|
+
const eventTimer = EventTimer.get();
|
|
63
|
+
const transformedEntries = transformToObjectEntries(eventTimer.properties);
|
|
64
|
+
const filteredEventTimerProperties = filterUndefinedProperties(transformedEntries);
|
|
65
|
+
const mappedEventTimerProperties = mapEventTimerPropertiesToString(filteredEventTimerProperties);
|
|
66
|
+
const properties = mappedEventTimerProperties
|
|
67
|
+
.concat(devProperties)
|
|
68
|
+
.concat(adBlockerProperties);
|
|
69
|
+
commercialMetricsPayload.properties = properties;
|
|
70
|
+
const metrics = roundTimeStamp(eventTimer.events);
|
|
71
|
+
commercialMetricsPayload.metrics = metrics;
|
|
72
|
+
sendMetrics();
|
|
73
|
+
}
|
|
74
|
+
const listener = (e) => {
|
|
75
|
+
switch (e.type) {
|
|
76
|
+
case 'visibilitychange':
|
|
77
|
+
if (document.visibilityState === 'hidden') {
|
|
78
|
+
gatherMetricsOnPageUnload();
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
case 'pagehide':
|
|
82
|
+
gatherMetricsOnPageUnload();
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const addVisibilityListeners = () => {
|
|
87
|
+
// Report all available metrics when the page is unloaded or in background.
|
|
88
|
+
window.addEventListener('visibilitychange', listener);
|
|
89
|
+
// Safari does not reliably fire the `visibilitychange` on page unload.
|
|
90
|
+
window.addEventListener('pagehide', listener);
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* A method to asynchronously send metrics after initialization.
|
|
94
|
+
*/
|
|
95
|
+
export function bypassCommercialMetricsSampling() {
|
|
96
|
+
if (!initialised) {
|
|
97
|
+
console.warn('initCommercialMetrics not yet initialised');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
addVisibilityListeners();
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* A method to initialise metrics.
|
|
104
|
+
* @param init.pageViewId - identifies the page view. Usually available on `guardian.config.ophan.pageViewId`. Defaults to `null`
|
|
105
|
+
* @param init.browserId - identifies the browser. Usually available via `getCookie({ name: 'bwid' })`. Defaults to `null`
|
|
106
|
+
* @param init.isDev - used to determine whether to use CODE or PROD endpoints.
|
|
107
|
+
* @param init.adBlockerInUse - indicates whether or not ann adblocker is being used.
|
|
108
|
+
*/
|
|
109
|
+
export function initCommercialMetrics(pageViewId, browserId, isDev, adBlockerInUse, sampling = 1 / 100) {
|
|
110
|
+
commercialMetricsPayload.page_view_id = pageViewId;
|
|
111
|
+
commercialMetricsPayload.browser_id = browserId;
|
|
112
|
+
setEndpoint(isDev);
|
|
113
|
+
setDevProperties(isDev);
|
|
114
|
+
setAdBlockerProperties(adBlockerInUse);
|
|
115
|
+
if (initialised) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
initialised = true;
|
|
119
|
+
const userIsInSamplingGroup = Math.random() <= sampling;
|
|
120
|
+
if (isDev || userIsInSamplingGroup) {
|
|
121
|
+
addVisibilityListeners();
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
40
125
|
}
|
|
126
|
+
export const _ = {
|
|
127
|
+
Endpoints,
|
|
128
|
+
setEndpoint,
|
|
129
|
+
filterUndefinedProperties,
|
|
130
|
+
mapEventTimerPropertiesToString,
|
|
131
|
+
roundTimeStamp,
|
|
132
|
+
transformToObjectEntries,
|
|
133
|
+
reset: () => {
|
|
134
|
+
initialised = false;
|
|
135
|
+
commercialMetricsPayload = {
|
|
136
|
+
page_view_id: undefined,
|
|
137
|
+
browser_id: undefined,
|
|
138
|
+
platform: 'NEXT_GEN',
|
|
139
|
+
metrics: [],
|
|
140
|
+
properties: [],
|
|
141
|
+
};
|
|
142
|
+
removeEventListener('visibilitychange', listener);
|
|
143
|
+
removeEventListener('pagehide', listener);
|
|
144
|
+
},
|
|
145
|
+
};
|
|
@@ -39,4 +39,9 @@ export declare type ViewportTargeting = {
|
|
|
39
39
|
*/
|
|
40
40
|
skinsize: 'l' | 's';
|
|
41
41
|
};
|
|
42
|
-
|
|
42
|
+
declare type Viewport = {
|
|
43
|
+
viewPortWidth: number;
|
|
44
|
+
cmpBannerWillShow: boolean;
|
|
45
|
+
};
|
|
46
|
+
export declare const getViewportTargeting: ({ viewPortWidth, cmpBannerWillShow, }: Viewport) => ViewportTargeting;
|
|
47
|
+
export {};
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
const findBreakpoint = (width) => {
|
|
3
3
|
if (width >= 980)
|
|
4
4
|
return 'desktop';
|
|
5
|
-
if (width >=
|
|
5
|
+
if (width >= 660)
|
|
6
6
|
return 'tablet';
|
|
7
7
|
return 'mobile';
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
export const getViewportTargeting = (viewPortWidth, cmpBannerWillShow) => {
|
|
9
|
+
export const getViewportTargeting = ({ viewPortWidth, cmpBannerWillShow, }) => {
|
|
11
10
|
// Don’t show inskin if if a privacy message will be shown
|
|
12
11
|
const inskin = cmpBannerWillShow ? 'f' : 't';
|
|
13
12
|
return {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { GetThirdPartyTag } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Allows creatives to show survey
|
|
4
|
+
* https://trello.com/c/wHffHVF1/171-integrate-and-test-inizio
|
|
5
|
+
* @param {} {shouldRun}
|
|
6
|
+
*/
|
|
2
7
|
export declare const inizio: GetThirdPartyTag;
|
|
3
8
|
export declare const _: {
|
|
4
9
|
onLoad: () => void;
|
|
@@ -18,6 +18,11 @@ const onLoad = () => {
|
|
|
18
18
|
},
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Allows creatives to show survey
|
|
23
|
+
* https://trello.com/c/wHffHVF1/171-integrate-and-test-inizio
|
|
24
|
+
* @param {} {shouldRun}
|
|
25
|
+
*/
|
|
21
26
|
export const inizio = ({ shouldRun }) => ({
|
|
22
27
|
shouldRun,
|
|
23
28
|
url: '//cdn.brandmetrics.com/survey/script/e96d04c832084488a841a06b49b8fb2d.js',
|
|
@@ -5,6 +5,11 @@ const onLoad = () => {
|
|
|
5
5
|
google_remarketing_only: true,
|
|
6
6
|
});
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Google conversion tracking
|
|
10
|
+
* https://support.google.com/google-ads/answer/6095821
|
|
11
|
+
* @param {} {shouldRun}
|
|
12
|
+
*/
|
|
8
13
|
export const remarketing = ({ shouldRun }) => ({
|
|
9
14
|
shouldRun,
|
|
10
15
|
url: '//www.googleadservices.com/pagead/conversion_async.js',
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import type { GetThirdPartyTag } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* tracking pixel
|
|
4
|
+
* https://business.twitter.com/en/help/campaign-measurement-and-analytics/conversion-tracking-for-websites.html
|
|
5
|
+
* @param {} {shouldRun}
|
|
6
|
+
*/
|
|
2
7
|
export declare const twitter: GetThirdPartyTag;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { twitterScript as insertSnippet } from '../__vendor/twitter-script';
|
|
2
|
+
/**
|
|
3
|
+
* tracking pixel
|
|
4
|
+
* https://business.twitter.com/en/help/campaign-measurement-and-analytics/conversion-tracking-for-websites.html
|
|
5
|
+
* @param {} {shouldRun}
|
|
6
|
+
*/
|
|
2
7
|
export const twitter = ({ shouldRun }) => ({
|
|
3
8
|
shouldRun,
|
|
4
9
|
name: 'twitter',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guardian/commercial-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Guardian advertising business logic",
|
|
5
5
|
"homepage": "https://github.com/guardian/commercial-core#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"precommit:lint": "lint-staged",
|
|
27
27
|
"prepush:test": "jest --verbose --runInBand --onlyChanged",
|
|
28
28
|
"test": "jest",
|
|
29
|
+
"test:watch": "jest --watch",
|
|
29
30
|
"test:ci": "jest --coverage --ci",
|
|
30
31
|
"tsc": "tsc --noEmit",
|
|
31
32
|
"validate": "npm-run-all tsc lint test build",
|
|
@@ -41,12 +42,12 @@
|
|
|
41
42
|
},
|
|
42
43
|
"prettier": "@guardian/prettier",
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"@commitlint/cli": "^
|
|
45
|
-
"@commitlint/config-conventional": "^
|
|
45
|
+
"@commitlint/cli": "^16.1.0",
|
|
46
|
+
"@commitlint/config-conventional": "^16.0.0",
|
|
46
47
|
"@guardian/ab-core": "^2.0.0",
|
|
47
48
|
"@guardian/consent-management-platform": "^10.1.0",
|
|
48
|
-
"@guardian/eslint-config-typescript": "^0.
|
|
49
|
-
"@guardian/libs": "3.
|
|
49
|
+
"@guardian/eslint-config-typescript": "^1.0.0",
|
|
50
|
+
"@guardian/libs": "3.6.1",
|
|
50
51
|
"@guardian/prettier": "^0.7.0",
|
|
51
52
|
"@octokit/core": "^3.5.1",
|
|
52
53
|
"@semantic-release/github": "^8.0.2",
|