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:
+60
-6
@@ -7,7 +7,10 @@
|
||||
// gets it, an existing lsclk is never replaced, an unparsable target goes out unchanged), the click rows pushed with a valid
|
||||
// signature and the contract fields, the owner's own click flagged self=1 and not counted, the proxies, the Campaigns pane
|
||||
// showing goals and cost per goal (300 credits / 4 = 75), LinkSpin down: pane still loads, panel says so, rows kept and
|
||||
// pushed once it is back. Exit code 1 on any failure.
|
||||
// pushed once it is back. 2026-10-26: own soft keys pushed as owners and an own-browser click flagged self (billing
|
||||
// unchanged), Send a test conversion loads the real pixel in test mode (routed in the browser, nothing leaves the machine)
|
||||
// with the partner call as fallback, the own-click test count on the card, cost per goal (30 days) from the credit log.
|
||||
// Exit code 1 on any failure.
|
||||
import http from 'node:http';
|
||||
import crypto from 'node:crypto';
|
||||
import fs from 'node:fs';
|
||||
@@ -38,12 +41,17 @@ const camp = (id, owner, name, targetUrl, spent) => ({ id, owner, memberId: 0, t
|
||||
budget: 1000, spent, accrued: 0, imps: 50, clicks: 0, batchImps: 0, width: 468, height: 60, status: 'paused', created: now - 86400000 });
|
||||
const T1 = 'https://adv.example/landing?utm_source=iap&x=a%2Cb&q=hello+world#top';
|
||||
const CAMPS = [camp(1, A1, 'QA landing', T1, 300), camp(2, A1, 'QA spin link', 'https://linkspin.app/r/abc12', 120),
|
||||
camp(3, A1, 'QA has lsclk', 'https://adv.example/p?lsclk=keepme', 0), camp(4, A1, 'QA odd target', 'adv.example/no-scheme', 0), camp(5, A2, 'QA other', 'https://other.example/', 50)];
|
||||
camp(3, A1, 'QA has lsclk', 'https://adv.example/p?lsclk=keepme', 0), camp(4, A1, 'QA odd target', 'adv.example/no-scheme', 0), camp(5, A2, 'QA other', 'https://other.example/', 50),
|
||||
Object.assign(camp(6, A1, 'QA old no log', 'https://adv.example/old', 500), { created: now - 60 * 86400000 }), Object.assign(camp(7, A1, 'QA new no log', 'https://adv.example/new', 90), { created: now - 3 * 86400000 })];
|
||||
// cost per goal (30 days): campaign 1 spent 150 today + 50 five days ago inside the window, 100 forty days ago outside it
|
||||
const ctd = t => new Date(t).toLocaleDateString('en-CA', { timeZone: 'America/Chicago' });
|
||||
const cl = (t, delta, ref) => ({ email: A1, ts: t, day: ctd(t), delta, kind: 'delivery', note: 'Ad views: QA landing', ref: String(ref) });
|
||||
fs.writeFileSync(path.join(DATA, 'credit-log.json'), JSON.stringify({ items: [cl(now - 40 * 86400000, -100, 1), cl(now - 5 * 86400000, -50, 1), cl(now - 60000, -150, 1), Object.assign(cl(now - 60000, -999, 1), { email: A2 })] }));
|
||||
fs.writeFileSync(path.join(DATA, 'campaigns.json'), JSON.stringify({ v: 1, nextId: 6, campaigns: CAMPS, burnsPending: [] }));
|
||||
|
||||
// ---- mock LinkSpin ----
|
||||
const PX1 = 'px0123456789', PX2 = 'pxabcdef0123';
|
||||
const mock = { clicks: new Map(), badSig: 0, calls: [], down: false, goals: { [A1]: [{ px: PX1, name: 'subscriber', value: null, created: now - 86400000, conv: 6, convDays: 30, lastAt: now - 3600000, lastTest: null }, { px: PX2, name: 'sale', value: 19.95, created: now - 86400000, conv: 1, convDays: 30, lastAt: now - 7200000, lastTest: null }] } };
|
||||
const mock = { clicks: new Map(), owners: [], badSig: 0, calls: [], down: false, goals: { [A1]: [{ px: PX1, name: 'subscriber', value: null, created: now - 86400000, conv: 6, convDays: 30, lastAt: now - 3600000, lastTest: null }, { px: PX2, name: 'sale', value: 19.95, created: now - 86400000, conv: 1, convDays: 30, lastAt: now - 7200000, lastTest: null }] } };
|
||||
const verify = (ts, sig, raw) => { if (!ts || !sig || Math.abs(Date.now() - Number(ts)) > 300000) return false; const want = crypto.createHmac('sha256', SECRET).update(ts + '\n' + raw).digest('hex'); return want.length === String(sig).length && crypto.timingSafeEqual(Buffer.from(want), Buffer.from(String(sig))); };
|
||||
const send = (res, code, obj) => { res.writeHead(code, { 'Content-Type': 'application/json' }); res.end(JSON.stringify(obj)); };
|
||||
function mockHandler(req, res) {
|
||||
@@ -52,11 +60,11 @@ function mockHandler(req, res) {
|
||||
if (req.method !== 'POST') return send(res, 404, { error: 'not found' });
|
||||
if (!verify(req.headers['x-ls-ts'], req.headers['x-ls-sig'], raw)) { mock.badSig++; return send(res, 401, { error: 'bad signature' }); }
|
||||
const b = JSON.parse(raw || '{}');
|
||||
if (req.url === '/api/partner/clicks') { for (const c of b.clicks || []) mock.clicks.set(c.id, c); return send(res, 200, { ok: true, n: (b.clicks || []).length }); }
|
||||
if (req.url === '/api/partner/clicks') { for (const c of b.clicks || []) mock.clicks.set(c.id, c); for (const o of b.owners || []) mock.owners.push(o); return send(res, 200, { ok: true, n: (b.clicks || []).length, owners: (b.owners || []).length }); }
|
||||
if (req.url === '/api/partner/conv') {
|
||||
mock.calls.push(b); const email = String(b.email || '');
|
||||
const goals = mock.goals[email] || (mock.goals[email] = []);
|
||||
if (b.op === 'summary') return send(res, 200, { ok: true, goals, byCampaign: email === A1 ? { 1: { clicks: 9, conv: { [PX1]: 4, [PX2]: 1 }, value: { [PX2]: 19.95 } }, 2: { clicks: 3, conv: {} } } : {}, methods: { url: 2, stored: 2, cookie: 1, soft: 1 }, host: 'linkspin.app' });
|
||||
if (b.op === 'summary') return send(res, 200, { ok: true, goals, byCampaign: email === A1 ? { 1: { clicks: 9, conv: { [PX1]: 4, [PX2]: 1 }, value: { [PX2]: 19.95 } }, 2: { clicks: 3, conv: {} }, 6: { clicks: 4, conv: { [PX1]: 2 } }, 7: { clicks: 5, conv: { [PX1]: 3 } } } : {}, methods: { url: 2, stored: 2, cookie: 1, soft: 1 }, selfTests: email === A1 ? 3 : 0, host: 'linkspin.app' });
|
||||
if (b.op === 'create') { const g = { px: 'px' + crypto.randomBytes(5).toString('hex'), name: b.name, value: b.value == null ? null : b.value, created: Date.now(), conv: 0, convDays: 30, lastAt: null, lastTest: null }; goals.push(g); return send(res, 200, { ok: true, goal: g }); }
|
||||
if (b.op === 'remove') { const i = goals.findIndex(g => g.px === b.px); if (i < 0) return send(res, 404, { error: 'No such goal.' }); goals.splice(i, 1); return send(res, 200, { ok: true }); }
|
||||
if (b.op === 'test') { const g = goals.find(x => x.px === b.px); if (!g) return send(res, 404, { error: 'No such goal.' }); g.lastTest = Date.now(); return send(res, 200, { ok: true, at: g.lastTest }); }
|
||||
@@ -126,10 +134,22 @@ try {
|
||||
const after = (await api('/api/my/campaigns', null, { Cookie: ck1 })).j;
|
||||
const clicksAfter = ((after && after.campaigns) || []).find(c => c.id === 1);
|
||||
ok(clicksBefore && clicksAfter && clicksAfter.clicks === clicksBefore.clicks && clicksBefore.clicks === 2, 'own click not counted (clicks stay 2)', JSON.stringify([clicksBefore && clicksBefore.clicks, clicksAfter && clicksAfter.clicks]));
|
||||
// fix 1 (2026-10-26): the soft keys the owner signs in from go to LinkSpin as owners; a click from that browser while
|
||||
// signed out is flagged self for conversions (billing unchanged: it is still a counted click)
|
||||
const skNode = ['127.0.0.1', '::ffff:127.0.0.1'].map(x => 's:' + crypto.createHash('sha256').update(x + '|node').digest('hex').slice(0, 20));
|
||||
ok(!!(await waitFor(() => mock.owners.some(o => o.owner === A1 && skNode.includes(o.sk)), 10000)), "owner's session soft key pushed to LinkSpin as owners (no raw IP)", JSON.stringify(mock.owners));
|
||||
ok(!JSON.stringify(mock.owners).includes('127.0.0.1'), 'no raw IP in the owners rows');
|
||||
const ownSk = await click(1, { 'User-Agent': 'node' }); const idOwnSk = (ID.exec(ownSk.loc || '') || [])[1];
|
||||
ok(!!(await waitFor(() => mock.clicks.get(idOwnSk), 10000)) && mock.clicks.get(idOwnSk).self === 1, "a click from the owner's own browser, signed out, is pushed self=1", JSON.stringify(mock.clicks.get(idOwnSk)));
|
||||
const strangerC = await click(1, { 'User-Agent': 'Mozilla/5.0 Stranger QA' }); const idStr = (ID.exec(strangerC.loc || '') || [])[1];
|
||||
ok(!!(await waitFor(() => mock.clicks.get(idStr), 10000)) && mock.clicks.get(idStr).self === 0, "a stranger's click is still self=0");
|
||||
const nOwners = mock.owners.length; await api('/api/my/campaigns', null, { Cookie: ck1 }); await sleep(3500);
|
||||
ok(mock.owners.length === nOwners, 'the same session soft key is not pushed again within 6 h');
|
||||
|
||||
// 4. proxies
|
||||
const sum = await api('/api/my/conversions', null, { Cookie: ck1 });
|
||||
ok(sum.j && sum.j.ok === true && sum.j.goals.length === 2 && sum.j.byCampaign['1'].conv[PX1] === 4, 'GET /api/my/conversions relays the LinkSpin summary', JSON.stringify(sum.j).slice(0, 200));
|
||||
ok(sum.j && sum.j.spend30 && sum.j.spend30['1'] === 200 && sum.j.spend30['6'] == null && sum.j.spend30['7'] == null && sum.j.spendSince > Date.now() - 31 * 86400000, 'spend30 from the credit log: campaign 1 = 150 + 50 inside the 30 days (the 100 from 40 days ago and another member\'s row left out)', JSON.stringify(sum.j && sum.j.spend30));
|
||||
const lastSum = mock.calls.filter(c => c.op === 'summary').pop();
|
||||
ok(lastSum && lastSum.email === A1 && lastSum.days === 30, 'summary asked for the signed-in email, 30 days', JSON.stringify(lastSum));
|
||||
const nSum = mock.calls.filter(c => c.op === 'summary').length; await api('/api/my/conversions', null, { Cookie: ck1 });
|
||||
@@ -163,6 +183,7 @@ try {
|
||||
rows: document.querySelectorAll('#campList .camp-table tbody tr').length,
|
||||
line1: (document.querySelector('[data-convcamp="1"]') || {}).textContent || '', line1Hidden: !!(document.querySelector('[data-convcamp="1"]') || {}).hidden,
|
||||
line5Hidden: (document.querySelector('[data-convcamp="5"]') || { hidden: true }).hidden,
|
||||
line6: (document.querySelector('[data-convcamp="6"]') || {}).textContent || '', line7: (document.querySelector('[data-convcamp="7"]') || {}).textContent || '', title1: (document.querySelector('[data-convcamp="1"]') || {}).title || '',
|
||||
card: !document.getElementById('convCard').hidden, status: document.getElementById('convStatus').textContent,
|
||||
goals: document.querySelectorAll('#convGoals tbody tr').length, convCells: [...document.querySelectorAll('#convGoals td[data-l="Conversions (30 days)"]')].map(td => (td.firstChild && td.firstChild.textContent || '').trim()), landing: (document.getElementById('convLanding') || {}).value || '', img: (document.getElementById('convImg') || {}).value || '',
|
||||
js: (document.getElementById('convJs') || {}).value || '', tip: document.getElementById('convCard').textContent }));
|
||||
@@ -171,7 +192,11 @@ try {
|
||||
}
|
||||
const p1 = await pane(ck1, 'convpixel-pane.png');
|
||||
ok(p1.st.rows >= 4 && p1.st.card, 'Campaigns pane loads with the Conversion tracking card', JSON.stringify(p1.st).slice(0, 200));
|
||||
ok(!p1.st.line1Hidden && /subscriber 4 \(75 credits each\)/.test(p1.st.line1) && /sale 1 \(300 credits each\)/.test(p1.st.line1), 'campaign row shows goals + cost per goal (300 / 4 = 75 credits)', p1.st.line1);
|
||||
ok(!p1.st.line1Hidden && /cost per goal \(30 days\)/.test(p1.st.line1) && /subscriber 4 \(50 credits each\)/.test(p1.st.line1) && /sale 1 \(200 credits each\)/.test(p1.st.line1), 'campaign row: cost per goal (30 days) = 200 credits spent in the 30 days / 4 = 50 (not lifetime 300 / 4 = 75)', p1.st.line1);
|
||||
ok(/same 30 days/.test(p1.st.title1), 'its tooltip says the spend is the same 30 days', p1.st.title1);
|
||||
ok(/subscriber 2/.test(p1.st.line6) && !/credits each/.test(p1.st.line6) && /no spend on record/.test(p1.st.line6), 'an older campaign with no spend in the log shows no cost per goal rather than a lifetime figure', p1.st.line6);
|
||||
ok(/subscriber 3 \(30 credits each\)/.test(p1.st.line7), 'a campaign started inside the window with no log rows uses its spend since start (90 / 3 = 30)', p1.st.line7);
|
||||
ok(/3 from your own clicks, kept as tests/.test(p1.st.status), 'card shows the own-click test count (selfTests from LinkSpin)', p1.st.status);
|
||||
ok(!/\$/.test(p1.st.line1), 'cost per goal is in credits, never dollars');
|
||||
ok(JSON.stringify(p1.st.convCells) === '["6","1"]', 'goal rows show the conversion count, not the 30-day window (convDays is the window length)', JSON.stringify(p1.st.convCells));
|
||||
ok(p1.st.goals === 2 && p1.st.landing === '<script async src="https://linkspin.app/t.js?px=' + PX1 + '"></script>', 'goal list + landing tag snippet', p1.st.landing);
|
||||
@@ -179,6 +204,35 @@ try {
|
||||
ok(/Thank You Page: custom page/.test(p1.st.tip) && /Thank-you page: custom URL/.test(p1.st.tip) && /24-hour match/.test(p1.st.tip), 'autoresponder advice + match legend present');
|
||||
ok(/url 2, stored 2, cookie 1, soft 1/.test(p1.st.status), 'match methods line', p1.st.status);
|
||||
ok(!p1.errs.length, 'no page errors', p1.errs.join(' | '));
|
||||
// fix 2 (2026-10-26): Send a test conversion loads the REAL pixel in test mode. The browser's request to linkspin.app is
|
||||
// routed here (nothing leaves the machine): PX1 answers X-LS-Result: test like LinkSpin; PX2 answers unknown, so the
|
||||
// card falls back to the signed partner call (op test).
|
||||
{
|
||||
const ctx = await browser.newContext({ viewport: { width: 1280, height: 1000 } });
|
||||
await ctx.addInitScript(() => { try { sessionStorage.setItem('iap.welcome.v1', '1'); } catch (e) {} });
|
||||
const [k, v] = ck1.split(';')[0].split('='); await ctx.addCookies([{ name: k, value: v, url: B }]);
|
||||
const pixelHits = [];
|
||||
await ctx.route(/^https:\/\/linkspin\.app\/cv\.gif/, route => { const u = new URL(route.request().url()); pixelHits.push(u.search); const px = u.searchParams.get('px'); const g = (mock.goals[A1] || []).find(x => x.px === px);
|
||||
const good = px === PX1 && u.searchParams.get('test') === '1' && g; if (good) g.lastTest = Date.now();
|
||||
return route.fulfill({ status: 200, headers: { 'Content-Type': 'image/gif', 'Access-Control-Allow-Origin': '*', 'Access-Control-Expose-Headers': 'X-LS-Result', 'X-LS-Result': good ? 'test' : 'unknown' }, body: Buffer.from('R0lGODlhAQABAAAAACw=', 'base64') }); });
|
||||
const page = await ctx.newPage(); const errs = []; page.on('pageerror', e => errs.push(e.message));
|
||||
await page.goto(B + '/my', { waitUntil: 'domcontentloaded' }); await page.waitForTimeout(2500);
|
||||
await page.evaluate(() => { document.querySelectorAll('.modal-back,.lgate,.iap-welcome').forEach(m => m.hidden = true); });
|
||||
await page.click('.bo-menu [data-pane="campaigns"]'); await page.waitForTimeout(2500);
|
||||
const testsBefore = mock.calls.filter(c => c.op === 'test').length;
|
||||
await page.click('[data-convtest="' + PX1 + '"]'); await page.waitForTimeout(2000);
|
||||
const msg1 = await page.evaluate(() => document.body.innerText);
|
||||
const last1 = await page.evaluate(px => { const b = document.querySelector('[data-convtest="' + px + '"]'); const tr = b && b.closest('tr'); const td = tr && tr.querySelector('td[data-l="Last test"]'); return td ? td.textContent.trim() : ''; }, PX1);
|
||||
ok(pixelHits.some(q => q.includes('px=' + PX1) && q.includes('test=1')), 'Send a test conversion loads the real pixel cv.gif?px=..&test=1 from the browser', JSON.stringify(pixelHits));
|
||||
ok(/received by your real pixel/.test(msg1) && last1 && last1 !== 'never' && mock.calls.filter(c => c.op === 'test').length === testsBefore, 'pixel answered test: Last test updates, no partner fallback needed', last1);
|
||||
await page.click('[data-convtest="' + PX2 + '"]'); await page.waitForTimeout(2000);
|
||||
const msg2 = await page.evaluate(() => document.body.innerText);
|
||||
const tcall = mock.calls.filter(c => c.op === 'test').pop();
|
||||
ok(pixelHits.some(q => q.includes('px=' + PX2)) && tcall && tcall.px === PX2 && /recorded through InstantAdPay/.test(msg2), 'pixel did not confirm: falls back to the signed partner call (op test)', JSON.stringify(tcall));
|
||||
ok(!errs.length, 'no page errors during the tests', errs.join(' | '));
|
||||
await page.screenshot({ path: path.join(OUT, 'convpixel-test-button.png'), fullPage: true }).catch(() => {});
|
||||
await ctx.close();
|
||||
}
|
||||
|
||||
// 6. LinkSpin down: the pane still loads, the panel says so, campaign rows omit the goal line; clicks are kept and pushed later
|
||||
mock.down = true;
|
||||
|
||||
Reference in New Issue
Block a user