Page leads count as conversions again; pixel keeps the event name; cookieless pixel hits stop inflating audiences (Marty approved, 2026-10-22)
B2: the built-in page form posted an empty lsid (pt.js only filled .lsform, the pasted-form class), so page leads never
reached the rotator 'lead' conversion or the postback. The server now fills the hidden lsid at render from ?lsid or the
ls.click cookie, the lead POST falls back to the ls.click cookie when the form sends none, and pt.js fills both .ls-form
and .lsform as a fallback (cache tag pt.js?v=2). Pasted provider forms get no added field: some providers reject unknown
fields, so the lsid only rides along when the member's own form code has an lsid field.
B4: /p.gif now stores the pixel's e= event name (lowercase [a-z0-9_-]{1,32}) in a parallel ev map in audiences.json;
hits stay plain timestamps, so old rows count, match and prune as before. The audiences list shows counts by event
(events for cookie visitors, eventsSoft for 24 h soft keys).
B3: a pixel hit with no ls.vid cookie still offers the cookie but is counted under the 24 h IP + user agent key only,
not a fresh 30-day visitor id, so a cookie-blocking browser counts once.
Test: qa/lsid-pixel.test.mjs (bash qa/run.sh lsid), unit + local end to end on a throwaway data dir.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1195,9 +1195,11 @@ const server = http.createServer(async (req, res) => {
|
||||
}
|
||||
// audience pixel: 1x1 gif, sets/refreshes the visitor cookie, records the hit (30-day membership)
|
||||
if (p === '/p.gif' && req.method === 'GET') {
|
||||
const a = String(u.searchParams.get('a') || ''); let vid = audiences.cookieVid(req); const h = { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store, private', 'Content-Length': String(PIXEL_GIF.length) };
|
||||
if (!vid) { vid = audiences.newVid(); h['Set-Cookie'] = audiences.cookieHeader(vid, IS_PROD); }
|
||||
if (audiences.isId(a)) audiences.hit(a, vid, audiences.softKey(req));
|
||||
const a = String(u.searchParams.get('a') || ''); const vid = audiences.cookieVid(req); const h = { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store, private', 'Content-Length': String(PIXEL_GIF.length) };
|
||||
// no cookie came in: offer one, but count this hit under the soft key only (2026-10-22). A browser that blocks the
|
||||
// cookie would otherwise add a fresh 30-day visitor on every hit and inflate the audience size.
|
||||
if (!vid) h['Set-Cookie'] = audiences.cookieHeader(audiences.newVid(), IS_PROD);
|
||||
if (audiences.isId(a)) audiences.hit(a, vid, audiences.softKey(req), audiences.cleanEvent(u.searchParams.get('e')));
|
||||
res.writeHead(200, h); return res.end(PIXEL_GIF);
|
||||
}
|
||||
if (p === '/p.js') { try { const body = fs.readFileSync(path.join(PUBLIC_DIR, 'p.js')); res.writeHead(200, { 'Content-Type': 'application/javascript; charset=utf-8', 'Cache-Control': 'public, max-age=300' }); return res.end(body); } catch (e) { res.writeHead(404); return res.end(); } }
|
||||
@@ -1250,12 +1252,16 @@ const server = http.createServer(async (req, res) => {
|
||||
const hdr = { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'strict-origin-when-cross-origin',
|
||||
'Content-Security-Policy': "default-src 'none'; script-src 'self'; style-src 'unsafe-inline'; img-src 'self' https: data:; form-action https: http:; base-uri 'none'; frame-ancestors *; connect-src 'self'" };
|
||||
if (/^[a-z0-9]{6,20}$/i.test(lsid)) hdr['Set-Cookie'] = 'ls.click=' + lsid + '; Path=/; SameSite=Lax; Max-Age=2592000' + (IS_PROD ? '; Secure' : '');
|
||||
res.writeHead(200, hdr); return res.end(pages.html(pg, { leadUrl: '/p/' + pg.slug + '/lead', trackSrc: '/assets/pt.js', footerLink: 'https://' + SITE_HOST + '/', footerText: 'Made with LinkSpin', pixel: 'https://' + SITE_HOST + '/p.gif?a=' + audiences.defaultFor(pg.owner) + '&e=page' }));
|
||||
// the visitor's click id goes into the built-in form at render (2026-10-22): from ?lsid, else the ls.click cookie a
|
||||
// spin-link visit left earlier, so a lead counts as the rotator's 'lead' conversion even when the script never runs
|
||||
const formLsid = /^[a-z0-9]{6,20}$/i.test(lsid) ? lsid : (/^[a-z0-9]{6,20}$/i.test(String(parseCookies(req)['ls.click'] || '')) ? parseCookies(req)['ls.click'] : '');
|
||||
res.writeHead(200, hdr); return res.end(pages.html(pg, { leadUrl: '/p/' + pg.slug + '/lead', lsid: formLsid, trackSrc: '/assets/pt.js?v=2', footerLink: 'https://' + SITE_HOST + '/', footerText: 'Made with LinkSpin', pixel: 'https://' + SITE_HOST + '/p.gif?a=' + audiences.defaultFor(pg.owner) + '&e=page' }));
|
||||
}
|
||||
pm = /^\/p\/([a-z0-9-]{3,60})\/lead$/i.exec(p);
|
||||
if (pm && req.method === 'POST') {
|
||||
const raw = await new Promise(r => { let d = ''; req.on('data', c => { d += c; if (d.length > 20000) req.destroy(); }); req.on('end', () => r(d)); });
|
||||
const b = {}; try { const ct = String(req.headers['content-type'] || ''); if (/json/.test(ct)) Object.assign(b, JSON.parse(raw)); else for (const [k, v] of new URLSearchParams(raw)) b[k] = v; } catch (e) {}
|
||||
if (!/^[a-z0-9]{6,20}$/i.test(String(b.lsid || ''))) { const lc = String(parseCookies(req)['ls.click'] || ''); if (/^[a-z0-9]{6,20}$/i.test(lc)) b.lsid = lc; } // form posted no click id: the cookie from the page visit
|
||||
const r = await pages.lead(pm[1], b, req);
|
||||
if (r.error) { res.writeHead(400, { 'Content-Type': 'text/html; charset=utf-8' }); return res.end('<!doctype html><title>Try again</title><p style="font-family:system-ui;padding:40px">' + r.error + ' <a href="javascript:history.back()">Go back</a></p>'); }
|
||||
if (r.owner && r.lsid) { try { postbacks.bindClick(String(b.email || '').toLowerCase(), r.lsid); const hit = await rotator.convert(r.lsid, 'lead', {}); if (hit) postbacks.fire(hit.owner, 'lead', Object.assign({ q: hit.q || {}, source: hit.s, country: hit.c, device: hit.dv, lsid: r.lsid, code: hit.code, sourceId: hit.sourceId || '' })).catch(() => {}); } catch (e) {} }
|
||||
|
||||
Reference in New Issue
Block a user