@adobe/spacecat-shared-rum-api-client 2.31.1 → 2.32.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.32.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.32.0...@adobe/spacecat-shared-rum-api-client-v2.32.1) (2025-07-12)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update dependency @adobe/rum-distiller to v1.17.0 ([#844](https://github.com/adobe/spacecat-shared/issues/844)) ([17e8237](https://github.com/adobe/spacecat-shared/commit/17e8237ef56c9b7a6d4b13cd8ddf5f868e8d92bc)), closes [#8203](https://github.com/adobe/spacecat-shared/issues/8203)
7
+
8
+ # [@adobe/spacecat-shared-rum-api-client-v2.32.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.31.1...@adobe/spacecat-shared-rum-api-client-v2.32.0) (2025-07-11)
9
+
10
+
11
+ ### Features
12
+
13
+ * add RUM API Client handler for paid traffic analysis import ([#841](https://github.com/adobe/spacecat-shared/issues/841)) ([6e6656e](https://github.com/adobe/spacecat-shared/commit/6e6656efb7e9741b52d26c21ea910988b219e2cc))
14
+
1
15
  # [@adobe/spacecat-shared-rum-api-client-v2.31.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.31.0...@adobe/spacecat-shared-rum-api-client-v2.31.1) (2025-06-30)
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.31.1",
3
+ "version": "2.32.1",
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.2.2",
41
41
  "@adobe/spacecat-shared-utils": "1.26.4",
42
- "@adobe/rum-distiller": "1.16.3",
42
+ "@adobe/rum-distiller": "1.17.0",
43
43
  "aws4": "1.13.2",
44
44
  "urijs": "1.19.11"
45
45
  },
@@ -0,0 +1,129 @@
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 { utils } from '@adobe/rum-distiller';
14
+ import { classifyTraffic } from '../common/traffic.js';
15
+
16
+ function getUTM(bundle, type) {
17
+ return bundle.events
18
+ .find((e) => e.checkpoint === 'utm' && e.source === `utm_${type}`)
19
+ ?.target || null;
20
+ }
21
+
22
+ function getCWV(bundle, metric) {
23
+ const measurements = bundle.events
24
+ .filter((e) => e.checkpoint === `cwv-${metric}`)
25
+ .map((e) => e.value);
26
+
27
+ return measurements.length > 0 ? Math.max(...measurements) : null;
28
+ }
29
+
30
+ function containsEngagedScroll(bundle) {
31
+ return bundle.events
32
+ .some((e) => (e.checkpoint === 'viewmedia' || e.checkpoint === 'viewblock') && e.timeDelta >= 10000)
33
+ ? 1 : 0;
34
+ }
35
+
36
+ function getNotFound(bundle) {
37
+ return bundle.events
38
+ .find((e) => e.checkpoint === '404')
39
+ ?.source || null;
40
+ }
41
+
42
+ function getReferrer(bundle) {
43
+ const enterCheckpoint = bundle.events
44
+ .find((e) => e.checkpoint === 'enter')
45
+ ?.source;
46
+
47
+ const navigateCheckpoint = bundle.events
48
+ .find((e) => e.checkpoint === 'navigate')
49
+ ?.source;
50
+
51
+ return navigateCheckpoint || enterCheckpoint || null;
52
+ }
53
+
54
+ function getClicked(bundle) {
55
+ const latestClickEvent = bundle.events
56
+ .filter((e) => e.checkpoint === 'click')
57
+ .reduce((latest, current) => {
58
+ if (!latest || !latest.timeDelta) return current;
59
+ if (current?.timeDelta > latest.timeDelta) return current;
60
+ return latest;
61
+ }, null);
62
+
63
+ if (!latestClickEvent) return 0;
64
+
65
+ const isConsentClick = !!utils.reclassifyConsent(latestClickEvent).vendor;
66
+
67
+ if (isConsentClick) return 0;
68
+
69
+ return 1;
70
+ }
71
+
72
+ function getConsent(bundle) {
73
+ const consentBannerStatus = bundle.events
74
+ .find((e) => e.checkpoint === 'consent')
75
+ ?.target;
76
+
77
+ const consentClick = bundle.events.find((e) => e.checkpoint === 'click' && utils.reclassifyConsent(e).vendor);
78
+
79
+ if (!consentClick) return consentBannerStatus || null;
80
+
81
+ return utils.reclassifyConsent(consentClick).target;
82
+ }
83
+
84
+ function trafficType(bundle, memo) {
85
+ const key = `${bundle.id}${bundle.url}${bundle.time}`;
86
+ if (memo[key]) return memo[key];
87
+
88
+ const type = classifyTraffic(bundle);
89
+ // eslint-disable-next-line no-param-reassign
90
+ memo[key] = type;
91
+ return type;
92
+ }
93
+
94
+ async function handler(bundles) {
95
+ const memo = {};
96
+
97
+ const result = bundles.map((bundle) => {
98
+ /* eslint-disable camelcase */
99
+ const trafficData = trafficType(bundle, memo);
100
+ const clicked = getClicked(bundle);
101
+
102
+ return {
103
+ path: new URL(bundle.url).pathname,
104
+ trf_type: trafficData.type,
105
+ trf_channel: trafficData.category,
106
+ trf_platform: trafficData.vendor || null,
107
+ device: bundle.userAgent.split(':')[0],
108
+ utm_source: getUTM(bundle, 'source'),
109
+ utm_medium: getUTM(bundle, 'medium'),
110
+ utm_campaign: getUTM(bundle, 'campaign'),
111
+ referrer: getReferrer(bundle),
112
+ consent: getConsent(bundle),
113
+ notfound: getNotFound(bundle),
114
+ pageviews: bundle.weight,
115
+ clicked,
116
+ engaged: containsEngagedScroll(bundle) || clicked,
117
+ lcp: getCWV(bundle, 'lcp'),
118
+ inp: getCWV(bundle, 'inp'),
119
+ cls: getCWV(bundle, 'cls'),
120
+ };
121
+ /* eslint-enable camelcase */
122
+ });
123
+
124
+ return result;
125
+ }
126
+
127
+ export default {
128
+ handler,
129
+ };
package/src/index.js CHANGED
@@ -24,6 +24,7 @@ import trafficMetrics from './functions/traffic-metrics.js';
24
24
  import rageclick from './functions/opportunities/rageclick.js';
25
25
  import highInorganicHighBounceRate from './functions/opportunities/high-inorganic-high-bounce-rate.js';
26
26
  import highOrganicLowCtr from './functions/opportunities/high-organic-low-ctr.js';
27
+ import trafficAnalysis from './functions/traffic-analysis.js';
27
28
 
28
29
  // exported for tests
29
30
  export const RUM_BUNDLER_API_HOST = 'https://bundles.aem.page';
@@ -42,6 +43,7 @@ const HANDLERS = {
42
43
  'high-organic-low-ctr': highOrganicLowCtr,
43
44
  pageviews,
44
45
  trafficMetrics,
46
+ 'traffic-analysis': trafficAnalysis,
45
47
  };
46
48
 
47
49
  function sanitize(opts) {