@adobe/spacecat-shared-rum-api-client 2.19.1 → 2.20.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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [@adobe/spacecat-shared-rum-api-client-v2.20.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.20.0...@adobe/spacecat-shared-rum-api-client-v2.20.1) (2025-02-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **rum-api-client:** suppress rum logs ([#586](https://github.com/adobe/spacecat-shared/issues/586)) ([7cfe551](https://github.com/adobe/spacecat-shared/commit/7cfe55138c89bb21c8e16c59a7bfa26ff2cf8e80))
7
+
8
+ # [@adobe/spacecat-shared-rum-api-client-v2.20.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.19.1...@adobe/spacecat-shared-rum-api-client-v2.20.0) (2025-02-06)
9
+
10
+
11
+ ### Features
12
+
13
+ * add timeOnPage data for HOTLC ([#567](https://github.com/adobe/spacecat-shared/issues/567)) ([e055eb9](https://github.com/adobe/spacecat-shared/commit/e055eb9d035d0191cbd1fa521918796f584e99b6))
14
+
1
15
  # [@adobe/spacecat-shared-rum-api-client-v2.19.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.19.0...@adobe/spacecat-shared-rum-api-client-v2.19.1) (2025-01-31)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-rum-api-client",
3
- "version": "2.19.1",
3
+ "version": "2.20.1",
4
4
  "description": "Shared modules of the Spacecat Services - Rum API client",
5
5
  "type": "module",
6
6
  "engines": {
@@ -46,7 +46,7 @@
46
46
  "devDependencies": {
47
47
  "chai": "5.1.2",
48
48
  "chai-as-promised": "8.0.1",
49
- "nock": "13.5.6",
49
+ "nock": "14.0.0",
50
50
  "sinon": "19.0.2",
51
51
  "sinon-chai": "4.0.0",
52
52
  "typescript": "5.7.3"
@@ -193,8 +193,6 @@ async function fetchBundles(opts, log) {
193
193
  // eslint-disable-next-line no-loop-func
194
194
  const responses = await Promise.all(chunk.map(async (url) => {
195
195
  const response = await fetch(url);
196
- const xCache = response.headers.get('x-cache')?.toLowerCase().includes('hit');
197
- log.info(`Retrieving RUM bundles. Source: ${xCache ? 'CDN' : 'ORIGIN'}. Granularity: ${granularity}. Domain: ${domain}`);
198
196
  totalTransferSize += parseInt(response.headers.get('content-length'), 10);
199
197
  return response;
200
198
  }));
@@ -22,7 +22,7 @@ const MAIN_TYPES = ['paid', 'earned', 'owned'];
22
22
 
23
23
  function convertToOpportunity(traffic) {
24
24
  const {
25
- url, total, ctr, paid, owned, earned, sources, siteAvgCTR, ctrByUrlAndVendor,
25
+ url, total, ctr, paid, owned, earned, sources, siteAvgCTR, ctrByUrlAndVendor, pageOnTime,
26
26
  } = traffic;
27
27
 
28
28
  const vendors = sources.reduce((acc, { type, views }) => {
@@ -66,6 +66,12 @@ function convertToOpportunity(traffic) {
66
66
  value: {
67
67
  page: ctr,
68
68
  },
69
+ }, {
70
+ type: 'pageOnTime',
71
+ vendor: '*',
72
+ value: {
73
+ time: pageOnTime,
74
+ },
69
75
  }],
70
76
  };
71
77
  opportunity.metrics.push(...topVendors.flatMap(([vendor, {
@@ -88,7 +94,14 @@ function convertToOpportunity(traffic) {
88
94
  page: ctrByUrlAndVendor[vendor],
89
95
  },
90
96
  };
91
- return [trafficMetrics, ctrMetrics];
97
+ const pageOnTimeMetrics = {
98
+ type: 'pageOnTime',
99
+ vendor,
100
+ value: {
101
+ time: pageOnTime,
102
+ },
103
+ };
104
+ return [trafficMetrics, ctrMetrics, pageOnTimeMetrics];
92
105
  }));
93
106
  return opportunity;
94
107
  }
@@ -117,11 +130,11 @@ function handler(bundles, opts = {}) {
117
130
  ctr: ctrByUrlAndVendor[traffic.url].value,
118
131
  siteAvgCTR,
119
132
  ctrByUrlAndVendor: ctrByUrlAndVendor[traffic.url].vendors,
133
+ pageOnTime: traffic.maxTimeDelta,
120
134
  }))
121
135
  .map(convertToOpportunity);
122
136
  }
123
137
 
124
138
  export default {
125
139
  handler,
126
- checkpoints: ['email', 'enter', 'paid', 'utm', 'click', 'experiment'],
127
140
  };
@@ -15,13 +15,14 @@ import { classifyTraffic } from '../common/traffic.js';
15
15
  const MAIN_TYPES = ['total', 'paid', 'earned', 'owned'];
16
16
 
17
17
  function collectByUrlAndTrafficSource(acc, {
18
- url, weight, trafficSource,
18
+ url, weight, trafficSource, maxTimeDelta,
19
19
  }) {
20
20
  acc[url] = acc[url] || {
21
- total: 0, owned: 0, earned: 0, paid: 0,
21
+ total: 0, owned: 0, earned: 0, paid: 0, maxTimeDelta: 0,
22
22
  };
23
23
  acc[url][trafficSource] = (acc[url][trafficSource] || 0) + weight;
24
24
  acc[url].total += weight;
25
+ acc[url].maxTimeDelta = maxTimeDelta;
25
26
  const trafficType = trafficSource.split(':')[0];
26
27
  acc[url][trafficType] += weight;
27
28
  return acc;
@@ -34,26 +35,34 @@ function transformFormat(trafficSources) {
34
35
  earned: value.earned,
35
36
  owned: value.owned,
36
37
  paid: value.paid,
38
+ maxTimeDelta: value.maxTimeDelta,
37
39
  sources: Object.entries(value)
38
- .filter(([source]) => !MAIN_TYPES.includes(source))
40
+ .filter(([source]) => !MAIN_TYPES.includes(source) && source !== 'maxTimeDelta')
39
41
  .map(([source, views]) => ({ type: source, views })),
40
42
  }));
41
43
  }
42
44
 
43
45
  function formatTraffic(row) {
44
46
  const {
45
- url, weight, type, category, vendor,
47
+ url, weight, type, category, vendor, events = [],
46
48
  } = row;
49
+
50
+ const maxTimeDelta = events.reduce((max, e) => Math.max(max, e.timeDelta), 0);
51
+
47
52
  return {
48
53
  url,
49
54
  weight,
50
55
  trafficSource: vendor ? `${type}:${category}:${vendor}` : `${type}:${category}`,
56
+ maxTimeDelta,
51
57
  };
52
58
  }
53
59
 
54
60
  function handler(bundles) {
55
61
  const trafficSources = bundles
56
- .map(classifyTraffic)
62
+ .map((bundle) => ({
63
+ ...classifyTraffic(bundle),
64
+ events: bundle.events,
65
+ }))
57
66
  .map(formatTraffic)
58
67
  .reduce(collectByUrlAndTrafficSource, {});
59
68
 
@@ -63,5 +72,4 @@ function handler(bundles) {
63
72
 
64
73
  export default {
65
74
  handler,
66
- checkpoints: ['email', 'enter', 'paid', 'utm', 'experiment'],
67
75
  };