@guardian/commercial-core 3.0.0 → 3.2.1
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 +9 -1
- package/dist/cjs/EventTimer.js +6 -0
- package/dist/cjs/ad-sizes.d.ts +1 -1
- package/dist/cjs/ad-sizes.js +0 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/track-scroll-depth.d.ts +8 -0
- package/dist/cjs/track-scroll-depth.js +41 -0
- package/dist/esm/EventTimer.d.ts +9 -1
- package/dist/esm/EventTimer.js +6 -0
- package/dist/esm/ad-sizes.d.ts +1 -1
- package/dist/esm/ad-sizes.js +0 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/track-scroll-depth.d.ts +8 -0
- package/dist/esm/track-scroll-depth.js +38 -0
- package/package.json +1 -1
package/dist/cjs/EventTimer.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ interface EventTimerProperties {
|
|
|
29
29
|
effectiveType?: string;
|
|
30
30
|
adSlotsInline?: number;
|
|
31
31
|
adSlotsTotal?: number;
|
|
32
|
+
pageHeightVH?: number;
|
|
33
|
+
lazyLoadMarginPercent?: number;
|
|
32
34
|
}
|
|
33
35
|
export declare class EventTimer {
|
|
34
36
|
private _events;
|
|
@@ -63,7 +65,13 @@ export declare class EventTimer {
|
|
|
63
65
|
*/
|
|
64
66
|
get events(): Event[];
|
|
65
67
|
private constructor();
|
|
66
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Adds an event timer property
|
|
70
|
+
*
|
|
71
|
+
* @param {string} name - the property's name
|
|
72
|
+
* @param {value} number - the property's value
|
|
73
|
+
*/
|
|
74
|
+
setProperty(name: 'adSlotsInline' | 'adSlotsTotal' | 'pageHeightVH' | 'lazyLoadMarginPercent', value: number): void;
|
|
67
75
|
/**
|
|
68
76
|
* Creates a new performance mark
|
|
69
77
|
* For slot events also ensures each TYPE of event event is marked only once for 'first'
|
package/dist/cjs/EventTimer.js
CHANGED
|
@@ -108,6 +108,12 @@ class EventTimer {
|
|
|
108
108
|
]
|
|
109
109
|
: this._events;
|
|
110
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Adds an event timer property
|
|
113
|
+
*
|
|
114
|
+
* @param {string} name - the property's name
|
|
115
|
+
* @param {value} number - the property's value
|
|
116
|
+
*/
|
|
111
117
|
setProperty(name, value) {
|
|
112
118
|
this.properties[name] = value;
|
|
113
119
|
}
|
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 = '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'
|
|
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';
|
|
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
package/dist/cjs/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { adSizes, getAdSize } from './ad-sizes';
|
|
|
11
11
|
export type { SizeKeys, AdSizeString, AdSize } from './ad-sizes';
|
|
12
12
|
export { isAdBlockInUse } from './detectAdBlocker';
|
|
13
13
|
export { clearPermutiveSegments, getPermutiveSegments, getPermutivePFPSegments, } from './permutive';
|
|
14
|
+
export { initTrackScrollDepth } from './track-scroll-depth';
|
|
14
15
|
export { buildAdsConfigWithConsent, disabledAds } from './ad-targeting-youtube';
|
|
15
16
|
export type { AdsConfig, AdsConfigBasic, AdsConfigDisabled, AdTargetingBuilder, CustomParams, } from './types';
|
|
16
17
|
export * as constants from './constants';
|
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.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;
|
|
23
|
+
exports.pickTargetingValues = exports.getViewportTargeting = exports.getSharedTargeting = exports.getSessionTargeting = exports.getPersonalisedTargeting = exports.getContentTargeting = exports.constants = exports.disabledAds = exports.buildAdsConfigWithConsent = exports.initTrackScrollDepth = 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");
|
|
@@ -47,6 +47,8 @@ var permutive_2 = require("./permutive");
|
|
|
47
47
|
Object.defineProperty(exports, "clearPermutiveSegments", { enumerable: true, get: function () { return permutive_2.clearPermutiveSegments; } });
|
|
48
48
|
Object.defineProperty(exports, "getPermutiveSegments", { enumerable: true, get: function () { return permutive_2.getPermutiveSegments; } });
|
|
49
49
|
Object.defineProperty(exports, "getPermutivePFPSegments", { enumerable: true, get: function () { return permutive_2.getPermutivePFPSegments; } });
|
|
50
|
+
var track_scroll_depth_1 = require("./track-scroll-depth");
|
|
51
|
+
Object.defineProperty(exports, "initTrackScrollDepth", { enumerable: true, get: function () { return track_scroll_depth_1.initTrackScrollDepth; } });
|
|
50
52
|
var ad_targeting_youtube_1 = require("./ad-targeting-youtube");
|
|
51
53
|
Object.defineProperty(exports, "buildAdsConfigWithConsent", { enumerable: true, get: function () { return ad_targeting_youtube_1.buildAdsConfigWithConsent; } });
|
|
52
54
|
Object.defineProperty(exports, "disabledAds", { enumerable: true, get: function () { return ad_targeting_youtube_1.disabledAds; } });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collect commercial metrics on scroll depth
|
|
3
|
+
* Insert hidden elements at intervals of 1 viewport height
|
|
4
|
+
* then use an intersection observer to mark the time when the viewport intersects with these elements.
|
|
5
|
+
* Approach inspired by https://gist.github.com/bgreater/2412517f5a3f9c6fc4cafeb1ca71384f
|
|
6
|
+
*/
|
|
7
|
+
declare const initTrackScrollDepth: () => void;
|
|
8
|
+
export { initTrackScrollDepth };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initTrackScrollDepth = void 0;
|
|
4
|
+
const libs_1 = require("@guardian/libs");
|
|
5
|
+
const EventTimer_1 = require("./EventTimer");
|
|
6
|
+
/**
|
|
7
|
+
* Collect commercial metrics on scroll depth
|
|
8
|
+
* Insert hidden elements at intervals of 1 viewport height
|
|
9
|
+
* then use an intersection observer to mark the time when the viewport intersects with these elements.
|
|
10
|
+
* Approach inspired by https://gist.github.com/bgreater/2412517f5a3f9c6fc4cafeb1ca71384f
|
|
11
|
+
*/
|
|
12
|
+
const initTrackScrollDepth = () => {
|
|
13
|
+
const pageHeight = document.body.offsetHeight;
|
|
14
|
+
const intViewportHeight = window.innerHeight;
|
|
15
|
+
// how many viewports tall is the page?
|
|
16
|
+
const pageHeightVH = Math.floor(pageHeight / intViewportHeight);
|
|
17
|
+
const eventTimer = EventTimer_1.EventTimer.get();
|
|
18
|
+
eventTimer.setProperty('pageHeightVH', pageHeightVH);
|
|
19
|
+
const observer = new IntersectionObserver(
|
|
20
|
+
/* istanbul ignore next */
|
|
21
|
+
(entries) => {
|
|
22
|
+
entries.forEach((entry) => {
|
|
23
|
+
if (entry.isIntersecting) {
|
|
24
|
+
const currentDepthVH = String(entry.target.getAttribute('data-depth'));
|
|
25
|
+
(0, libs_1.log)('commercial', `current scroll depth ${currentDepthVH}`);
|
|
26
|
+
eventTimer.trigger(`scroll-depth-vh-${currentDepthVH}`);
|
|
27
|
+
observer.unobserve(entry.target);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
for (let depth = 1; depth <= pageHeightVH; depth++) {
|
|
32
|
+
const div = document.createElement('div');
|
|
33
|
+
div.dataset.depth = String(depth);
|
|
34
|
+
div.style.top = String(100 * depth) + '%';
|
|
35
|
+
div.style.position = 'absolute';
|
|
36
|
+
div.className = 'scroll-depth-marker';
|
|
37
|
+
document.body.appendChild(div);
|
|
38
|
+
observer.observe(div);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.initTrackScrollDepth = initTrackScrollDepth;
|
package/dist/esm/EventTimer.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ interface EventTimerProperties {
|
|
|
29
29
|
effectiveType?: string;
|
|
30
30
|
adSlotsInline?: number;
|
|
31
31
|
adSlotsTotal?: number;
|
|
32
|
+
pageHeightVH?: number;
|
|
33
|
+
lazyLoadMarginPercent?: number;
|
|
32
34
|
}
|
|
33
35
|
export declare class EventTimer {
|
|
34
36
|
private _events;
|
|
@@ -63,7 +65,13 @@ export declare class EventTimer {
|
|
|
63
65
|
*/
|
|
64
66
|
get events(): Event[];
|
|
65
67
|
private constructor();
|
|
66
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Adds an event timer property
|
|
70
|
+
*
|
|
71
|
+
* @param {string} name - the property's name
|
|
72
|
+
* @param {value} number - the property's value
|
|
73
|
+
*/
|
|
74
|
+
setProperty(name: 'adSlotsInline' | 'adSlotsTotal' | 'pageHeightVH' | 'lazyLoadMarginPercent', value: number): void;
|
|
67
75
|
/**
|
|
68
76
|
* Creates a new performance mark
|
|
69
77
|
* For slot events also ensures each TYPE of event event is marked only once for 'first'
|
package/dist/esm/EventTimer.js
CHANGED
|
@@ -105,6 +105,12 @@ export class EventTimer {
|
|
|
105
105
|
]
|
|
106
106
|
: this._events;
|
|
107
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Adds an event timer property
|
|
110
|
+
*
|
|
111
|
+
* @param {string} name - the property's name
|
|
112
|
+
* @param {value} number - the property's value
|
|
113
|
+
*/
|
|
108
114
|
setProperty(name, value) {
|
|
109
115
|
this.properties[name] = value;
|
|
110
116
|
}
|
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 = '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'
|
|
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';
|
|
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
package/dist/esm/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { adSizes, getAdSize } from './ad-sizes';
|
|
|
11
11
|
export type { SizeKeys, AdSizeString, AdSize } from './ad-sizes';
|
|
12
12
|
export { isAdBlockInUse } from './detectAdBlocker';
|
|
13
13
|
export { clearPermutiveSegments, getPermutiveSegments, getPermutivePFPSegments, } from './permutive';
|
|
14
|
+
export { initTrackScrollDepth } from './track-scroll-depth';
|
|
14
15
|
export { buildAdsConfigWithConsent, disabledAds } from './ad-targeting-youtube';
|
|
15
16
|
export type { AdsConfig, AdsConfigBasic, AdsConfigDisabled, AdTargetingBuilder, CustomParams, } from './types';
|
|
16
17
|
export * as constants from './constants';
|
package/dist/esm/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { bypassCommercialMetricsSampling, initCommercialMetrics, } from './sendC
|
|
|
10
10
|
export { adSizes, getAdSize } from './ad-sizes';
|
|
11
11
|
export { isAdBlockInUse } from './detectAdBlocker';
|
|
12
12
|
export { clearPermutiveSegments, getPermutiveSegments, getPermutivePFPSegments, } from './permutive';
|
|
13
|
+
export { initTrackScrollDepth } from './track-scroll-depth';
|
|
13
14
|
export { buildAdsConfigWithConsent, disabledAds } from './ad-targeting-youtube';
|
|
14
15
|
import * as constants_1 from './constants';
|
|
15
16
|
export { constants_1 as constants };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collect commercial metrics on scroll depth
|
|
3
|
+
* Insert hidden elements at intervals of 1 viewport height
|
|
4
|
+
* then use an intersection observer to mark the time when the viewport intersects with these elements.
|
|
5
|
+
* Approach inspired by https://gist.github.com/bgreater/2412517f5a3f9c6fc4cafeb1ca71384f
|
|
6
|
+
*/
|
|
7
|
+
declare const initTrackScrollDepth: () => void;
|
|
8
|
+
export { initTrackScrollDepth };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { log } from '@guardian/libs';
|
|
2
|
+
import { EventTimer } from './EventTimer';
|
|
3
|
+
/**
|
|
4
|
+
* Collect commercial metrics on scroll depth
|
|
5
|
+
* Insert hidden elements at intervals of 1 viewport height
|
|
6
|
+
* then use an intersection observer to mark the time when the viewport intersects with these elements.
|
|
7
|
+
* Approach inspired by https://gist.github.com/bgreater/2412517f5a3f9c6fc4cafeb1ca71384f
|
|
8
|
+
*/
|
|
9
|
+
const initTrackScrollDepth = () => {
|
|
10
|
+
const pageHeight = document.body.offsetHeight;
|
|
11
|
+
const intViewportHeight = window.innerHeight;
|
|
12
|
+
// how many viewports tall is the page?
|
|
13
|
+
const pageHeightVH = Math.floor(pageHeight / intViewportHeight);
|
|
14
|
+
const eventTimer = EventTimer.get();
|
|
15
|
+
eventTimer.setProperty('pageHeightVH', pageHeightVH);
|
|
16
|
+
const observer = new IntersectionObserver(
|
|
17
|
+
/* istanbul ignore next */
|
|
18
|
+
(entries) => {
|
|
19
|
+
entries.forEach((entry) => {
|
|
20
|
+
if (entry.isIntersecting) {
|
|
21
|
+
const currentDepthVH = String(entry.target.getAttribute('data-depth'));
|
|
22
|
+
log('commercial', `current scroll depth ${currentDepthVH}`);
|
|
23
|
+
eventTimer.trigger(`scroll-depth-vh-${currentDepthVH}`);
|
|
24
|
+
observer.unobserve(entry.target);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
for (let depth = 1; depth <= pageHeightVH; depth++) {
|
|
29
|
+
const div = document.createElement('div');
|
|
30
|
+
div.dataset.depth = String(depth);
|
|
31
|
+
div.style.top = String(100 * depth) + '%';
|
|
32
|
+
div.style.position = 'absolute';
|
|
33
|
+
div.className = 'scroll-depth-marker';
|
|
34
|
+
document.body.appendChild(div);
|
|
35
|
+
observer.observe(div);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export { initTrackScrollDepth };
|