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:
martbost
2026-10-26 06:31:18 -05:00
parent 27d663ca29
commit 06f0a87452
9 changed files with 138 additions and 37 deletions
+21 -8
View File
@@ -1104,13 +1104,19 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
document.querySelectorAll('[data-convcamp]').forEach(el => { el.hidden = true; el.innerHTML = ''; });
if (!d || !d.ok || !(d.goals || []).length) return;
const by = d.byCampaign || {};
// cost per goal (30 days), 2026-10-26: goals are the last 30 days, so the spend is too. spend30 = credits each campaign
// spent in those days (credit activity log). A campaign started inside the window with no log rows uses its spend
// since it started (all of it is inside the window); otherwise no cost is shown rather than a lifetime figure.
const sp30 = d.spend30 || null, since = Number(d.spendSince) || (Date.now() - 30 * 86400000);
document.querySelectorAll('[data-convcamp]').forEach(el => {
const id = el.dataset.convcamp; const b = by[id]; const c = convCamps.find(x => String(x.id) === String(id)); if (!c) return;
const spent = Number(c.spent || 0);
let spent = null, basis = '';
if (sp30 && sp30[id] != null) { spent = Number(sp30[id]) || 0; basis = 'the credits it spent in the same 30 days'; }
else if (Number(c.created) >= since) { spent = Number(c.spent || 0); basis = 'the credits it spent since it started on ' + new Date(Number(c.created)).toLocaleDateString([], { month: 'short', day: 'numeric' }) + ', inside the 30 days'; }
const parts = d.goals.map(g => { const n = Number(b && b.conv && b.conv[g.px]) || 0;
return '<span>' + esc(g.name) + ' ' + n.toLocaleString() + (n > 0 ? ' (' + convFmt(spent / n) + ' credits each)' : '') + '</span>'; });
el.innerHTML = '\u{1F3AF} ' + parts.join(' · ') + (b && b.clicks ? ' <span class="muted">· ' + Number(b.clicks).toLocaleString() + ' tracked clicks</span>' : '');
el.title = 'Goals counted for this campaign in the last 30 days. Cost per goal = the credits this campaign has spent, divided by its goals.';
return '<span>' + esc(g.name) + ' ' + n.toLocaleString() + (n > 0 && spent != null ? ' (' + convFmt(spent / n) + ' credits each)' : '') + '</span>'; });
el.innerHTML = '\u{1F3AF} <span class="muted">Goals and cost per goal (30 days):</span> ' + parts.join(' · ') + (spent == null ? ' <span class="muted">· no spend on record for these 30 days, so no cost per goal</span>' : '') + (b && b.clicks ? ' <span class="muted">· ' + Number(b.clicks).toLocaleString() + ' tracked clicks</span>' : '');
el.title = 'Goals counted for this campaign in the last 30 days. Cost per goal (30 days) = ' + (spent != null ? basis : 'the credits it spent in the same 30 days') + ', divided by those goals.';
el.hidden = false;
});
}
@@ -1125,7 +1131,9 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
add.hidden = false;
const goals = d.goals || [];
const m = d.methods || {}; const mt = ['url', 'stored', 'cookie', 'soft'].reduce((s, k) => s + (Number(m[k]) || 0), 0);
st.textContent = goals.length ? (mt ? 'How your conversions were matched (30 days): ' + ['url', 'stored', 'cookie', 'soft'].map(k => k + ' ' + Number(m[k] || 0).toLocaleString()).join(', ') + '.' : 'No conversions counted yet in the last 30 days.') : 'No goals yet. Add your first one below.';
const selfN = Number(d.selfTests) || 0; // own clicks (ads here, spin links and Banner Spins on LinkSpin), kept as tests
st.textContent = goals.length ? (mt ? 'How your conversions were matched (30 days): ' + ['url', 'stored', 'cookie', 'soft'].map(k => k + ' ' + Number(m[k] || 0).toLocaleString()).join(', ') + '.' : 'No conversions counted yet in the last 30 days.')
+ (selfN ? ' ' + selfN.toLocaleString() + ' from your own clicks, kept as tests and left out.' : '') : 'No goals yet. Add your first one below.';
if (!goals.length) { list.innerHTML = ''; snips.innerHTML = ''; return; }
if (!convSel || !goals.some(g => g.px === convSel)) convSel = goals[0].px;
const when = ts => ts ? new Date(ts).toLocaleString([], { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) : 'never';
@@ -1145,10 +1153,15 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str
+ '<p class="small muted" style="margin:6px 0 0">Use it where your page allows scripts. It also sends the click id the landing tag stored, which makes the count surer.</p>'
+ convBox('convJs', 'Goal pixel, JS version', sn.js) + '</details>';
list.querySelectorAll('[data-convpick]').forEach(b => b.addEventListener('click', () => { convSel = b.dataset.convpick; loadConv(); }));
// Send a test conversion (2026-10-26): loads the member's REAL pixel in test mode from this browser, the same request a
// thank-you page makes (LinkSpin answers X-LS-Result: test). If the browser blocks it, the signed partner call records the test.
list.querySelectorAll('[data-convtest]').forEach(b => b.addEventListener('click', async () => {
b.disabled = true;
try { await api('/api/my/conversions/test', { px: b.dataset.convtest }); IAP.status('Test conversion sent. It shows under Last test and never counts in your numbers.', 'ok'); await loadConv(true); }
catch (e) { IAP.status(e.message, 'bad'); b.disabled = false; }
b.disabled = true; const px = b.dataset.convtest; let via = '';
const base = 'https://' + String(d.host || 'linkspin.app').replace(/^https?:\/\//, '').replace(/\/+$/, '');
try { const r = await fetch(base + '/cv.gif?px=' + encodeURIComponent(px) + '&test=1&r=' + Date.now(), { cache: 'no-store', mode: 'cors', credentials: 'omit' }); if (r.ok && /^test/.test(r.headers.get('X-LS-Result') || '')) via = 'pixel'; } catch (e) {}
if (!via) { try { await api('/api/my/conversions/test', { px }); via = 'relay'; } catch (e) { IAP.status(e.message, 'bad'); b.disabled = false; return; } }
IAP.status(via === 'pixel' ? 'Test conversion received by your real pixel. It shows under Last test and never counts in your numbers.' : 'Test conversion recorded through InstantAdPay (this browser did not load the pixel itself). It shows under Last test and never counts in your numbers.', 'ok');
await loadConv(true);
}));
list.querySelectorAll('[data-convdel]').forEach(b => b.addEventListener('click', async () => {
const yes = await IAP.confirmBox('Remove the goal "' + b.dataset.convname + '"? Its pixel stops counting. Pages that still carry it will simply be ignored.', { title: 'Remove goal', ok: 'Remove', cancel: 'Keep it' });