@adobe/helix-rum-enhancer 2.17.1 → 2.19.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/CHANGELOG.md +14 -0
- package/modules/defaults.js +4 -1
- package/modules/fflags.js +1 -1
- package/modules/index.js +14 -95
- package/modules/martech.js +81 -0
- package/package.json +8 -8
- package/src/index.js +83 -91
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [2.19.0](https://github.com/adobe/helix-rum-enhancer/compare/v2.18.0...v2.19.0) (2024-08-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **onetrust:** enable on all domains ([6039f11](https://github.com/adobe/helix-rum-enhancer/commit/6039f1198f6484d623a3e42ffdd24807b6ed7c54))
|
|
7
|
+
|
|
8
|
+
# [2.18.0](https://github.com/adobe/helix-rum-enhancer/compare/v2.17.1...v2.18.0) (2024-08-08)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **loadresource:** include API calls in `loadresouce` requests for content request counting ([45449c2](https://github.com/adobe/helix-rum-enhancer/commit/45449c2e6a1602d80321f4ffa8698cbd116f1383))
|
|
14
|
+
|
|
1
15
|
## [2.17.1](https://github.com/adobe/helix-rum-enhancer/compare/v2.17.0...v2.17.1) (2024-08-02)
|
|
2
16
|
|
|
3
17
|
|
package/modules/defaults.js
CHANGED
|
@@ -9,5 +9,8 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
+
import { fflags } from './fflags.js';
|
|
13
|
+
|
|
12
14
|
export const KNOWN_PROPERTIES = ['weight', 'id', 'referer', 'checkpoint', 't', 'source', 'target', 'cwv', 'CLS', 'FID', 'LCP', 'INP', 'TTFB'];
|
|
13
|
-
export const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email'];
|
|
15
|
+
export const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email', 'consent'];
|
|
16
|
+
fflags.enabled('example', () => DEFAULT_TRACKING_EVENTS.push('example'));
|
package/modules/fflags.js
CHANGED
|
@@ -16,5 +16,5 @@ export const fflags = {
|
|
|
16
16
|
.reduce((a, b) => a + b, 1) % 1371) !== -1,
|
|
17
17
|
enabled: (flag, callback) => fflags.has(flag) && callback(),
|
|
18
18
|
disabled: (flag, callback) => !fflags.has(flag) && callback(),
|
|
19
|
-
|
|
19
|
+
example: [543, 770, 1136],
|
|
20
20
|
};
|
package/modules/index.js
CHANGED
|
@@ -12,9 +12,14 @@
|
|
|
12
12
|
/* eslint-env browser */
|
|
13
13
|
|
|
14
14
|
import { KNOWN_PROPERTIES, DEFAULT_TRACKING_EVENTS } from './defaults.js';
|
|
15
|
-
import { fflags } from './fflags.js';
|
|
16
15
|
import { urlSanitizers } from './utils.js';
|
|
17
16
|
import { targetSelector, sourceSelector } from './dom.js';
|
|
17
|
+
import {
|
|
18
|
+
addAdsParametersTracking,
|
|
19
|
+
addCookieConsentTracking,
|
|
20
|
+
addEmailParameterTracking,
|
|
21
|
+
addUTMParametersTracking,
|
|
22
|
+
} from './martech.js';
|
|
18
23
|
|
|
19
24
|
const { sampleRUM, queue, isSelected } = (window.hlx && window.hlx.rum) ? window.hlx.rum : {};
|
|
20
25
|
|
|
@@ -22,21 +27,9 @@ const formSubmitListener = (e) => sampleRUM('formsubmit', { target: targetSelect
|
|
|
22
27
|
// eslint-disable-next-line no-use-before-define
|
|
23
28
|
const mutationObserver = window.MutationObserver ? new MutationObserver(mutationsCallback) : null;
|
|
24
29
|
|
|
25
|
-
// eslint-disable-next-line no-unused-vars
|
|
26
|
-
function optedIn(checkpoint, data) {
|
|
27
|
-
// TODO: check config service to know if
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
// Gets configured collection from the config service for the current domain
|
|
31
|
-
function getCollectionConfig() {
|
|
32
|
-
// eslint-disable-next-line max-len
|
|
33
|
-
fflags.enabled('onetrust', () => DEFAULT_TRACKING_EVENTS.push('consent'));
|
|
34
|
-
return DEFAULT_TRACKING_EVENTS;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
30
|
function trackCheckpoint(checkpoint, data, t) {
|
|
38
31
|
const { weight, id } = window.hlx.rum;
|
|
39
|
-
if (
|
|
32
|
+
if (isSelected) {
|
|
40
33
|
const sendPing = (pdata = data) => {
|
|
41
34
|
// eslint-disable-next-line object-curly-newline, max-len
|
|
42
35
|
const body = JSON.stringify({ weight, id, referer: urlSanitizers[window.hlx.RUM_MASK_URL || 'path'](), checkpoint, t, ...data }, KNOWN_PROPERTIES);
|
|
@@ -146,7 +139,7 @@ function addLoadResourceTracking() {
|
|
|
146
139
|
list.getEntries()
|
|
147
140
|
.filter((entry) => !entry.responseStatus || entry.responseStatus < 400)
|
|
148
141
|
.filter((entry) => window.location.hostname === new URL(entry.name).hostname)
|
|
149
|
-
.filter((entry) => new URL(entry.name).pathname.match('.*(\\.plain\\.html$|\\.json|graphql)'))
|
|
142
|
+
.filter((entry) => new URL(entry.name).pathname.match('.*(\\.plain\\.html$|\\.json|graphql|api)'))
|
|
150
143
|
.forEach((entry) => {
|
|
151
144
|
sampleRUM('loadresource', { source: entry.name, target: Math.round(entry.duration) });
|
|
152
145
|
});
|
|
@@ -216,45 +209,6 @@ function addViewMediaTracking(parent) {
|
|
|
216
209
|
}
|
|
217
210
|
}
|
|
218
211
|
|
|
219
|
-
function addUTMParametersTracking() {
|
|
220
|
-
const usp = new URLSearchParams(window.location.search);
|
|
221
|
-
[...usp.entries()]
|
|
222
|
-
.filter(([key]) => key.startsWith('utm_'))
|
|
223
|
-
// exclude keys that may leak PII
|
|
224
|
-
.filter(([key]) => key !== 'utm_id')
|
|
225
|
-
.filter(([key]) => key !== 'utm_term')
|
|
226
|
-
.forEach(([source, target]) => sampleRUM('utm', { source, target }));
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function addAdsParametersTracking() {
|
|
230
|
-
const networks = {
|
|
231
|
-
google: /gclid|gclsrc|wbraid|gbraid/,
|
|
232
|
-
doubleclick: /dclid/,
|
|
233
|
-
microsoft: /msclkid/,
|
|
234
|
-
facebook: /fb(cl|ad_|pxl_)id/,
|
|
235
|
-
twitter: /tw(clid|src|term)/,
|
|
236
|
-
linkedin: /li_fat_id/,
|
|
237
|
-
pinterest: /epik/,
|
|
238
|
-
tiktok: /ttclid/,
|
|
239
|
-
};
|
|
240
|
-
const params = Array.from(new URLSearchParams(window.location.search).keys());
|
|
241
|
-
Object.entries(networks).forEach(([network, regex]) => {
|
|
242
|
-
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('paid', { source: network, target: param }));
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function addEmailParameterTracking() {
|
|
247
|
-
const networks = {
|
|
248
|
-
mailchimp: /mc_(c|e)id/,
|
|
249
|
-
marketo: /mkt_tok/,
|
|
250
|
-
|
|
251
|
-
};
|
|
252
|
-
const params = Array.from(new URLSearchParams(window.location.search).keys());
|
|
253
|
-
Object.entries(networks).forEach(([network, regex]) => {
|
|
254
|
-
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('email', { source: network, target: param }));
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
|
|
258
212
|
function addFormTracking(parent) {
|
|
259
213
|
activateBlocksMutationObserver();
|
|
260
214
|
parent.querySelectorAll('form').forEach((form) => {
|
|
@@ -263,42 +217,7 @@ function addFormTracking(parent) {
|
|
|
263
217
|
});
|
|
264
218
|
}
|
|
265
219
|
|
|
266
|
-
|
|
267
|
-
const cmpCookie = document.cookie.split(';')
|
|
268
|
-
.map((c) => c.trim())
|
|
269
|
-
.find((cookie) => cookie.startsWith('OptanonAlertBoxClosed='));
|
|
270
|
-
|
|
271
|
-
if (cmpCookie) {
|
|
272
|
-
sampleRUM('consent', { source: 'onetrust', target: 'hidden' });
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
let consentMutationObserver;
|
|
277
|
-
const trackShowConsent = () => {
|
|
278
|
-
if (document.querySelector('body > div#onetrust-consent-sdk')) {
|
|
279
|
-
sampleRUM('consent', { source: 'onetrust', target: 'show' });
|
|
280
|
-
if (consentMutationObserver) {
|
|
281
|
-
consentMutationObserver.disconnect();
|
|
282
|
-
}
|
|
283
|
-
return true;
|
|
284
|
-
}
|
|
285
|
-
return false;
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
if (!trackShowConsent()) {
|
|
289
|
-
// eslint-disable-next-line max-len
|
|
290
|
-
consentMutationObserver = window.MutationObserver ? new MutationObserver(trackShowConsent) : null;
|
|
291
|
-
if (consentMutationObserver) {
|
|
292
|
-
consentMutationObserver.observe(
|
|
293
|
-
document.body,
|
|
294
|
-
// eslint-disable-next-line object-curly-newline
|
|
295
|
-
{ attributes: false, childList: true, subtree: false },
|
|
296
|
-
);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const addObserver = (ck, fn, block) => getCollectionConfig().includes(ck) && fn(block);
|
|
220
|
+
const addObserver = (ck, fn, block) => DEFAULT_TRACKING_EVENTS.includes(ck) && fn(block);
|
|
302
221
|
function mutationsCallback(mutations) {
|
|
303
222
|
mutations.filter((m) => m.type === 'attributes' && m.attributeName === 'data-block-status')
|
|
304
223
|
.filter((m) => m.target.dataset.blockStatus === 'loaded')
|
|
@@ -320,15 +239,15 @@ function addTrackingFromConfig() {
|
|
|
320
239
|
form: () => addFormTracking(window.document.body),
|
|
321
240
|
enterleave: () => addEnterLeaveTracking(),
|
|
322
241
|
loadresource: () => addLoadResourceTracking(),
|
|
323
|
-
utm: () => addUTMParametersTracking(),
|
|
242
|
+
utm: () => addUTMParametersTracking(sampleRUM),
|
|
324
243
|
viewblock: () => addViewBlockTracking(window.document.body),
|
|
325
244
|
viewmedia: () => addViewMediaTracking(window.document.body),
|
|
326
|
-
consent: () => addCookieConsentTracking(),
|
|
327
|
-
paid: () => addAdsParametersTracking(),
|
|
328
|
-
email: () => addEmailParameterTracking(),
|
|
245
|
+
consent: () => addCookieConsentTracking(sampleRUM),
|
|
246
|
+
paid: () => addAdsParametersTracking(sampleRUM),
|
|
247
|
+
email: () => addEmailParameterTracking(sampleRUM),
|
|
329
248
|
};
|
|
330
249
|
|
|
331
|
-
|
|
250
|
+
DEFAULT_TRACKING_EVENTS.filter((ck) => trackingFunctions[ck])
|
|
332
251
|
.forEach((ck) => trackingFunctions[ck]());
|
|
333
252
|
}
|
|
334
253
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
export function addCookieConsentTracking(sampleRUM) {
|
|
13
|
+
const cmpCookie = document.cookie.split(';')
|
|
14
|
+
.map((c) => c.trim())
|
|
15
|
+
.find((cookie) => cookie.startsWith('OptanonAlertBoxClosed='));
|
|
16
|
+
|
|
17
|
+
if (cmpCookie) {
|
|
18
|
+
sampleRUM('consent', { source: 'onetrust', target: 'hidden' });
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let consentMutationObserver;
|
|
23
|
+
const trackShowConsent = () => {
|
|
24
|
+
if (document.querySelector('body > div#onetrust-consent-sdk')) {
|
|
25
|
+
sampleRUM('consent', { source: 'onetrust', target: 'show' });
|
|
26
|
+
if (consentMutationObserver) {
|
|
27
|
+
consentMutationObserver.disconnect();
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
if (!trackShowConsent()) {
|
|
35
|
+
// eslint-disable-next-line max-len
|
|
36
|
+
consentMutationObserver = window.MutationObserver ? new MutationObserver(trackShowConsent) : null;
|
|
37
|
+
if (consentMutationObserver) {
|
|
38
|
+
consentMutationObserver.observe(
|
|
39
|
+
document.body,
|
|
40
|
+
// eslint-disable-next-line object-curly-newline
|
|
41
|
+
{ attributes: false, childList: true, subtree: false },
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function addUTMParametersTracking(sampleRUM) {
|
|
48
|
+
const usp = new URLSearchParams(window.location.search);
|
|
49
|
+
[...usp.entries()]
|
|
50
|
+
.filter(([key]) => key.startsWith('utm_'))
|
|
51
|
+
// exclude keys that may leak PII
|
|
52
|
+
.filter(([key]) => key !== 'utm_id')
|
|
53
|
+
.filter(([key]) => key !== 'utm_term')
|
|
54
|
+
.forEach(([source, target]) => sampleRUM('utm', { source, target }));
|
|
55
|
+
}
|
|
56
|
+
export function addAdsParametersTracking(sampleRUM) {
|
|
57
|
+
const networks = {
|
|
58
|
+
google: /gclid|gclsrc|wbraid|gbraid/,
|
|
59
|
+
doubleclick: /dclid/,
|
|
60
|
+
microsoft: /msclkid/,
|
|
61
|
+
facebook: /fb(cl|ad_|pxl_)id/,
|
|
62
|
+
twitter: /tw(clid|src|term)/,
|
|
63
|
+
linkedin: /li_fat_id/,
|
|
64
|
+
pinterest: /epik/,
|
|
65
|
+
tiktok: /ttclid/,
|
|
66
|
+
};
|
|
67
|
+
const params = Array.from(new URLSearchParams(window.location.search).keys());
|
|
68
|
+
Object.entries(networks).forEach(([network, regex]) => {
|
|
69
|
+
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('paid', { source: network, target: param }));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export function addEmailParameterTracking(sampleRUM) {
|
|
73
|
+
const networks = {
|
|
74
|
+
mailchimp: /mc_(c|e)id/,
|
|
75
|
+
marketo: /mkt_tok/,
|
|
76
|
+
};
|
|
77
|
+
const params = Array.from(new URLSearchParams(window.location.search).keys());
|
|
78
|
+
Object.entries(networks).forEach(([network, regex]) => {
|
|
79
|
+
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('email', { source: network, target: param }));
|
|
80
|
+
});
|
|
81
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-rum-enhancer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.19.0",
|
|
4
4
|
"description": "Helix RUM Enhancer",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@semantic-release/changelog": "6.0.3",
|
|
40
40
|
"@semantic-release/git": "10.0.1",
|
|
41
41
|
"@semantic-release/npm": "12.0.1",
|
|
42
|
-
"@web/test-runner": "0.18.
|
|
42
|
+
"@web/test-runner": "0.18.3",
|
|
43
43
|
"@web/test-runner-commands": "0.9.0",
|
|
44
44
|
"@web/test-runner-mocha": "0.9.0",
|
|
45
45
|
"@web/test-runner-playwright": "0.11.0",
|
|
@@ -48,17 +48,17 @@
|
|
|
48
48
|
"eslint": "8.57.0",
|
|
49
49
|
"eslint-plugin-header": "3.1.1",
|
|
50
50
|
"eslint-plugin-import": "2.29.1",
|
|
51
|
-
"husky": "9.1.
|
|
51
|
+
"husky": "9.1.4",
|
|
52
52
|
"jsdoc-to-markdown": "8.0.3",
|
|
53
|
-
"junit-report-builder": "
|
|
54
|
-
"lint-staged": "15.2.
|
|
55
|
-
"mocha": "10.7.
|
|
53
|
+
"junit-report-builder": "5.0.0",
|
|
54
|
+
"lint-staged": "15.2.8",
|
|
55
|
+
"mocha": "10.7.3",
|
|
56
56
|
"mocha-multi-reporters": "1.5.1",
|
|
57
|
-
"rollup": "4.
|
|
57
|
+
"rollup": "4.20.0",
|
|
58
58
|
"rollup-plugin-cleanup": "3.2.1",
|
|
59
59
|
"rollup-plugin-eslint-bundle": "9.0.0",
|
|
60
60
|
"semantic-release": "24.0.0",
|
|
61
|
-
"web-vitals": "4.2.
|
|
61
|
+
"web-vitals": "4.2.3"
|
|
62
62
|
},
|
|
63
63
|
"lint-staged": {
|
|
64
64
|
"*.js": "eslint",
|
package/src/index.js
CHANGED
|
@@ -15,9 +15,6 @@
|
|
|
15
15
|
(function () {
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const KNOWN_PROPERTIES = ['weight', 'id', 'referer', 'checkpoint', 't', 'source', 'target', 'cwv', 'CLS', 'FID', 'LCP', 'INP', 'TTFB'];
|
|
19
|
-
const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email'];
|
|
20
|
-
|
|
21
18
|
const fflags = {
|
|
22
19
|
has: (flag) => !!window.origin.match(/localhost/)
|
|
23
20
|
|| fflags[flag].indexOf(Array.from(window.origin)
|
|
@@ -25,9 +22,13 @@
|
|
|
25
22
|
.reduce((a, b) => a + b, 1) % 1371) !== -1,
|
|
26
23
|
enabled: (flag, callback) => fflags.has(flag) && callback(),
|
|
27
24
|
disabled: (flag, callback) => !fflags.has(flag) && callback(),
|
|
28
|
-
|
|
25
|
+
example: [543, 770, 1136],
|
|
29
26
|
};
|
|
30
27
|
|
|
28
|
+
const KNOWN_PROPERTIES = ['weight', 'id', 'referer', 'checkpoint', 't', 'source', 'target', 'cwv', 'CLS', 'FID', 'LCP', 'INP', 'TTFB'];
|
|
29
|
+
const DEFAULT_TRACKING_EVENTS = ['click', 'cwv', 'form', 'enterleave', 'viewblock', 'viewmedia', 'loadresource', 'utm', 'paid', 'email', 'consent'];
|
|
30
|
+
fflags.enabled('example', () => DEFAULT_TRACKING_EVENTS.push('example'));
|
|
31
|
+
|
|
31
32
|
const urlSanitizers = {
|
|
32
33
|
/**
|
|
33
34
|
* Returns the full url.
|
|
@@ -123,17 +124,82 @@
|
|
|
123
124
|
}
|
|
124
125
|
};
|
|
125
126
|
|
|
127
|
+
function addCookieConsentTracking(sampleRUM) {
|
|
128
|
+
const cmpCookie = document.cookie.split(';')
|
|
129
|
+
.map((c) => c.trim())
|
|
130
|
+
.find((cookie) => cookie.startsWith('OptanonAlertBoxClosed='));
|
|
131
|
+
|
|
132
|
+
if (cmpCookie) {
|
|
133
|
+
sampleRUM('consent', { source: 'onetrust', target: 'hidden' });
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let consentMutationObserver;
|
|
138
|
+
const trackShowConsent = () => {
|
|
139
|
+
if (document.querySelector('body > div#onetrust-consent-sdk')) {
|
|
140
|
+
sampleRUM('consent', { source: 'onetrust', target: 'show' });
|
|
141
|
+
if (consentMutationObserver) {
|
|
142
|
+
consentMutationObserver.disconnect();
|
|
143
|
+
}
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
return false;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
if (!trackShowConsent()) {
|
|
150
|
+
// eslint-disable-next-line max-len
|
|
151
|
+
consentMutationObserver = window.MutationObserver ? new MutationObserver(trackShowConsent) : null;
|
|
152
|
+
if (consentMutationObserver) {
|
|
153
|
+
consentMutationObserver.observe(
|
|
154
|
+
document.body,
|
|
155
|
+
// eslint-disable-next-line object-curly-newline
|
|
156
|
+
{ attributes: false, childList: true, subtree: false },
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function addUTMParametersTracking(sampleRUM) {
|
|
163
|
+
const usp = new URLSearchParams(window.location.search);
|
|
164
|
+
[...usp.entries()]
|
|
165
|
+
.filter(([key]) => key.startsWith('utm_'))
|
|
166
|
+
// exclude keys that may leak PII
|
|
167
|
+
.filter(([key]) => key !== 'utm_id')
|
|
168
|
+
.filter(([key]) => key !== 'utm_term')
|
|
169
|
+
.forEach(([source, target]) => sampleRUM('utm', { source, target }));
|
|
170
|
+
}
|
|
171
|
+
function addAdsParametersTracking(sampleRUM) {
|
|
172
|
+
const networks = {
|
|
173
|
+
google: /gclid|gclsrc|wbraid|gbraid/,
|
|
174
|
+
doubleclick: /dclid/,
|
|
175
|
+
microsoft: /msclkid/,
|
|
176
|
+
facebook: /fb(cl|ad_|pxl_)id/,
|
|
177
|
+
twitter: /tw(clid|src|term)/,
|
|
178
|
+
linkedin: /li_fat_id/,
|
|
179
|
+
pinterest: /epik/,
|
|
180
|
+
tiktok: /ttclid/,
|
|
181
|
+
};
|
|
182
|
+
const params = Array.from(new URLSearchParams(window.location.search).keys());
|
|
183
|
+
Object.entries(networks).forEach(([network, regex]) => {
|
|
184
|
+
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('paid', { source: network, target: param }));
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
function addEmailParameterTracking(sampleRUM) {
|
|
188
|
+
const networks = {
|
|
189
|
+
mailchimp: /mc_(c|e)id/,
|
|
190
|
+
marketo: /mkt_tok/,
|
|
191
|
+
};
|
|
192
|
+
const params = Array.from(new URLSearchParams(window.location.search).keys());
|
|
193
|
+
Object.entries(networks).forEach(([network, regex]) => {
|
|
194
|
+
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('email', { source: network, target: param }));
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
126
198
|
const { sampleRUM, queue, isSelected } = (window.hlx && window.hlx.rum) ? window.hlx.rum : {};
|
|
127
199
|
|
|
128
200
|
const formSubmitListener = (e) => sampleRUM('formsubmit', { target: targetSelector(e.target), source: sourceSelector(e.target) });
|
|
129
201
|
// eslint-disable-next-line no-use-before-define
|
|
130
202
|
const mutationObserver = window.MutationObserver ? new MutationObserver(mutationsCallback) : null;
|
|
131
|
-
// Gets configured collection from the config service for the current domain
|
|
132
|
-
function getCollectionConfig() {
|
|
133
|
-
// eslint-disable-next-line max-len
|
|
134
|
-
fflags.enabled('onetrust', () => DEFAULT_TRACKING_EVENTS.push('consent'));
|
|
135
|
-
return DEFAULT_TRACKING_EVENTS;
|
|
136
|
-
}
|
|
137
203
|
|
|
138
204
|
function trackCheckpoint(checkpoint, data, t) {
|
|
139
205
|
const { weight, id } = window.hlx.rum;
|
|
@@ -245,7 +311,7 @@
|
|
|
245
311
|
list.getEntries()
|
|
246
312
|
.filter((entry) => !entry.responseStatus || entry.responseStatus < 400)
|
|
247
313
|
.filter((entry) => window.location.hostname === new URL(entry.name).hostname)
|
|
248
|
-
.filter((entry) => new URL(entry.name).pathname.match('.*(\\.plain\\.html$|\\.json|graphql)'))
|
|
314
|
+
.filter((entry) => new URL(entry.name).pathname.match('.*(\\.plain\\.html$|\\.json|graphql|api)'))
|
|
249
315
|
.forEach((entry) => {
|
|
250
316
|
sampleRUM('loadresource', { source: entry.name, target: Math.round(entry.duration) });
|
|
251
317
|
});
|
|
@@ -313,45 +379,6 @@
|
|
|
313
379
|
}
|
|
314
380
|
}
|
|
315
381
|
|
|
316
|
-
function addUTMParametersTracking() {
|
|
317
|
-
const usp = new URLSearchParams(window.location.search);
|
|
318
|
-
[...usp.entries()]
|
|
319
|
-
.filter(([key]) => key.startsWith('utm_'))
|
|
320
|
-
// exclude keys that may leak PII
|
|
321
|
-
.filter(([key]) => key !== 'utm_id')
|
|
322
|
-
.filter(([key]) => key !== 'utm_term')
|
|
323
|
-
.forEach(([source, target]) => sampleRUM('utm', { source, target }));
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function addAdsParametersTracking() {
|
|
327
|
-
const networks = {
|
|
328
|
-
google: /gclid|gclsrc|wbraid|gbraid/,
|
|
329
|
-
doubleclick: /dclid/,
|
|
330
|
-
microsoft: /msclkid/,
|
|
331
|
-
facebook: /fb(cl|ad_|pxl_)id/,
|
|
332
|
-
twitter: /tw(clid|src|term)/,
|
|
333
|
-
linkedin: /li_fat_id/,
|
|
334
|
-
pinterest: /epik/,
|
|
335
|
-
tiktok: /ttclid/,
|
|
336
|
-
};
|
|
337
|
-
const params = Array.from(new URLSearchParams(window.location.search).keys());
|
|
338
|
-
Object.entries(networks).forEach(([network, regex]) => {
|
|
339
|
-
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('paid', { source: network, target: param }));
|
|
340
|
-
});
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
function addEmailParameterTracking() {
|
|
344
|
-
const networks = {
|
|
345
|
-
mailchimp: /mc_(c|e)id/,
|
|
346
|
-
marketo: /mkt_tok/,
|
|
347
|
-
|
|
348
|
-
};
|
|
349
|
-
const params = Array.from(new URLSearchParams(window.location.search).keys());
|
|
350
|
-
Object.entries(networks).forEach(([network, regex]) => {
|
|
351
|
-
params.filter((param) => regex.test(param)).forEach((param) => sampleRUM('email', { source: network, target: param }));
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
|
|
355
382
|
function addFormTracking(parent) {
|
|
356
383
|
activateBlocksMutationObserver();
|
|
357
384
|
parent.querySelectorAll('form').forEach((form) => {
|
|
@@ -360,42 +387,7 @@
|
|
|
360
387
|
});
|
|
361
388
|
}
|
|
362
389
|
|
|
363
|
-
|
|
364
|
-
const cmpCookie = document.cookie.split(';')
|
|
365
|
-
.map((c) => c.trim())
|
|
366
|
-
.find((cookie) => cookie.startsWith('OptanonAlertBoxClosed='));
|
|
367
|
-
|
|
368
|
-
if (cmpCookie) {
|
|
369
|
-
sampleRUM('consent', { source: 'onetrust', target: 'hidden' });
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
let consentMutationObserver;
|
|
374
|
-
const trackShowConsent = () => {
|
|
375
|
-
if (document.querySelector('body > div#onetrust-consent-sdk')) {
|
|
376
|
-
sampleRUM('consent', { source: 'onetrust', target: 'show' });
|
|
377
|
-
if (consentMutationObserver) {
|
|
378
|
-
consentMutationObserver.disconnect();
|
|
379
|
-
}
|
|
380
|
-
return true;
|
|
381
|
-
}
|
|
382
|
-
return false;
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
if (!trackShowConsent()) {
|
|
386
|
-
// eslint-disable-next-line max-len
|
|
387
|
-
consentMutationObserver = window.MutationObserver ? new MutationObserver(trackShowConsent) : null;
|
|
388
|
-
if (consentMutationObserver) {
|
|
389
|
-
consentMutationObserver.observe(
|
|
390
|
-
document.body,
|
|
391
|
-
// eslint-disable-next-line object-curly-newline
|
|
392
|
-
{ attributes: false, childList: true, subtree: false },
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
const addObserver = (ck, fn, block) => getCollectionConfig().includes(ck) && fn(block);
|
|
390
|
+
const addObserver = (ck, fn, block) => DEFAULT_TRACKING_EVENTS.includes(ck) && fn(block);
|
|
399
391
|
function mutationsCallback(mutations) {
|
|
400
392
|
mutations.filter((m) => m.type === 'attributes' && m.attributeName === 'data-block-status')
|
|
401
393
|
.filter((m) => m.target.dataset.blockStatus === 'loaded')
|
|
@@ -417,15 +409,15 @@
|
|
|
417
409
|
form: () => addFormTracking(window.document.body),
|
|
418
410
|
enterleave: () => addEnterLeaveTracking(),
|
|
419
411
|
loadresource: () => addLoadResourceTracking(),
|
|
420
|
-
utm: () => addUTMParametersTracking(),
|
|
412
|
+
utm: () => addUTMParametersTracking(sampleRUM),
|
|
421
413
|
viewblock: () => addViewBlockTracking(window.document.body),
|
|
422
414
|
viewmedia: () => addViewMediaTracking(window.document.body),
|
|
423
|
-
consent: () => addCookieConsentTracking(),
|
|
424
|
-
paid: () => addAdsParametersTracking(),
|
|
425
|
-
email: () => addEmailParameterTracking(),
|
|
415
|
+
consent: () => addCookieConsentTracking(sampleRUM),
|
|
416
|
+
paid: () => addAdsParametersTracking(sampleRUM),
|
|
417
|
+
email: () => addEmailParameterTracking(sampleRUM),
|
|
426
418
|
};
|
|
427
419
|
|
|
428
|
-
|
|
420
|
+
DEFAULT_TRACKING_EVENTS.filter((ck) => trackingFunctions[ck])
|
|
429
421
|
.forEach((ck) => trackingFunctions[ck]());
|
|
430
422
|
}
|
|
431
423
|
|