@adobe/spacecat-shared-rum-api-client 2.0.3 → 2.1.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 +7 -0
- package/README.md +58 -0
- package/package.json +3 -3
- package/src/functions/experiment.js +83 -0
- package/src/index.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-rum-api-client-v2.1.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.0.3...@adobe/spacecat-shared-rum-api-client-v2.1.0) (2024-06-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* adding experiment function for rum bundler APIs ([#264](https://github.com/adobe/spacecat-shared/issues/264)) ([b1a076d](https://github.com/adobe/spacecat-shared/commit/b1a076d0044fe4364951accf5d2aa1a5ae315b7b))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-rum-api-client-v2.0.3](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.0.2...@adobe/spacecat-shared-rum-api-client-v2.0.3) (2024-06-11)
|
|
2
9
|
|
|
3
10
|
|
package/README.md
CHANGED
|
@@ -133,6 +133,64 @@ An example response:
|
|
|
133
133
|
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
+
### experiment
|
|
137
|
+
|
|
138
|
+
Lists all the experiments for a specified domain within the requested interval. The results are grouped by URL. The output includes all the URLs running the experiment, along with experiment id, variants, number of clicks/convert/formsubmit events per variant/selector and views for each of the variant in the experiment.
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
An example response:
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"https://www.aem.live/home": [
|
|
146
|
+
{
|
|
147
|
+
"experiment": "short-home",
|
|
148
|
+
"variants": [
|
|
149
|
+
{
|
|
150
|
+
"name": "challenger-1",
|
|
151
|
+
"views": 1300,
|
|
152
|
+
"click": {
|
|
153
|
+
".hero": 100,
|
|
154
|
+
".header #navmenu-0": 100,
|
|
155
|
+
".roi-calculator .button": 100,
|
|
156
|
+
".hero .button": 100
|
|
157
|
+
},
|
|
158
|
+
"convert": {},
|
|
159
|
+
"formsubmit": {}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"name": "control",
|
|
163
|
+
"views": 800,
|
|
164
|
+
"click": {
|
|
165
|
+
".hero .button": 100,
|
|
166
|
+
".header .button": 200,
|
|
167
|
+
".header #navmenu-0": 200
|
|
168
|
+
},
|
|
169
|
+
"convert": {},
|
|
170
|
+
"formsubmit": {}
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
],
|
|
175
|
+
|
|
176
|
+
"https://www.aem.live/new-exp-page": [
|
|
177
|
+
{
|
|
178
|
+
"experiment": "visitor-behavior",
|
|
179
|
+
"variants": [
|
|
180
|
+
{
|
|
181
|
+
"name": "https://www.aem.live/some-other-page",
|
|
182
|
+
"views": 500,
|
|
183
|
+
"click": {},
|
|
184
|
+
"convert": {},
|
|
185
|
+
"formsubmit": {}
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
|
|
136
194
|
## Linting
|
|
137
195
|
Lint the codebase using:
|
|
138
196
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-rum-api-client",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - Rum API client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"chai": "4.4.1",
|
|
43
|
-
"chai-as-promised": "
|
|
43
|
+
"chai-as-promised": "8.0.0",
|
|
44
44
|
"nock": "13.5.4",
|
|
45
|
-
"sinon": "
|
|
45
|
+
"sinon": "18.0.0",
|
|
46
46
|
"sinon-chai": "3.7.0",
|
|
47
47
|
"typescript": "5.4.5"
|
|
48
48
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
const EXPERIMENT_CHECKPOINT = ['experiment'];
|
|
14
|
+
const METRIC_CHECKPOINTS = ['click', 'convert', 'formsubmit'];
|
|
15
|
+
const CHECKPOINTS = [...EXPERIMENT_CHECKPOINT, ...METRIC_CHECKPOINTS];
|
|
16
|
+
|
|
17
|
+
function toClassName(name) {
|
|
18
|
+
return typeof name === 'string'
|
|
19
|
+
? name.toLowerCase().replace(/[^0-9a-z]/gi, '-').replace(/-+/g, '-').replace(/^-|-$/g, '')
|
|
20
|
+
: '';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getOrCreateExperimentObject(urlInsights, experimentName) {
|
|
24
|
+
let experimentObject = urlInsights.find((e) => e.experiment === toClassName(experimentName));
|
|
25
|
+
if (!experimentObject) {
|
|
26
|
+
experimentObject = {
|
|
27
|
+
experiment: toClassName(experimentName),
|
|
28
|
+
variants: [],
|
|
29
|
+
};
|
|
30
|
+
urlInsights.push(experimentObject);
|
|
31
|
+
}
|
|
32
|
+
return experimentObject;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getOrCreateVariantObject(variants, variantName) {
|
|
36
|
+
let variantObject = variants.find((v) => v.name === variantName);
|
|
37
|
+
if (!variantObject) {
|
|
38
|
+
variantObject = {
|
|
39
|
+
name: variantName,
|
|
40
|
+
views: 0,
|
|
41
|
+
click: {},
|
|
42
|
+
convert: {},
|
|
43
|
+
formsubmit: {},
|
|
44
|
+
};
|
|
45
|
+
variants.push(variantObject);
|
|
46
|
+
}
|
|
47
|
+
return variantObject;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handler(bundles) {
|
|
51
|
+
const experimentInsights = {};
|
|
52
|
+
for (const bundle of bundles) {
|
|
53
|
+
const experimentEvent = bundle.events.find((e) => e.checkpoint === 'experiment');
|
|
54
|
+
if (experimentEvent) {
|
|
55
|
+
const { url, weight } = bundle;
|
|
56
|
+
if (!experimentInsights[url]) {
|
|
57
|
+
experimentInsights[url] = [];
|
|
58
|
+
}
|
|
59
|
+
const experimentName = experimentEvent.source;
|
|
60
|
+
const variantName = experimentEvent.target;
|
|
61
|
+
const experimentObject = getOrCreateExperimentObject(experimentInsights[url], experimentName);
|
|
62
|
+
const variantObject = getOrCreateVariantObject(experimentObject.variants, variantName);
|
|
63
|
+
variantObject.views += weight;
|
|
64
|
+
|
|
65
|
+
for (const event of bundle.events) {
|
|
66
|
+
if (METRIC_CHECKPOINTS.includes(event.checkpoint)) {
|
|
67
|
+
const { source, checkpoint } = event;
|
|
68
|
+
if (!variantObject[checkpoint][source]) {
|
|
69
|
+
variantObject[checkpoint][source] = weight;
|
|
70
|
+
} else {
|
|
71
|
+
variantObject[checkpoint][source] += weight;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return experimentInsights;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export default {
|
|
81
|
+
handler,
|
|
82
|
+
checkpoints: CHECKPOINTS,
|
|
83
|
+
};
|
package/src/index.js
CHANGED
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
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
|
+
import experiment from './functions/experiment.js';
|
|
15
16
|
|
|
16
17
|
const HANDLERS = {
|
|
17
18
|
404: notfound,
|
|
18
19
|
cwv,
|
|
20
|
+
experiment,
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
export default class RUMAPIClient {
|