From f9b21d6e53398530c9d4969ebaba114e49157133 Mon Sep 17 00:00:00 2001 From: rublea Date: Fri, 20 Dec 2024 12:47:47 +0200 Subject: [PATCH] fix: add totalClicks --- .../src/functions/total-metrics.js | 7 ++++--- .../test/total-metrics.test.js | 1 + 2 files changed, 5 insertions(+), 3 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 04428313..7f3ab52a 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 @@ -17,16 +17,17 @@ function handler(bundles) { const dataChunks = new DataChunks(); loadBundles(bundles, dataChunks); dataChunks.addSeries('traffic_domain', series.pageViews); - dataChunks.addSeries('ctr', (bundle) => (bundle.events.some((e) => e.checkpoint === 'click') + dataChunks.addSeries('clicks', (bundle) => (bundle.events.some((e) => e.checkpoint === 'click') ? bundle.weight : 0)); const totalPageViews = dataChunks?.totals?.traffic_domain?.weight; - const sum = dataChunks?.totals?.ctr?.sum ?? 0; - const weight = dataChunks?.totals?.ctr?.weight ?? 0; + const sum = dataChunks?.totals?.clicks?.sum ?? 0; + const weight = dataChunks?.totals?.clicks?.weight ?? 0; const totalCTR = weight !== 0 ? sum / weight : 0; return { totalPageViews, totalCTR, + totalClicks: sum, }; } 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 35e69e38..631a0bec 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 @@ -19,6 +19,7 @@ describe('Total Metrics Queries', () => { const result = totalMetrics.handler(bundlesForUrls.rumBundles); expect(result).to.deep.equal({ totalCTR: 0.2027468663384768, + totalClicks: 4901, totalPageViews: 24173, }); });