@adobe/spacecat-shared-rum-api-client 2.2.0 → 2.3.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 CHANGED
@@ -1,3 +1,18 @@
1
+ # [@adobe/spacecat-shared-rum-api-client-v2.3.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.2.1...@adobe/spacecat-shared-rum-api-client-v2.3.0) (2024-07-12)
2
+
3
+
4
+ ### Features
5
+
6
+ * audit top pages for language mismatch (SITES-22690) ([#289](https://github.com/adobe/spacecat-shared/issues/289)) ([ec9d83a](https://github.com/adobe/spacecat-shared/commit/ec9d83a9f59ba7c88b2be3181c60290eae132219))
7
+
8
+ # [@adobe/spacecat-shared-rum-api-client-v2.2.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.2.0...@adobe/spacecat-shared-rum-api-client-v2.2.1) (2024-07-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * Click count is artificially inflating the conversion rate ([#278](https://github.com/adobe/spacecat-shared/issues/278)) ([77a1c6a](https://github.com/adobe/spacecat-shared/commit/77a1c6a27103db4ce463959b882311cf1d3924a3))
14
+ * **deps:** update external fixes ([#284](https://github.com/adobe/spacecat-shared/issues/284)) ([f4fe169](https://github.com/adobe/spacecat-shared/commit/f4fe1699c432637f1217198ad7f4a1cde6deeb76))
15
+
1
16
  # [@adobe/spacecat-shared-rum-api-client-v2.2.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.1.1...@adobe/spacecat-shared-rum-api-client-v2.2.0) (2024-06-28)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-rum-api-client",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Shared modules of the Spacecat Services - Rum API client",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -44,6 +44,6 @@
44
44
  "nock": "13.5.4",
45
45
  "sinon": "18.0.0",
46
46
  "sinon-chai": "3.7.0",
47
- "typescript": "5.5.2"
47
+ "typescript": "5.5.3"
48
48
  }
49
49
  }
@@ -62,9 +62,25 @@ function handler(bundles) {
62
62
  const variantObject = getOrCreateVariantObject(experimentObject.variants, variantName);
63
63
  variantObject.views += weight;
64
64
 
65
+ const metrics = {};
66
+ for (const checkpoint of METRIC_CHECKPOINTS) {
67
+ metrics[checkpoint] = {};
68
+ }
65
69
  for (const event of bundle.events) {
66
70
  if (METRIC_CHECKPOINTS.includes(event.checkpoint)) {
67
71
  const { source, checkpoint } = event;
72
+ if (!metrics[checkpoint][source]) {
73
+ metrics[checkpoint][source] = weight;
74
+ } else {
75
+ metrics[checkpoint][source] += weight;
76
+ }
77
+ }
78
+ }
79
+ // combine metrics and variantObject, considering the interaction events
80
+ // only once during the session
81
+ for (const checkpoint of METRIC_CHECKPOINTS) {
82
+ // eslint-disable-next-line no-restricted-syntax
83
+ for (const source in metrics[checkpoint]) {
68
84
  if (!variantObject[checkpoint][source]) {
69
85
  variantObject[checkpoint][source] = weight;
70
86
  } else {
@@ -72,6 +88,25 @@ function handler(bundles) {
72
88
  }
73
89
  }
74
90
  }
91
+ // add each metric to the variantObject's * count by weight
92
+ for (const checkpoint of Object.keys(metrics)) {
93
+ if (Object.keys(metrics[checkpoint]).length > 0) {
94
+ if (!variantObject[checkpoint]['*']) {
95
+ variantObject[checkpoint]['*'] = weight;
96
+ } else {
97
+ variantObject[checkpoint]['*'] += weight;
98
+ }
99
+ }
100
+ }
101
+ // add global interactionsCount if there's any interaction
102
+ const hasInteraction = Object.values(metrics).some((m) => Object.keys(m).length > 0);
103
+ if (hasInteraction) {
104
+ if (!variantObject.interactionsCount) {
105
+ variantObject.interactionsCount = weight;
106
+ } else {
107
+ variantObject.interactionsCount += weight;
108
+ }
109
+ }
75
110
  }
76
111
  }
77
112
  return experimentInsights;
@@ -0,0 +1,121 @@
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 { isObject } from '@adobe/spacecat-shared-utils';
14
+
15
+ const VARIANT_CHECKPOINT = 'variant';
16
+
17
+ function getOrCreateLanguageObject(languageInsights, language) {
18
+ let languageObject = languageInsights.find((l) => l.language === language);
19
+
20
+ if (isObject(languageObject)) {
21
+ return languageObject;
22
+ }
23
+
24
+ languageObject = {
25
+ language,
26
+ count: 0,
27
+ mismatches: {
28
+ type1: { preferredLanguages: {} }, // Type 1 mismatches
29
+ type2: { preferredLanguages: {} }, // Type 2 mismatches
30
+ type3: { preferredLanguages: {} }, // Type 3 mismatches
31
+ },
32
+ regions: {}, // Tracks the count of events for each region
33
+ };
34
+
35
+ languageInsights.push(languageObject);
36
+ return languageObject;
37
+ }
38
+
39
+ function handler(bundles) {
40
+ const languageInsights = [];
41
+
42
+ for (const bundle of bundles) {
43
+ let preferredLanguages = [];
44
+ let pageLanguage = null;
45
+ let userRegion = null;
46
+
47
+ for (const event of bundle.events) {
48
+ if (event.checkpoint === VARIANT_CHECKPOINT) {
49
+ const { target, source } = event;
50
+
51
+ if (source === 'preferred-languages') {
52
+ preferredLanguages = target.split(',').map((lang) => lang.trim());
53
+ } else if (source === 'page-language') {
54
+ pageLanguage = target;
55
+ } else if (source === 'user-region') {
56
+ userRegion = target;
57
+ }
58
+ }
59
+ }
60
+
61
+ if (pageLanguage) {
62
+ const languageObject = getOrCreateLanguageObject(languageInsights, pageLanguage);
63
+ languageObject.count += 1; // Increment the total count for this page language
64
+
65
+ // Type 1 Mismatch: List out each mismatch if the preferred language list
66
+ // does not contain the page language
67
+ const isType1Mismatch = !preferredLanguages.includes(pageLanguage);
68
+ if (isType1Mismatch) {
69
+ preferredLanguages.forEach((preferredLanguage) => {
70
+ if (!languageObject.mismatches.type1.preferredLanguages[preferredLanguage]) {
71
+ languageObject.mismatches.type1.preferredLanguages[preferredLanguage] = 1;
72
+ } else {
73
+ languageObject.mismatches.type1.preferredLanguages[preferredLanguage] += 1;
74
+ }
75
+ });
76
+ }
77
+
78
+ // Type 2 Mismatch: Count as one mismatch if any preferred language
79
+ // is different from page language
80
+ const isType2Mismatch = preferredLanguages.some(
81
+ (preferredLanguage) => preferredLanguage !== pageLanguage,
82
+ );
83
+ if (isType2Mismatch) {
84
+ const preferredLanguage = preferredLanguages.join(',');
85
+ if (!languageObject.mismatches.type2.preferredLanguages[preferredLanguage]) {
86
+ languageObject.mismatches.type2.preferredLanguages[preferredLanguage] = 1;
87
+ } else {
88
+ languageObject.mismatches.type2.preferredLanguages[preferredLanguage] += 1;
89
+ }
90
+ }
91
+
92
+ // Type 3 Mismatch: Compare each language in preferred language list to page language,
93
+ // and count each mismatch
94
+ preferredLanguages.forEach((preferredLanguage) => {
95
+ if (preferredLanguage !== pageLanguage) {
96
+ if (!languageObject.mismatches.type3.preferredLanguages[preferredLanguage]) {
97
+ languageObject.mismatches.type3.preferredLanguages[preferredLanguage] = 1;
98
+ } else {
99
+ languageObject.mismatches.type3.preferredLanguages[preferredLanguage] += 1;
100
+ }
101
+ }
102
+ });
103
+
104
+ // Track regions
105
+ if (userRegion) {
106
+ if (!languageObject.regions[userRegion]) {
107
+ languageObject.regions[userRegion] = 1;
108
+ } else {
109
+ languageObject.regions[userRegion] += 1;
110
+ }
111
+ }
112
+ }
113
+ }
114
+
115
+ return languageInsights;
116
+ }
117
+
118
+ export default {
119
+ handler,
120
+ checkpoints: VARIANT_CHECKPOINT,
121
+ };
package/src/index.js CHANGED
@@ -13,11 +13,13 @@ import { fetchBundles } from './common/rum-bundler-client.js';
13
13
  import notfound from './functions/404.js';
14
14
  import cwv from './functions/cwv.js';
15
15
  import experiment from './functions/experiment.js';
16
+ import variant from './functions/variant.js';
16
17
 
17
18
  const HANDLERS = {
18
19
  404: notfound,
19
20
  cwv,
20
21
  experiment,
22
+ variant,
21
23
  };
22
24
 
23
25
  export default class RUMAPIClient {