Skip to content

Commit

Permalink
feat(series): redefine page views so that prerenders (that never are …
Browse files Browse the repository at this point in the history
…turned into navigation events) are no longer counted
  • Loading branch information
trieloff committed Oct 15, 2024
1 parent a39b930 commit 2e54f16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion series.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ import { reclassifyAcquisition } from './utils.js';
* @param {Bundle} bundle a series of events that belong to the same page view
* @returns {number} the number of page views
*/
export const pageViews = (bundle) => bundle.weight;
export const pageViews = (bundle) => {
const isBundle = true;
const isPrerender = bundle.events.find((evt) =>
evt.checkpoint === 'prerender'
);
const isPrerenderThenNavigate = bundle.events.find((evt) =>
evt.checkpoint === 'navigate'
&& evt.target === 'prerender');
return isBundle && (!isPrerender || isPrerenderThenNavigate) ? bundle.weight : 0;
};

/**
* A visit is a page view that does not follow an internal link. This means a visit starts
Expand Down
5 changes: 4 additions & 1 deletion test/series.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {

describe('series:pageViews', () => {
it('pageViews:bare', () => {
assert.equal(pageViews({ weight: 1 }), 1);
assert.equal(pageViews({ weight: 1, events: [] }), 1);
assert.equal(pageViews({ weight: 1, events: [{ checkpoint: 'prerender' }] }), 0);
assert.equal(pageViews({ weight: 1, events: [{ checkpoint: 'navigate', target: 'prerender' }] }), 1);
assert.equal(pageViews({ weight: 1, events: [{ checkpoint: 'prerender' }, { checkpoint: 'navigate', target: 'prerender' }] }), 1);
});

it('pageViews:DataChunks', () => {
Expand Down

0 comments on commit 2e54f16

Please sign in to comment.