Skip to content

Commit

Permalink
fix: add totalClicks
Browse files Browse the repository at this point in the history
  • Loading branch information
alinarublea committed Dec 20, 2024
1 parent d863949 commit f9b21d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
Expand Down

0 comments on commit f9b21d6

Please sign in to comment.