@adobe/spacecat-shared-rum-api-client 2.4.0 → 2.5.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,10 @@
1
+ # [@adobe/spacecat-shared-rum-api-client-v2.5.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.4.0...@adobe/spacecat-shared-rum-api-client-v2.5.0) (2024-07-23)
2
+
3
+
4
+ ### Features
5
+
6
+ * Experimentation entity ([#288](https://github.com/adobe/spacecat-shared/issues/288)) ([774e2c7](https://github.com/adobe/spacecat-shared/commit/774e2c7013c9e617c745c494e20e1cdd8cce71e7))
7
+
1
8
  # [@adobe/spacecat-shared-rum-api-client-v2.4.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-rum-api-client-v2.3.0...@adobe/spacecat-shared-rum-api-client-v2.4.0) (2024-07-19)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-rum-api-client",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Shared modules of the Spacecat Services - Rum API client",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -47,12 +47,49 @@ function getOrCreateVariantObject(variants, variantName) {
47
47
  return variantObject;
48
48
  }
49
49
 
50
+ function updateInferredStartAndEndDate(experimentObject, time) {
51
+ const bundleTime = new Date(time);
52
+ const yesterday = new Date();
53
+ yesterday.setDate(yesterday.getDate() - 1);
54
+ yesterday.setHours(0, 0, 0, 0);
55
+ const bundleDate = new Date(bundleTime);
56
+ bundleDate.setHours(0, 0, 0, 0);
57
+ if (!experimentObject.inferredStartDate && !experimentObject.inferredEndDate) {
58
+ // adding the inferredStartDate and inferredEndDate properties for the first time
59
+ // eslint-disable-next-line no-param-reassign
60
+ experimentObject.inferredStartDate = time;
61
+ // check if bundleTime is before yesterday
62
+ if (bundleDate < yesterday) {
63
+ // RUM data is delayed by a day, so if we don't have
64
+ // any RUM data for yesterday, so we can infer the endDate
65
+ // eslint-disable-next-line no-param-reassign
66
+ experimentObject.inferredEndDate = time;
67
+ } else {
68
+ // eslint-disable-next-line no-param-reassign
69
+ experimentObject.inferredEndDate = null;
70
+ }
71
+ } else {
72
+ const inferredStartDateObj = new Date(experimentObject.inferredStartDate);
73
+ if (bundleTime < inferredStartDateObj) {
74
+ // eslint-disable-next-line no-param-reassign
75
+ experimentObject.inferredStartDate = time;
76
+ }
77
+ if (bundleDate < yesterday) {
78
+ if (!experimentObject.inferredEndDate
79
+ || (bundleTime > new Date(experimentObject.inferredEndDate))) {
80
+ // eslint-disable-next-line no-param-reassign
81
+ experimentObject.inferredEndDate = time;
82
+ }
83
+ }
84
+ }
85
+ }
86
+
50
87
  function handler(bundles) {
51
88
  const experimentInsights = {};
52
89
  for (const bundle of bundles) {
53
- const experimentEvent = bundle.events.find((e) => e.checkpoint === 'experiment');
90
+ const experimentEvent = bundle.events?.find((e) => e.checkpoint === 'experiment');
54
91
  if (experimentEvent) {
55
- const { url, weight } = bundle;
92
+ const { url, weight, time } = bundle;
56
93
  if (!experimentInsights[url]) {
57
94
  experimentInsights[url] = [];
58
95
  }
@@ -60,6 +97,7 @@ function handler(bundles) {
60
97
  const variantName = experimentEvent.target;
61
98
  const experimentObject = getOrCreateExperimentObject(experimentInsights[url], experimentName);
62
99
  const variantObject = getOrCreateVariantObject(experimentObject.variants, variantName);
100
+ updateInferredStartAndEndDate(experimentObject, time);
63
101
  variantObject.views += weight;
64
102
 
65
103
  const metrics = {};