Conversion tracking fixes (Marty approved 2026-10-26): real test pixel, own-click count, own-browser clicks as tests, cost per goal (30 days)
1. Own clicks: auth.onSeen notes the soft key of every InstantAdPay session (lsconv.noteSession, once per 6 h per email + soft key) and the click push carries them as owners [{owner, sk, ts}] (requeued on a failed push), so LinkSpin keeps members' own clicks on their ads, spin links and Banner Spins as tests. /api/ads/click flags a click self for conversions when signed in as the owner OR from a browser the owner signs in from; whether the click is counted and billed is unchanged (still the signed-in check). Linked positions share the owner's email.
2. Send a test conversion now loads the member's real LinkSpin pixel in test mode from the browser (cv.gif?px=..&test=1, reads X-LS-Result: test, the same request LinkSpin's button makes) and falls back to the signed partner call (op test) when the browser cannot load it; CSP connect-src adds https://linkspin.app. The card shows "N from your own clicks, kept as tests and left out" (selfTests from LinkSpin's summary).
4. Cost per goal (30 days): /api/my/conversions returns spend30 = each campaign's spend over the same 30 days from credit_log (ads.spendSince: delivery, login, buy, refund rows by Central day, ref = campaign id). Campaign lines read "Goals and cost per goal (30 days)"; a campaign started inside the window with no log rows uses its spend since start (labelled in the tooltip); an older campaign with no spend on record shows no cost rather than a lifetime figure.
Copy: Conversion tracking card note, /conversion-tracking (test button, own clicks, cost per goal (30 days) row). Chatbot CANNED + FACTS, KNOWLEDGE_DATE 2026-10-26. my.js ?v=20261026cv.
QA: convpixel all passed (new: owners pushed without raw IP, own-browser click self=1 and stranger 0, no re-push within 6 h, spend30 = 200 of the window with the 40-day-old row and another member left out, 50/200 credits each vs lifetime 75, no-log old campaign shows no cost, new campaign uses spend since start, own-click count on the card, test button loads cv.gif?px&test=1 in the browser (routed locally) and falls back to op test); fuel all pass (engine.js / engine-room.js / kit.js untouched, byte-identical with LinkSpin); member walk 0 bugs; public 0 bugs (known /shorts ellipsis warning).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
// LinkSpin upserts by id, so two app copies pushing the same rows during a deploy is harmless.
|
||||
// conv(email,..) the member's goals and summary through POST /api/partner/conv (op summary/create/update/remove/test),
|
||||
// summary cached 60 s per email.
|
||||
// owners (2026-10-26) the soft keys members sign in from ride on the click push, so LinkSpin keeps a member's own
|
||||
// clicks (ads here, spin links and Banner Spins there) as tests, never counted
|
||||
// No LS_SYNC_SECRET (or shorter than 32 chars): clicks still get ids and rows, nothing is sent.
|
||||
// The raw IP is never stored: only the soft key 's:' + sha256(ip + '|' + ua) first 20 hex, same on both sites.
|
||||
'use strict';
|
||||
@@ -73,6 +75,24 @@ function withClickId(target, id) {
|
||||
return base + sep + 'lsclk=' + encodeURIComponent(id) + hash;
|
||||
}
|
||||
|
||||
// ---- own-click tests (Marty approved 2026-10-26) ----
|
||||
// A member's own click is a test on LinkSpin, on every click type. LinkSpin knows the soft keys its members sign in from;
|
||||
// InstantAdPay members may never sign in there, so the soft keys of their InstantAdPay sessions ride along with the click
|
||||
// push as owners: [{ owner, sk, ts }] (no raw IP, same hash as the click rows). Queued at most once per 6 h per
|
||||
// email + soft key; a failed push puts them back. Also checked here so an own click is flagged self=1 at the source.
|
||||
const OWN_MS = 31 * 86400e3, ownSeen = new Map(); let ownQueue = new Map();
|
||||
function noteSession(email, ip, ua) {
|
||||
const e = String(email || '').trim().toLowerCase(); if (!e || e.length > 190) return false;
|
||||
const sk = softKey(ip, ua); const k = e + '|' + sk; const now = Date.now();
|
||||
if (now - (ownSeen.get(k) || 0) < 6 * 3600e3) return false;
|
||||
ownSeen.set(k, now); if (ownSeen.size > 50000) ownSeen.delete(ownSeen.keys().next().value);
|
||||
if (on()) { ownQueue.set(k, { owner: e, sk, ts: now }); if (ownQueue.size > 5000) ownQueue.delete(ownQueue.keys().next().value); }
|
||||
return true;
|
||||
}
|
||||
function isOwnerSk(owner, sk) { const t = ownSeen.get(String(owner || '').toLowerCase() + '|' + sk); return !!(t && Date.now() - t <= OWN_MS); }
|
||||
function takeOwners() { const out = [...ownQueue.values()].slice(0, 2000); for (const o of out) ownQueue.delete(o.owner + '|' + o.sk); return out; }
|
||||
function requeueOwners(list) { for (const o of list || []) if (!ownQueue.has(o.owner + '|' + o.sk)) ownQueue.set(o.owner + '|' + o.sk, o); }
|
||||
|
||||
// ---- storage ----
|
||||
function jload() { if (jstate) return jstate; try { jstate = JSON.parse(fs.readFileSync(JFILE(), 'utf8')); if (!Array.isArray(jstate.rows)) throw 0; } catch (e) { jstate = { rows: [] }; } return jstate; }
|
||||
function jsave() { if (saveT) return; saveT = setTimeout(() => { saveT = null; try { fs.writeFileSync(JFILE(), JSON.stringify(jload())); } catch (e) {} }, 500); }
|
||||
@@ -121,11 +141,13 @@ async function flush() {
|
||||
if (!on() || flushing || Date.now() < nextAt) return { skipped: true };
|
||||
flushing = true; let sent = 0;
|
||||
try {
|
||||
for (let round = 0; round < 20; round++) { // drain a backlog, 500 at a time
|
||||
const rows = await unpushed(500); if (!rows.length) break;
|
||||
const res = await signedPost('/api/partner/clicks', { clicks: rows }, 20000);
|
||||
if (!res || res.ok !== true) throw new Error('linkspin answered without ok');
|
||||
await markPushed(rows.map(r => r.id)); sent += rows.length; stats.pushed += rows.length; stats.lastAt = Date.now();
|
||||
for (let round = 0; round < 20; round++) { // drain a backlog, 500 at a time; owners (own soft keys) ride on the first request
|
||||
const rows = await unpushed(500); const owners = round === 0 ? takeOwners() : [];
|
||||
if (!rows.length && !owners.length) break;
|
||||
let res; try { res = await signedPost('/api/partner/clicks', { clicks: rows, owners }, 20000); } catch (e) { requeueOwners(owners); throw e; }
|
||||
if (!res || res.ok !== true) { requeueOwners(owners); throw new Error('linkspin answered without ok'); }
|
||||
if (rows.length) { await markPushed(rows.map(r => r.id)); sent += rows.length; stats.pushed += rows.length; stats.lastAt = Date.now(); }
|
||||
if (owners.length) stats.owners = (stats.owners || 0) + owners.length;
|
||||
if (rows.length < 500) break;
|
||||
}
|
||||
fails = 0; nextAt = 0; return { sent };
|
||||
@@ -151,4 +173,4 @@ async function goalOp(email, op, fields) {
|
||||
cache.delete(e); return out;
|
||||
}
|
||||
function adminView() { return { on: on(), url: URL_(), pushed: stats.pushed, lastAt: stats.lastAt, errors: stats.errors, lastError: stats.lastError, fails, nextAt: nextAt || null }; }
|
||||
module.exports = { init, record, flush, summary, goalOp, withClickId, softKey, placementOf, deviceOf, newId, adminView, on };
|
||||
module.exports = { init, record, flush, summary, goalOp, withClickId, softKey, placementOf, deviceOf, newId, adminView, on, noteSession, isOwnerSk };
|
||||
|
||||
Reference in New Issue
Block a user