From c27d9efe91e20072e0cde42e647e11403b61fdea Mon Sep 17 00:00:00 2001 From: rublea Date: Fri, 20 Dec 2024 12:12:19 +0200 Subject: [PATCH] fix: new rum checkpoint --- .../src/functions/total-metrics.js | 4 +++- .../spacecat-shared-rum-api-client/test/total-metrics.test.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/spacecat-shared-rum-api-client/src/functions/total-metrics.js b/packages/spacecat-shared-rum-api-client/src/functions/total-metrics.js index 0a932c15..04428313 100644 --- a/packages/spacecat-shared-rum-api-client/src/functions/total-metrics.js +++ b/packages/spacecat-shared-rum-api-client/src/functions/total-metrics.js @@ -21,7 +21,9 @@ function handler(bundles) { ? bundle.weight : 0)); const totalPageViews = dataChunks?.totals?.traffic_domain?.weight; - const totalCTR = dataChunks?.totals?.ctr?.sum / dataChunks?.totals?.ctr?.weight; + const sum = dataChunks?.totals?.ctr?.sum ?? 0; + const weight = dataChunks?.totals?.ctr?.weight ?? 0; + const totalCTR = weight !== 0 ? sum / weight : 0; return { totalPageViews, totalCTR, diff --git a/packages/spacecat-shared-rum-api-client/test/total-metrics.test.js b/packages/spacecat-shared-rum-api-client/test/total-metrics.test.js index 30857b8a..35e69e38 100644 --- a/packages/spacecat-shared-rum-api-client/test/total-metrics.test.js +++ b/packages/spacecat-shared-rum-api-client/test/total-metrics.test.js @@ -18,7 +18,7 @@ describe('Total Metrics Queries', () => { it('crunches CWV data', async () => { const result = totalMetrics.handler(bundlesForUrls.rumBundles); expect(result).to.deep.equal({ - totalCTR: 7303, + totalCTR: 0.2027468663384768, totalPageViews: 24173, }); });