@adobe/spacecat-shared-rum-api-client 2.7.4 → 2.9.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/README.md +86 -0
- package/package.json +2 -2
- package/src/common/aggregateFns.js +54 -0
- package/src/functions/opportunities/high-inorganic-high-bounce-rate.js +74 -0
- package/src/functions/opportunities/high-organic-low-ctr.js +77 -0
- package/src/functions/opportunities/rageclick.js +222 -0
- package/src/functions/traffic-acquisition.js +11 -3
- package/src/index.d.ts +1 -1
- package/src/index.js +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-rum-api-client-v2.9.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.8.0...@adobe/spacecat-shared-rum-api-client-v2.9.0) (2024-09-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* experimentation opportunities ([#351](https://github.com/adobe/spacecat-shared/issues/351)) ([f21a765](https://github.com/adobe/spacecat-shared/commit/f21a765996990b1748c11b0cd8089e87ec91d9ad))
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-rum-api-client-v2.8.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.7.4...@adobe/spacecat-shared-rum-api-client-v2.8.0) (2024-08-26)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* [oppty] Pages with high click amount on non-interacting element ([#329](https://github.com/adobe/spacecat-shared/issues/329)) ([610a22f](https://github.com/adobe/spacecat-shared/commit/610a22f59c1f197afb5ee4b1b9244a7f73fbce40))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-rum-api-client-v2.7.4](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.7.3...@adobe/spacecat-shared-rum-api-client-v2.7.4) (2024-08-24)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -191,6 +191,92 @@ An example response:
|
|
|
191
191
|
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
+
### high-inorganic-high-bounce-rate (Experimentation Opportunity)
|
|
195
|
+
|
|
196
|
+
Calculates the amount of inorganic traffic and the bounce rate for each page. Identifies pages with both high inorganic traffic and high bounce rates, which can be targeted for future experimentation opportunities. An example payload is provided below:
|
|
197
|
+
|
|
198
|
+
```json
|
|
199
|
+
[
|
|
200
|
+
{
|
|
201
|
+
"type": "high-inorganic-high-bounce-rate",
|
|
202
|
+
"page": "https://www.spacecat.com/",
|
|
203
|
+
"screenshot": "",
|
|
204
|
+
"trackedPageKPIName": "Bounce Rate",
|
|
205
|
+
"trackedPageKPIValue": 0.6507592190889371,
|
|
206
|
+
"pageViews": 46100,
|
|
207
|
+
"samples": 46100,
|
|
208
|
+
"metrics": [
|
|
209
|
+
{
|
|
210
|
+
"type": "traffic",
|
|
211
|
+
"value": {
|
|
212
|
+
"total": 46100,
|
|
213
|
+
"paid": 40700,
|
|
214
|
+
"owned": 5400,
|
|
215
|
+
"earned": 0
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"type": "high-inorganic-high-bounce-rate",
|
|
222
|
+
"page": "https://www.spacecat.com/pricing",
|
|
223
|
+
"screenshot": "",
|
|
224
|
+
"trackedPageKPIName": "Bounce Rate",
|
|
225
|
+
"trackedPageKPIValue": 0.8723897911832946,
|
|
226
|
+
"pageViews": 43100,
|
|
227
|
+
"samples": 43100,
|
|
228
|
+
"metrics": [
|
|
229
|
+
{
|
|
230
|
+
"type": "traffic",
|
|
231
|
+
"value": {
|
|
232
|
+
"total": 43100,
|
|
233
|
+
"paid": 24100,
|
|
234
|
+
"owned": 19000,
|
|
235
|
+
"earned": 0
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
]
|
|
239
|
+
}
|
|
240
|
+
]
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### high-organic-low-ctr (Experimentation Opportunity)
|
|
244
|
+
|
|
245
|
+
Calculates the amount of non-inorganic (earned and owned) traffic and the click-through rate for each page. Identifies pages with high non-inorganic traffic and low click-through rates, which can be targeted for future experimentation opportunities. An example payload is provided below:
|
|
246
|
+
|
|
247
|
+
```json
|
|
248
|
+
[
|
|
249
|
+
{
|
|
250
|
+
"type": "high-organic-low-ctr",
|
|
251
|
+
"page": "https://www.spacecat.com/about-us",
|
|
252
|
+
"screenshot": "",
|
|
253
|
+
"trackedPageKPIName": "Click Through Rate",
|
|
254
|
+
"trackedPageKPIValue": 0.14099783080260303,
|
|
255
|
+
"pageViews": 46100,
|
|
256
|
+
"samples": 46100,
|
|
257
|
+
"metrics": [
|
|
258
|
+
{
|
|
259
|
+
"type": "traffic",
|
|
260
|
+
"value": {
|
|
261
|
+
"total": 46100,
|
|
262
|
+
"paid": 0,
|
|
263
|
+
"owned": 46100,
|
|
264
|
+
"earned": 0
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
"type": "ctr",
|
|
269
|
+
"value": {
|
|
270
|
+
"page": 0.14099783080260303,
|
|
271
|
+
"siteAverage": 0.4077909270216962
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
]
|
|
277
|
+
|
|
278
|
+
```
|
|
279
|
+
|
|
194
280
|
## Linting
|
|
195
281
|
Lint the codebase using:
|
|
196
282
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-rum-api-client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - Rum API client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@adobe/helix-shared-wrap": "2.0.2",
|
|
40
40
|
"@adobe/helix-universal": "5.0.5",
|
|
41
41
|
"@adobe/spacecat-shared-utils": "1.4.0",
|
|
42
|
-
"aws4": "1.13.
|
|
42
|
+
"aws4": "1.13.2",
|
|
43
43
|
"d3-array": "3.2.4",
|
|
44
44
|
"urijs": "^1.19.11"
|
|
45
45
|
},
|
|
@@ -23,6 +23,60 @@ function pageviewsByUrl(bundles) {
|
|
|
23
23
|
}, {});
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Calculates the Click-Through Rate (CTR) by URL.
|
|
28
|
+
* CTR is defined as the total number of sessions with at least one click event
|
|
29
|
+
* divided by the total number of pageviews for each URL.
|
|
30
|
+
*
|
|
31
|
+
* @param {Array<Object>} bundles - An array of RUM bundles (NOT Flat bundles).
|
|
32
|
+
* @returns {Object} - An object where the key is the URL and the value is the CTR value.
|
|
33
|
+
*/
|
|
34
|
+
function getCTRByUrl(bundles) {
|
|
35
|
+
const aggregated = bundles.reduce((acc, bundle) => {
|
|
36
|
+
const { url } = bundle;
|
|
37
|
+
if (!acc[url]) {
|
|
38
|
+
acc[url] = { sessionsWithClick: 0, totalPageviews: 0 };
|
|
39
|
+
}
|
|
40
|
+
const hasClick = bundle.events.some((event) => event.checkpoint === 'click');
|
|
41
|
+
|
|
42
|
+
acc[url].totalPageviews += bundle.weight;
|
|
43
|
+
if (hasClick) {
|
|
44
|
+
acc[url].sessionsWithClick += bundle.weight;
|
|
45
|
+
}
|
|
46
|
+
return acc;
|
|
47
|
+
}, {});
|
|
48
|
+
return Object.entries(aggregated)
|
|
49
|
+
.reduce((acc, [url, { sessionsWithClick, totalPageviews }]) => {
|
|
50
|
+
acc[url] = (sessionsWithClick / totalPageviews);
|
|
51
|
+
return acc;
|
|
52
|
+
}, {});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Calculates the Click-Through Rate (CTR) average for the entire site.
|
|
57
|
+
* CTR is defined as the total number of sessions with at least one click event
|
|
58
|
+
* divided by the total number of pageviews for the entire site.
|
|
59
|
+
*
|
|
60
|
+
* @param {Array<Object>} bundles - An array of RUM bundles (NOT Flat bundles).
|
|
61
|
+
* @returns {number} - Average CTR for the site.
|
|
62
|
+
*/
|
|
63
|
+
function getSiteAvgCTR(bundles) {
|
|
64
|
+
const aggregated = bundles.reduce((acc, bundle) => {
|
|
65
|
+
const hasClick = bundle.events.some((event) => event.checkpoint === 'click');
|
|
66
|
+
acc.totalPageviews += bundle.weight;
|
|
67
|
+
if (hasClick) {
|
|
68
|
+
acc.sessionsWithClick += bundle.weight;
|
|
69
|
+
}
|
|
70
|
+
return acc;
|
|
71
|
+
}, { sessionsWithClick: 0, totalPageviews: 0 });
|
|
72
|
+
|
|
73
|
+
return aggregated.totalPageviews === 0
|
|
74
|
+
? 0
|
|
75
|
+
: aggregated.sessionsWithClick / aggregated.totalPageviews;
|
|
76
|
+
}
|
|
77
|
+
|
|
26
78
|
export {
|
|
79
|
+
getSiteAvgCTR,
|
|
80
|
+
getCTRByUrl,
|
|
27
81
|
pageviewsByUrl,
|
|
28
82
|
};
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
|
|
13
|
+
import trafficAcquisition from '../traffic-acquisition.js';
|
|
14
|
+
import { getCTRByUrl } from '../../common/aggregateFns.js';
|
|
15
|
+
|
|
16
|
+
const HOMEPAGE_PAID_TRAFFIC_THRESHOLD = 0.8;
|
|
17
|
+
const NON_HOMEPAGE_PAID_TRAFFIC_THRESHOLD = 0.5;
|
|
18
|
+
const BOUNCE_RATE_THRESHOLD = 0.5;
|
|
19
|
+
const DAILY_PAGEVIEW_THRESHOLD = 1000;
|
|
20
|
+
|
|
21
|
+
function convertToOpportunity(traffic) {
|
|
22
|
+
const {
|
|
23
|
+
url, total, bounceRate, paid, earned, owned,
|
|
24
|
+
} = traffic;
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
type: 'high-inorganic-high-bounce-rate',
|
|
28
|
+
page: url,
|
|
29
|
+
screenshot: '',
|
|
30
|
+
trackedPageKPIName: 'Bounce Rate',
|
|
31
|
+
trackedPageKPIValue: bounceRate,
|
|
32
|
+
pageViews: total,
|
|
33
|
+
samples: total, // todo: get the actual number of samples
|
|
34
|
+
metrics: [{
|
|
35
|
+
type: 'traffic',
|
|
36
|
+
value: {
|
|
37
|
+
total,
|
|
38
|
+
paid,
|
|
39
|
+
owned,
|
|
40
|
+
earned,
|
|
41
|
+
},
|
|
42
|
+
}],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function hasHighInorganicTraffic(traffic) {
|
|
47
|
+
const { url, paid, total } = traffic;
|
|
48
|
+
const isHomepage = new URL(url).pathname === '/';
|
|
49
|
+
const threshold = isHomepage
|
|
50
|
+
? HOMEPAGE_PAID_TRAFFIC_THRESHOLD
|
|
51
|
+
: NON_HOMEPAGE_PAID_TRAFFIC_THRESHOLD;
|
|
52
|
+
return paid / total > threshold;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function hasHighBounceRate(ctr) {
|
|
56
|
+
return ctr < BOUNCE_RATE_THRESHOLD;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function handler(bundles, opts = {}) {
|
|
60
|
+
const { interval = 7 } = opts;
|
|
61
|
+
const trafficByUrl = trafficAcquisition.handler(bundles);
|
|
62
|
+
const ctrByUrl = getCTRByUrl(bundles);
|
|
63
|
+
|
|
64
|
+
return trafficByUrl.filter((traffic) => traffic.total > interval * DAILY_PAGEVIEW_THRESHOLD)
|
|
65
|
+
.filter(hasHighInorganicTraffic)
|
|
66
|
+
.filter((traffic) => hasHighBounceRate(ctrByUrl[traffic.url]))
|
|
67
|
+
.map((traffic) => ({ ...traffic, bounceRate: 1 - ctrByUrl[traffic.url] }))
|
|
68
|
+
.map(convertToOpportunity);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default {
|
|
72
|
+
handler,
|
|
73
|
+
checkpoints: ['email', 'enter', 'paid', 'utm', 'click', 'experiment'],
|
|
74
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
|
|
13
|
+
import trafficAcquisition from '../traffic-acquisition.js';
|
|
14
|
+
import { getCTRByUrl, getSiteAvgCTR } from '../../common/aggregateFns.js';
|
|
15
|
+
|
|
16
|
+
const DAILY_EARNED_THRESHOLD = 5000;
|
|
17
|
+
const CTR_THRESHOLD_RATIO = 0.95;
|
|
18
|
+
const DAILY_PAGEVIEW_THRESHOLD = 1000;
|
|
19
|
+
|
|
20
|
+
function convertToOpportunity(traffic) {
|
|
21
|
+
const {
|
|
22
|
+
url, total, ctr, paid, owned, earned, siteAvgCTR,
|
|
23
|
+
} = traffic;
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
type: 'high-organic-low-ctr',
|
|
27
|
+
page: url,
|
|
28
|
+
screenshot: '',
|
|
29
|
+
trackedPageKPIName: 'Click Through Rate',
|
|
30
|
+
trackedPageKPIValue: ctr,
|
|
31
|
+
pageViews: total,
|
|
32
|
+
samples: total, // todo: get the actual number of samples
|
|
33
|
+
metrics: [{
|
|
34
|
+
type: 'traffic',
|
|
35
|
+
value: {
|
|
36
|
+
total,
|
|
37
|
+
paid,
|
|
38
|
+
owned,
|
|
39
|
+
earned,
|
|
40
|
+
},
|
|
41
|
+
}, {
|
|
42
|
+
type: 'ctr',
|
|
43
|
+
value: {
|
|
44
|
+
page: ctr,
|
|
45
|
+
siteAverage: siteAvgCTR,
|
|
46
|
+
},
|
|
47
|
+
}],
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function hasHighOrganicTraffic(interval, traffic) {
|
|
52
|
+
const { earned, owned } = traffic;
|
|
53
|
+
return earned + owned > DAILY_EARNED_THRESHOLD * interval;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function hasLowerCTR(ctr, siteAvgCTR) {
|
|
57
|
+
return ctr < CTR_THRESHOLD_RATIO * siteAvgCTR;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function handler(bundles, opts = {}) {
|
|
61
|
+
const { interval = 7 } = opts;
|
|
62
|
+
|
|
63
|
+
const trafficByUrl = trafficAcquisition.handler(bundles);
|
|
64
|
+
const ctrByUrl = getCTRByUrl(bundles);
|
|
65
|
+
const siteAvgCTR = getSiteAvgCTR(bundles);
|
|
66
|
+
|
|
67
|
+
return trafficByUrl.filter((traffic) => traffic.total > interval * DAILY_PAGEVIEW_THRESHOLD)
|
|
68
|
+
.filter(hasHighOrganicTraffic.bind(null, interval))
|
|
69
|
+
.filter((traffic) => hasLowerCTR(ctrByUrl[traffic.url], siteAvgCTR))
|
|
70
|
+
.map((traffic) => ({ ...traffic, ctr: ctrByUrl[traffic.url], siteAvgCTR }))
|
|
71
|
+
.map(convertToOpportunity);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default {
|
|
75
|
+
handler,
|
|
76
|
+
checkpoints: ['email', 'enter', 'paid', 'utm', 'click', 'experiment'],
|
|
77
|
+
};
|
|
@@ -0,0 +1,222 @@
|
|
|
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
|
+
|
|
13
|
+
/**
|
|
14
|
+
* return the pages that have rage clicks along with selectors and number of clicks
|
|
15
|
+
* @param {*} bundles
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/* c8 ignore start */
|
|
20
|
+
const DEFAULT_RAGE_CLICK_THRESHOLD = 10;
|
|
21
|
+
const DEFAULT_RAGECLICK_PERCENT_THRESHOLD = 5;
|
|
22
|
+
const DEFAULT_MINIMUM_RAGECLICK_SAMPLES_THRESHOLD = 10;
|
|
23
|
+
const DEFAULT_RAGECLICK_SAMPLES_THRESHOLD = 100;
|
|
24
|
+
const DEFAULT_RAGECLICK_PAGEVIEW_THRESHOLD = 5000;
|
|
25
|
+
|
|
26
|
+
const COMMERCE_SELECTORS_IGNORE_LIST = [
|
|
27
|
+
'.product-list-page',
|
|
28
|
+
'.product-details-verb',
|
|
29
|
+
'.product-details',
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const EDS_BLOCK_SELECTORS_IGNORE_LIST = ['.accordion'];
|
|
33
|
+
|
|
34
|
+
const RAGECLICK_SELECTORS_IGNORE_LIST = [
|
|
35
|
+
...COMMERCE_SELECTORS_IGNORE_LIST,
|
|
36
|
+
...EDS_BLOCK_SELECTORS_IGNORE_LIST,
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
const OPPORTUNITY_TYPE = 'rageclick';
|
|
40
|
+
const OPPORTUNITY_DESCRIPTION = 'The percentage of users who click on the same element lot of times in a short period of time.';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns the selectors that have more than DEFAULT_RAGE_CLICK_THRESHOLD clicks from the events
|
|
44
|
+
* @param {*} events
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
function getRageClickSelectors(events, threshold, selectorsIgnoreList = []) {
|
|
48
|
+
const clickSelectors = {};
|
|
49
|
+
for (const event of events) {
|
|
50
|
+
const { source, target, checkpoint } = event;
|
|
51
|
+
if (checkpoint === 'click' && !selectorsIgnoreList.includes(source)) {
|
|
52
|
+
if (!clickSelectors[source]) {
|
|
53
|
+
clickSelectors[source] = {
|
|
54
|
+
value: 0,
|
|
55
|
+
target: {
|
|
56
|
+
[target]: 0,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
clickSelectors[source].value += 1;
|
|
61
|
+
if (!clickSelectors[source].target[target]) {
|
|
62
|
+
clickSelectors[source].target[target] = 1;
|
|
63
|
+
} else {
|
|
64
|
+
clickSelectors[source].target[target] += 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (const selector of Object.keys(clickSelectors)) {
|
|
69
|
+
if (clickSelectors[selector].value < threshold) {
|
|
70
|
+
delete clickSelectors[selector];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return clickSelectors;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function filterRageClickInstancesByThreshold(
|
|
77
|
+
rageClickInstances,
|
|
78
|
+
pageData,
|
|
79
|
+
thresholds,
|
|
80
|
+
) {
|
|
81
|
+
for (const url of Object.keys(rageClickInstances)) {
|
|
82
|
+
if (pageData[url].pageViews < thresholds.rageClickPageviewThreshold) {
|
|
83
|
+
// eslint-disable-next-line no-param-reassign
|
|
84
|
+
delete rageClickInstances[url];
|
|
85
|
+
} else {
|
|
86
|
+
for (const selector of Object.keys(rageClickInstances[url])) {
|
|
87
|
+
const rageClickPercentage = (
|
|
88
|
+
rageClickInstances[url][selector].samples / pageData[url].samples) * 100;
|
|
89
|
+
if ((rageClickInstances[url][selector].samples >= thresholds.rageClickMinSamplesThreshold
|
|
90
|
+
&& rageClickPercentage >= thresholds.rageClickPercentThreshold)
|
|
91
|
+
|| rageClickInstances[url][selector].samples >= thresholds.rageClickSamplesThreshold) {
|
|
92
|
+
// eslint-disable-next-line no-param-reassign
|
|
93
|
+
rageClickInstances[url][selector].percentage = rageClickPercentage;
|
|
94
|
+
} else {
|
|
95
|
+
// eslint-disable-next-line no-param-reassign
|
|
96
|
+
delete rageClickInstances[url][selector];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (Object.keys(rageClickInstances[url]).length === 0) {
|
|
100
|
+
// eslint-disable-next-line no-param-reassign
|
|
101
|
+
delete rageClickInstances[url];
|
|
102
|
+
} else {
|
|
103
|
+
// eslint-disable-next-line no-param-reassign
|
|
104
|
+
rageClickInstances[url].pageViews = pageData[url].pageViews;
|
|
105
|
+
// eslint-disable-next-line no-param-reassign
|
|
106
|
+
rageClickInstances[url].samples = pageData[url].samples;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function getRageClickOpportunities(rageClickInstances) {
|
|
113
|
+
const opportunities = [];
|
|
114
|
+
for (const url of Object.keys(rageClickInstances)) {
|
|
115
|
+
const opportunity = {
|
|
116
|
+
type: OPPORTUNITY_TYPE,
|
|
117
|
+
page: url,
|
|
118
|
+
screenshot: '',
|
|
119
|
+
trackedPageKPIName: OPPORTUNITY_DESCRIPTION,
|
|
120
|
+
trackedPageKPIValue: '',
|
|
121
|
+
pageViews: rageClickInstances[url].pageViews,
|
|
122
|
+
samples: rageClickInstances[url].samples,
|
|
123
|
+
metrics: [],
|
|
124
|
+
};
|
|
125
|
+
for (const selector of Object.keys(rageClickInstances[url])) {
|
|
126
|
+
if (typeof rageClickInstances[url][selector] === 'object') {
|
|
127
|
+
opportunity.metrics.push({
|
|
128
|
+
type: 'click',
|
|
129
|
+
selector,
|
|
130
|
+
targets: rageClickInstances[url][selector].target,
|
|
131
|
+
value: rageClickInstances[url][selector].value,
|
|
132
|
+
samples: rageClickInstances[url][selector].samples,
|
|
133
|
+
percentage: rageClickInstances[url][selector].percentage,
|
|
134
|
+
mobileSamples: rageClickInstances[url][selector].mobileSamples,
|
|
135
|
+
desktopSamples: rageClickInstances[url][selector].desktopSamples,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const avgRageClickPercentage = opportunity.metrics.reduce(
|
|
140
|
+
(acc, metric) => acc + metric.percentage,
|
|
141
|
+
0,
|
|
142
|
+
) / opportunity.metrics.length;
|
|
143
|
+
opportunity.trackedPageKPIValue = avgRageClickPercentage;
|
|
144
|
+
opportunities.push(opportunity);
|
|
145
|
+
}
|
|
146
|
+
return opportunities;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function handler(bundles) {
|
|
150
|
+
const rageClickInstances = {};
|
|
151
|
+
const pageData = {};
|
|
152
|
+
const rageClickThreshold = process.env.RAGE_CLICK_THRESHOLD || DEFAULT_RAGE_CLICK_THRESHOLD;
|
|
153
|
+
const rageClickPercentThreshold = process.env.RAGE_CLICK_PERCENT_THRESHOLD
|
|
154
|
+
|| DEFAULT_RAGECLICK_PERCENT_THRESHOLD;
|
|
155
|
+
const rageClickPageviewThreshold = process.env.RAGE_CLICK_PAGEVIEW_THRESHOLD
|
|
156
|
+
|| DEFAULT_RAGECLICK_PAGEVIEW_THRESHOLD;
|
|
157
|
+
const rageClickMinSamplesThreshold = process.env.RAGE_CLICK_MIN_SAMPLES_THRESHOLD
|
|
158
|
+
|| DEFAULT_MINIMUM_RAGECLICK_SAMPLES_THRESHOLD;
|
|
159
|
+
const rageClickSamplesThreshold = process.env.RAGE_CLICK_SAMPLES_THRESHOLD
|
|
160
|
+
|| DEFAULT_RAGECLICK_SAMPLES_THRESHOLD;
|
|
161
|
+
const thresholds = {
|
|
162
|
+
rageClickPercentThreshold,
|
|
163
|
+
rageClickPageviewThreshold,
|
|
164
|
+
rageClickMinSamplesThreshold,
|
|
165
|
+
rageClickSamplesThreshold,
|
|
166
|
+
};
|
|
167
|
+
for (const bundle of bundles) {
|
|
168
|
+
const { url, weight } = bundle;
|
|
169
|
+
if (!pageData[url]) {
|
|
170
|
+
pageData[url] = {
|
|
171
|
+
pageViews: weight,
|
|
172
|
+
samples: 1,
|
|
173
|
+
};
|
|
174
|
+
} else {
|
|
175
|
+
pageData[url].pageViews += weight;
|
|
176
|
+
pageData[url].samples += 1;
|
|
177
|
+
}
|
|
178
|
+
const rageClickSelectors = getRageClickSelectors(
|
|
179
|
+
bundle.events,
|
|
180
|
+
rageClickThreshold,
|
|
181
|
+
RAGECLICK_SELECTORS_IGNORE_LIST,
|
|
182
|
+
);
|
|
183
|
+
const isMobile = bundle.userAgent && bundle.userAgent.includes('mobile');
|
|
184
|
+
if (Object.keys(rageClickSelectors).length > 0) {
|
|
185
|
+
if (!rageClickInstances[url]) {
|
|
186
|
+
rageClickInstances[url] = {};
|
|
187
|
+
}
|
|
188
|
+
for (const selector of Object.keys(rageClickSelectors)) {
|
|
189
|
+
if (!rageClickInstances[url][selector]) {
|
|
190
|
+
rageClickInstances[url][selector] = {};
|
|
191
|
+
rageClickInstances[url][selector].value = rageClickSelectors[selector].value;
|
|
192
|
+
rageClickInstances[url][selector].samples = 1;
|
|
193
|
+
rageClickInstances[url][selector].target = rageClickSelectors[selector].target;
|
|
194
|
+
rageClickInstances[url][selector].mobileSamples = isMobile ? 1 : 0;
|
|
195
|
+
rageClickInstances[url][selector].desktopSamples = !isMobile ? 1 : 0;
|
|
196
|
+
} else {
|
|
197
|
+
rageClickInstances[url][selector].value += rageClickSelectors[selector].value;
|
|
198
|
+
rageClickInstances[url][selector].samples += 1;
|
|
199
|
+
rageClickInstances[url][selector].mobileSamples += isMobile ? 1 : 0;
|
|
200
|
+
rageClickInstances[url][selector].desktopSamples += !isMobile ? 1 : 0;
|
|
201
|
+
for (const target of Object.keys(rageClickSelectors[selector].target)) {
|
|
202
|
+
if (!rageClickInstances[url][selector].target[target]) {
|
|
203
|
+
// eslint-disable-next-line max-len
|
|
204
|
+
rageClickInstances[url][selector].target[target] = rageClickSelectors[selector].target[target];
|
|
205
|
+
} else {
|
|
206
|
+
// eslint-disable-next-line max-len
|
|
207
|
+
rageClickInstances[url][selector].target[target] += rageClickSelectors[selector].target[target];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
filterRageClickInstancesByThreshold(rageClickInstances, pageData, thresholds);
|
|
215
|
+
return getRageClickOpportunities(rageClickInstances);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export default {
|
|
219
|
+
handler,
|
|
220
|
+
checkpoints: ['click'],
|
|
221
|
+
};
|
|
222
|
+
/* c8 ignore stop */
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
import { classifyTrafficSource } from '../common/traffic.js';
|
|
14
14
|
|
|
15
|
+
const MAIN_TYPES = ['total', 'paid', 'earned', 'owned'];
|
|
16
|
+
|
|
15
17
|
function extractHints(bundle) {
|
|
16
18
|
const findEvent = (checkpoint, source = '') => bundle.events.find((e) => e.checkpoint === checkpoint && (!source || e.source === source)) || {};
|
|
17
19
|
|
|
@@ -31,9 +33,12 @@ function extractHints(bundle) {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
function collectByUrlAndTrafficSource(acc, { url, weight, trafficSource }) {
|
|
34
|
-
acc[url] = acc[url] || {
|
|
36
|
+
acc[url] = acc[url] || {
|
|
37
|
+
total: 0, owned: 0, earned: 0, paid: 0,
|
|
38
|
+
};
|
|
35
39
|
acc[url][trafficSource] = (acc[url][trafficSource] || 0) + weight;
|
|
36
40
|
acc[url].total += weight;
|
|
41
|
+
acc[url][trafficSource.split(':')[0]] += weight;
|
|
37
42
|
return acc;
|
|
38
43
|
}
|
|
39
44
|
|
|
@@ -41,13 +46,16 @@ function transformFormat(trafficSources) {
|
|
|
41
46
|
return Object.entries(trafficSources).map(([url, value]) => ({
|
|
42
47
|
url,
|
|
43
48
|
total: value.total,
|
|
49
|
+
earned: value.earned,
|
|
50
|
+
owned: value.owned,
|
|
51
|
+
paid: value.paid,
|
|
44
52
|
sources: Object.entries(value)
|
|
45
|
-
.filter(([source]) => source
|
|
53
|
+
.filter(([source]) => !MAIN_TYPES.includes(source))
|
|
46
54
|
.map(([source, views]) => ({ type: source, views })),
|
|
47
55
|
}));
|
|
48
56
|
}
|
|
49
57
|
|
|
50
|
-
|
|
58
|
+
function handler(bundles) {
|
|
51
59
|
const trafficSources = bundles
|
|
52
60
|
.map(extractHints)
|
|
53
61
|
.map((row) => {
|
package/src/index.d.ts
CHANGED
|
@@ -56,5 +56,5 @@ export default class RUMAPIClient {
|
|
|
56
56
|
* @returns {Promise<object>} A Promise that resolves to an object where each key is the name
|
|
57
57
|
* of a query, and each value is the result of that query.
|
|
58
58
|
*/
|
|
59
|
-
queryMulti(queries: string[], opts?: RUMAPIOptions): Promise<object
|
|
59
|
+
queryMulti(queries: string[], opts?: RUMAPIOptions): Promise<object>;
|
|
60
60
|
}
|
package/src/index.js
CHANGED
|
@@ -15,6 +15,9 @@ import cwv from './functions/cwv.js';
|
|
|
15
15
|
import experiment from './functions/experiment.js';
|
|
16
16
|
import trafficAcquisition from './functions/traffic-acquisition.js';
|
|
17
17
|
import variant from './functions/variant.js';
|
|
18
|
+
import rageclick from './functions/opportunities/rageclick.js';
|
|
19
|
+
import highInorganicHighBounceRate from './functions/opportunities/high-inorganic-high-bounce-rate.js';
|
|
20
|
+
import highOrganicLowCtr from './functions/opportunities/high-organic-low-ctr.js';
|
|
18
21
|
|
|
19
22
|
const HANDLERS = {
|
|
20
23
|
404: notfound,
|
|
@@ -22,6 +25,9 @@ const HANDLERS = {
|
|
|
22
25
|
experiment,
|
|
23
26
|
'traffic-acquisition': trafficAcquisition,
|
|
24
27
|
variant,
|
|
28
|
+
rageclick,
|
|
29
|
+
'high-inorganic-high-bounce-rate': highInorganicHighBounceRate,
|
|
30
|
+
'high-organic-low-ctr': highOrganicLowCtr,
|
|
25
31
|
};
|
|
26
32
|
|
|
27
33
|
export default class RUMAPIClient {
|
|
@@ -78,7 +84,7 @@ export default class RUMAPIClient {
|
|
|
78
84
|
// Execute each query handler sequentially
|
|
79
85
|
for (const { query, handler } of queryHandlers) {
|
|
80
86
|
// eslint-disable-next-line no-await-in-loop
|
|
81
|
-
results[query] = await handler(bundles);
|
|
87
|
+
results[query] = await handler(bundles, opts);
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
return results;
|