Count invalid clicks by recorded path #58
No files matched your search
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@goto/worker': patch
|
||||
---
|
||||
|
||||
Count new invalid clicks by their recorded path so they show up in Link and Tag Analytics. Link caps still count only valid visits.
|
||||
@@ -83,6 +83,23 @@ async function readTotals(db: WorkerContext['db'], scope: ReportScope): Promise<
|
||||
);
|
||||
}
|
||||
|
||||
test('expires invalid clicks from their path report without adding to lifetime link hits', async () => {
|
||||
const ctx = await context();
|
||||
try {
|
||||
const cutoff = Date.parse(period.from);
|
||||
const invalidVisit = { ...visit, outcome: 'invalid' as const };
|
||||
await insertVisit(ctx.db, { ...invalidVisit, visited_at: cutoff - 1 });
|
||||
await insertVisit(ctx.db, { ...invalidVisit, visited_at: cutoff });
|
||||
|
||||
await maintainVisits(ctx, reportNow);
|
||||
|
||||
expect(await readTotals(ctx.db, docs)).toEqual({ validVisits: 0, invalidVisits: 1 });
|
||||
expect(await readVisitTotals(ctx.db, docs)).toEqual({ validVisits: 0, invalidVisits: 0 });
|
||||
} finally {
|
||||
await ctx.db.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
test('accounts visits once across a batch boundary and keeps the cutoff-day survivor', async () => {
|
||||
const ctx = await context();
|
||||
try {
|
||||
|
||||
@@ -90,7 +90,7 @@ test('actual events create scope/day rows with Root normalization, independent f
|
||||
]);
|
||||
expect(await readTotals(overview)).toEqual({ validVisits: 2, invalidVisits: 2 });
|
||||
expect(await readTotals(domainScope)).toEqual({ validVisits: 2, invalidVisits: 2 });
|
||||
expect(await readTotals(docs)).toEqual({ validVisits: 1, invalidVisits: 0 });
|
||||
expect(await readTotals(docs)).toEqual({ validVisits: 1, invalidVisits: 1 });
|
||||
expect(await readTotals(root)).toEqual({ validVisits: 1, invalidVisits: 0 });
|
||||
expect(await readVisitDetails(db, domainScope, period)).toMatchObject({
|
||||
version: 5,
|
||||
@@ -110,7 +110,7 @@ test('actual events create scope/day rows with Root normalization, independent f
|
||||
]
|
||||
});
|
||||
const rows = await db.selectFrom('visit_daily_statistics').selectAll().execute();
|
||||
expect(rows).toHaveLength(4);
|
||||
expect(rows).toHaveLength(5);
|
||||
expect(rows.find(({ scope_kind }) => scope_kind === 'overview')).toMatchObject({
|
||||
day: '2026-04-01',
|
||||
last_visit_at: visit.visited_at,
|
||||
@@ -118,9 +118,10 @@ test('actual events create scope/day rows with Root normalization, independent f
|
||||
invalid_visits: 2
|
||||
});
|
||||
expect(JSON.parse(rows[0]!.browsers_json)[0]).not.toHaveProperty('day');
|
||||
expect(await readTotals({ kind: 'link', domain, path: '/unconfigured' })).toEqual(
|
||||
zeroVisitTotals()
|
||||
);
|
||||
expect(await readTotals({ kind: 'link', domain, path: '/unconfigured' })).toEqual({
|
||||
validVisits: 0,
|
||||
invalidVisits: 1
|
||||
});
|
||||
});
|
||||
|
||||
test('batches read no raw history, update only affected days and leave quiet data byte-identical without clock writes', async () => {
|
||||
|
||||
@@ -60,10 +60,11 @@ export async function warnIfDailyStatisticsMissing(db: WorkerContext['db']): Pro
|
||||
function groupDailyStatistics(visits: VisitFacts[]): DailyVisitStatistics[] {
|
||||
const days = new Map<string, DailyAccumulator>();
|
||||
for (const visit of visits) {
|
||||
const scopes: ReportScope[] = [{ kind: 'overview' }, { kind: 'domain', domain: visit.domain }];
|
||||
if (visit.outcome === 'valid') {
|
||||
scopes.push({ kind: 'link', domain: visit.domain, path: visit.path });
|
||||
}
|
||||
const scopes: ReportScope[] = [
|
||||
{ kind: 'overview' },
|
||||
{ kind: 'domain', domain: visit.domain },
|
||||
{ kind: 'link', domain: visit.domain, path: visit.path }
|
||||
];
|
||||
for (const scope of scopes) {
|
||||
const key = JSON.stringify([scope, visit.day]);
|
||||
let day = days.get(key);
|
||||
|
||||
Reference in new issue
Block a user