Skip to content

Commit

Permalink
fix: add totalClicks
Browse files Browse the repository at this point in the history
Please ensure your pull request adheres to the following guidelines:
- [ ] make sure to link the related issues in this description
- [ ] when merging / squashing, make sure the fixed issue references are
visible in the commits, for easy compilation of release notes

## Related Issues


Thanks for contributing!
  • Loading branch information
alinarublea authored Dec 20, 2024
1 parent d863949 commit df9a688
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 df9a688

Please sign in to comment.