diff --git a/ads.js b/ads.js index 4799996..c7332c9 100644 Binary files a/ads.js and b/ads.js differ diff --git a/bannerspin.js b/bannerspin.js index cbfe381..6e3fd38 100644 --- a/bannerspin.js +++ b/bannerspin.js @@ -51,7 +51,7 @@ const TIERS = { }; const ORDER = ['starter', 'builder', 'leader']; const MAX_BYTES = 150 * 1024, MAX_BANNERS = 25; -const NOTE_TTL = 15 * 60000, DEDUPE_MS = 60000, FLUSH_MS = 5000, UNIQ_CAP = 500, HOSTS_CAP = 200; +const NOTE_TTL = 60 * 60000, DEDUPE_MS = 60000, FLUSH_MS = 5000, UNIQ_CAP = 500, HOSTS_CAP = 200; const BOT = /bot|crawl|spider|slurp|facebookexternalhit|preview|telegrambot|whatsapp|curl|wget|python-requests|headless/i; const norm = e => String(e || '').trim().toLowerCase(); const CT_FMT = new Intl.DateTimeFormat('en-CA', { timeZone: 'America/Chicago', year: 'numeric', month: '2-digit', day: '2-digit' }); @@ -92,6 +92,12 @@ const ipOf = req => String(req.headers['x-forwarded-for'] || (req.socket && req. const vkey = (req, ts) => crypto.createHash('sha256').update(new Date(ts || Date.now()).toISOString().slice(0, 10) + '|' + ipOf(req) + '|' + String(req.headers['user-agent'] || '')).digest('hex').slice(0, 16); // keys to try for a click: today's, and yesterday's for the first 15 minutes after UTC midnight (a note made at 23:59 still matches) function vkeys(req) { const now = Date.now(); const k = [vkey(req, now)]; if (now % DAY < NOTE_TTL) k.push(vkey(req, now - DAY)); return k; } +// Second chance for a click (Michael Camire 2026-11-14: 3 clicks on his Banner Spin, every one unmatched, so no banner got +// credit): the same daily-salted hash WITHOUT the browser. A mail app or a traffic-exchange app shows the image in its own +// viewer and opens the click in the phone's or PC's browser: same IP, different user agent, so the full key never matches. +// Only used when the full key finds nothing; the most recent view of this Banner Spin from that IP wins. +const ipkey = (req, ts) => 'i' + crypto.createHash('sha256').update(new Date(ts || Date.now()).toISOString().slice(0, 10) + '|ip|' + ipOf(req)).digest('hex').slice(0, 15); +function ipkeys(req) { if (!ipOf(req)) return []; const now = Date.now(); const k = [ipkey(req, now)]; if (now % DAY < NOTE_TTL) k.push(ipkey(req, now - DAY)); return k; } const isBot = req => { const ua = String(req.headers['user-agent'] || ''); return !ua || BOT.test(ua); }; const isPrefetch = req => /prefetch|prerender|preview/i.test([req.headers.purpose, req.headers['sec-purpose'], req.headers['x-purpose'], req.headers['x-moz']].filter(Boolean).join(' ')); // a server fetching the image, not a browser (phase 3, 2026-10-20): mail image proxies and plain HTTP libraries. Kept out of @@ -279,7 +285,7 @@ function choose(s, req, opts) { const kind = loaderKind(req); rawLoad(String(s.id), hostOf(req), v, kind); if (!kind) { const bid = b ? b.id : 0; const host = hostOf(req); - note(v, s.id, host, bid); + note(v, s.id, host, bid); if (ipOf(req)) note(ipkey(req), s.id, host, bid); const k = v + '|' + s.id + '|' + bid; const last = SEEN.get(k); if (!last || Date.now() - last >= DEDUPE_MS) { SEEN.set(k, Date.now()); bump(String(s.id), bid, host, v); } } @@ -313,7 +319,7 @@ async function click(code, req, reqHost) { let b = null, m = 'none'; if (!live() || s.adminOff) m = 'off'; else if (xs != null && /^\d{1,4}$/.test(xs)) { b = Number(xs) ? s.banners.find(q => q.id === Number(xs) && !q.adminOff) || null : null; m = 'exact'; } - else { const n = findNote(keys, s.id, h); if (n) { b = n.b ? s.banners.find(q => q.id === n.b && !q.adminOff) || null : null; m = 'note'; } } + else { let n = findNote(keys, s.id, h), how = 'note'; if (!n) { n = findNote(ipkeys(req), s.id, h); how = 'ip'; } if (n) { b = n.b ? s.banners.find(q => q.id === n.b && !q.adminOff) || null : null; m = how; } } // where to: the banner's target (its spin link, on the same link domain), else the fallback let url = null; if (b) { if (b.link) { const r = rotator && rotator.rawRotations ? rotator.rawRotations().find(x => x.id === b.link && x.owner === s.owner) : null; url = r ? 'https://' + (reqHost || 'linkspin.app') + '/r/' + r.code : null; } else url = b.target; } @@ -383,7 +389,7 @@ function agg(spins, sinceTs) { if (!ids.has(c.s) || (sinceTs && c.ts < sinceTs)) continue; const dd = at(days, ctDay(c.ts)); if (c.bot) { T.botClicks++; dd.botClicks++; continue; } - const ok = c.m === 'exact' || c.m === 'note'; + const ok = c.m === 'exact' || c.m === 'note' || c.m === 'ip'; for (const o of [at(per, c.s + ':' + c.b), at(hosts, c.h || '(none)'), dd, T]) { o.clicks++; if (ok) o.matched++; else if (c.m === 'none') o.unmatched++; } const k = c.c || '(none)'; country[k] = (country[k] || 0) + 1; const dv = c.dv || '(none)'; device[dv] = (device[dv] || 0) + 1; } @@ -419,7 +425,9 @@ async function stats(owner, id) { const win = winnerOf(banners.filter(b => b.active)); for (const b of banners) b.winner = b.id === win; const fb = A.per[s.id + ':0'] || z; return { spin: pub(s), totals: { imps: A.T.imps, clicks: A.T.clicks, ctr: ctrOf(A.T), matchRate: mrOf(A.T), matched: A.T.matched, unmatched: A.T.unmatched, uniquesSampled: A.T.uniq, conversions: A.T.conv, bots: A.T.botClicks, botLoads: A.T.bots, serverLoads: A.T.srv }, - banners, winner: win, winMin: WIN_MIN, fallback: { imps: fb.imps, clicks: fb.clicks, ctr: ctrOf(fb) }, + // fallback = the fallback was SHOWN (views + the clicks matched to those views); unmatched = clicks we could not tie to any view, + // listed on their own row so the banner rows + these two add up to the Banner Spin's totals + banners, winner: win, winMin: WIN_MIN, fallback: { imps: fb.imps, clicks: fb.clicks - fb.unmatched, ctr: ctrOf({ imps: fb.imps, clicks: fb.clicks - fb.unmatched }) }, unmatched: { clicks: fb.unmatched }, placements: placementRows(A.hosts), days: dayRows(A.days, ctDay(Date.now() - 30 * DAY)), country: listOf(A.country), device: listOf(A.device), conversions: Object.entries(A.convBy).sort((a, b) => b[1] - a[1]).map(([k, n]) => ({ k, n })) }; } diff --git a/public/admin.html b/public/admin.html index d7fe09b..f100e83 100644 --- a/public/admin.html +++ b/public/admin.html @@ -7,7 +7,7 @@ - + diff --git a/public/ads.html b/public/ads.html index 5bc9065..21342ca 100644 --- a/public/ads.html +++ b/public/ads.html @@ -7,7 +7,7 @@