diff --git a/audit.js b/audit.js index a1aafb6..df182f8 100644 --- a/audit.js +++ b/audit.js @@ -20,9 +20,21 @@ async function run() { // 1. per-view formats: campaign.imps must equal the rows in the log that paid for them for (const [type, table, label] of [['video', 'video_seen', 'completed watches'], ['visits', 'visit_seen', 'verified visits'], ['solo', 'solo_inbox', 'inbox deliveries']]) { const rows = await db.q('SELECT campaign_id, COUNT(*) n FROM ' + table + ' GROUP BY campaign_id'); const logN = {}; for (const r of rows) logN[r.campaign_id] = Number(r.n); - const issues = []; let tot = 0, logTot = 0; - for (const c of byType(type)) { const l = logN[c.id] || 0; tot += Number(c.imps); logTot += l; if (Number(c.imps) !== l) issues.push('#' + c.id + ' ' + c.name.slice(0, 30) + ': ' + c.imps + ' views vs ' + l + ' ' + label); } - add(type + ' views vs ' + label, issues, tot + ' views recorded, ' + logTot + ' ' + label); + // visits are proven by three logs (2026-10-04: 37 false alarms): our viewer (visit_seen), repeat door knocks on Spooky Doors + // (visit_repeat), and visits delivered on PassiveDrip's PTC page (pdsync.json, read from PassiveDrip, never derived). + // A counter BELOW its proof is the advertiser getting a visit free; only a counter ABOVE its proof can overcharge them. + let extra = {}; + if (type === 'visits') { + for (const r of await db.q('SELECT campaign_id, COUNT(*) n FROM visit_repeat GROUP BY campaign_id')) extra[r.campaign_id] = (extra[r.campaign_id] || 0) + Number(r.n); + try { const pd = JSON.parse(fs.readFileSync(path.join(R.dataDir, 'pdsync.json'), 'utf8')).served || {}; for (const [id, n] of Object.entries(pd)) extra[id] = (extra[id] || 0) + Number(n || 0); } catch (e) {} + } + const issues = []; let tot = 0, logTot = 0, under = 0; + for (const c of byType(type)) { + const l = (logN[c.id] || 0) + (extra[c.id] || 0); tot += Number(c.imps); logTot += l; + if (type === 'visits') { if (Number(c.imps) > l) issues.push('#' + c.id + ' ' + c.name.slice(0, 30) + ': ' + c.imps + ' counted vs ' + l + ' proven (' + (Number(c.imps) - l) + ' not proven)'); else if (Number(c.imps) < l) under++; } + else if (Number(c.imps) !== l) issues.push('#' + c.id + ' ' + c.name.slice(0, 30) + ': ' + c.imps + ' views vs ' + l + ' ' + label); + } + add(type + ' views vs ' + label, issues, tot + ' views recorded, ' + logTot + ' ' + label + (type === 'visits' ? ' (our viewer + repeat door visits + PassiveDrip)' + (under ? '; ' + under + ' campaign(s) got a visit or two free' : '') : '')); } // 2. banner/text: imps must equal the hourly log (both bumped on serve) {