Conversion tracking fixes (Marty approved 2026-10-26): own clicks are tests on every click type, Banner Spin straight-to-page clicks carry lsclk

1. Own clicks: a goal owner's own click on ANY click type (LinkSpin/InstantAdPay ads, spin links, Banner Spins) is kept as a test, never counted, never fires a goal postback. Own = ad click flagged self for that owner, a spin-link / Banner Spin click marked at click time (signed in as the owner, or from an owner soft key: markOwnClick in server.js), or the clicking or converting browser's soft key is one the owner signs in from. auth.onSeen notes LinkSpin session soft keys (throttled, kept 31 days in convtrack.json S.own); /api/partner/clicks takes owners [{owner, sk, ts}] from InstantAdPay before the clicks, so IAP members' own browsers are known too. Linked positions share the owner's email. X-LS-Result adds ;self. partnerSummary returns selfTests for the IAP card. Conversions screen copy: test with Send a test conversion and the &test=1 page check, own clicks never count (conversions.js ?v=20261026a).
3. Banner Spin: a click whose target is a direct page (not a /r/ spin link) gets ?lsclk=<k click id> when the owner tracks goals (string insert like lsconv.withClickId: params kept, before #hash, an existing lsclk never replaced). convtrack.lookup resolves k ids through bannerspin.clickById; conversions record k:'bspin' with the Banner Spin, banner, page and source; report By Banner Spin, CSV site 'Banner Spin', postback ctx with its sub ids.
Guides: /conversion-tracking (Banner Spin straight to a page now counted, own clicks on every type are tests, By Banner Spin), /refuel tile. Chatbot CANNED + FACTS, KNOWLEDGE_DATE 2026-10-26.
QA: convpixel 77/77 (new: owner soft keys, own ad/spin/Banner Spin/IAP clicks as tests, stranger still counts, own-browser conversion, withClickId, Banner Spin lsclk + By Banner Spin + spin-link banner untouched, selfTests in the IAP summary, no postback for own clicks); lsid 31/31; fuel all pass (engine.js / engine-room.js / kit.js untouched, byte-identical with InstantAdPay); bannerspin 75/75; member walk 0 bugs; public 0 bugs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-26 06:19:54 -05:00
parent 28192b61e9
commit 98e3ed36d8
10 changed files with 206 additions and 48 deletions
+76 -8
View File
@@ -4,7 +4,9 @@
// campaigns.json): ad click -> click id on the target -> goal pixel counts once with method url / stored / cookie /
// soft; dedupe; owner mismatch refused; spin link reached through an ad inherits the ad; cost per goal; goal postback
// attempted (an .invalid host, nothing leaves the machine); InstantAdPay clicks + summary over the signed partner call;
// self click kept as a test; test conversion; CSV.
// self click kept as a test; test conversion; CSV. 2026-10-26: own clicks are tests on every click type (owner soft
// key from a session, signed-in clicks on spin links and Banner Spins, a goal finished in the owner's browser, InstantAdPay
// owners pushed with the clicks); Banner Spin straight to a page carries lsclk and reports By Banner Spin.
// 3) browser (Playwright, if present): the landing tag on another origin keeps the id, fills a hidden lsclk field and
// decorates same-site links; the script goal pixel on the thank-you page counts with method 'stored', also framed.
// node qa/convpixel.test.mjs (from the site dir; no internet needed) Env: PORT (default 8973), PW
@@ -58,6 +60,27 @@ const DAY = 86400000;
let limited = 0; for (let i = 0; i < 25; i++) if (C.record({ px, c: 'nosuchclick1' }, fake('192.0.2.99'), {}).result === 'limited') limited++;
check(limited === 5, 'per-visitor rate limit: 20 a minute, the rest refused', limited + ' limited');
check(C.record({ px: 'px0000000000', c: id }, fake('192.0.2.98'), {}).result === 'unknown', 'unknown pixel id ignored');
// fix 1 (2026-10-26): own clicks are tests on every click type. The owner is seen signed in from 192.0.2.7 + OwnerUA.
const ownReq = fake('192.0.2.7', 'OwnerUA');
check(C.noteSession('Own@U.test', ownReq) && C.isOwnerSk('own@u.test', C.softKey(ownReq)) && !C.isOwnerSk('else@u.test', C.softKey(ownReq)), 'owner soft key noted from a session (email lowercased), not shared with another owner');
const idOwnSk = C.recordAdClick({ id: 7, owner: 'own@u.test', name: 'Unit ad', type: 'banner', targetUrl: 'https://x.test/' }, ownReq, {});
check(C.lookup(idOwnSk).ad.self === 1, "an ad click from the owner's browser is flagged self even when not signed in");
r = C.record({ px, c: idOwnSk, m: 'url' }, fake('192.0.2.60'), {});
check(r.result === 'counted' && r.conv.self === 1, 'its conversion is kept as a test (self)', JSON.stringify(r.result));
const idStr = C.recordAdClick({ id: 7, owner: 'own@u.test', name: 'Unit ad', type: 'banner', targetUrl: 'https://x.test/' }, fake('192.0.2.61', 'StrangerUA'), {});
r = C.record({ px, c: idStr, m: 'url' }, ownReq, {});
check(r.result === 'counted' && r.conv.self === 1, "a stranger's click converted from the owner's own browser is a test too", JSON.stringify(r.result));
const idStr2 = C.recordAdClick({ id: 7, owner: 'own@u.test', name: 'Unit ad', type: 'banner', targetUrl: 'https://x.test/' }, fake('192.0.2.62', 'StrangerUA'), {});
r = C.record({ px, c: idStr2, m: 'url' }, fake('192.0.2.63', 'StrangerUA'), {});
check(r.result === 'counted' && !r.conv.self, "a stranger's click and conversion still count", JSON.stringify(r.conv && r.conv.self));
const skI = 's:' + 'b'.repeat(20);
check(C.importOwners([{ owner: 'Own@U.test', sk: skI, ts: Date.now() }, { owner: 'x@y.z', sk: 'nope' }]) === 1 && C.isOwnerSk('own@u.test', skI), 'InstantAdPay owner soft keys import (bad rows dropped)');
C.importClicks([{ id: 'i0123456789c', camp: 5, owner: 'own@u.test', ts: Date.now(), sk: skI, self: 0 }]);
check(C.lookup('i0123456789c').ad.self === 1, "an InstantAdPay click from the owner's InstantAdPay browser imports as self");
check(C.markSelfClick('abcdef0123', 'own@u.test', ownReq, '') && C.markSelfClick('abcdef0124', 'own@u.test', fake('192.0.2.64', 'Other'), 'OWN@u.test') && !C.markSelfClick('abcdef0125', 'own@u.test', fake('192.0.2.65', 'Other'), 'else@u.test'), 'spin / Banner Spin clicks marked self by owner soft key or owner session, not by someone else');
// withClickId: the string insert lsconv uses
check(C.withClickId('https://a.test/p?utm=x&q=a%2Cb#top', 'k0123456789a') === 'https://a.test/p?utm=x&q=a%2Cb&lsclk=k0123456789a#top' && C.withClickId('https://a.test/p?lsclk=keep', 'k0123456789a') === 'https://a.test/p?lsclk=keep'
&& C.withClickId('https://a.test', 'k0123456789a') === 'https://a.test?lsclk=k0123456789a' && C.withClickId('not a url', 'k0123456789a') === 'not a url', 'withClickId: params kept byte for byte, before the #hash, an lsclk never replaced, bad URL unchanged');
fs.rmSync(UD, { recursive: true, force: true });
}
@@ -176,26 +199,71 @@ try {
const own = await req('GET', '/api/ads/click/1', { ip: '10.77.0.1', cookie: cA });
const idSelf = lsclkOf(own.headers.location);
r = await req('GET', '/cv.gif?px=' + PX + '&c=' + idSelf + '&m=url', { ip: '198.18.0.11' });
check(res(r) === 'counted;url', "advertiser's own click still gets an id and is recorded (as a test)", res(r));
check(res(r) === 'counted;url;self', "advertiser's own click still gets an id and is recorded (as a test)", res(r));
// fix 1: the owner's own SPIN LINK click (from the browser they signed in with, no cookie on the link domain) is a test
const ownSpin = await req('GET', '/r/' + rot.code, { ip: '10.77.0.1' });
const idOwnSpin = lsclkOf(ownSpin.headers.location);
r = await req('GET', '/cv.gif?px=' + PX + '&c=' + idOwnSpin + '&m=url', { ip: '198.18.0.12' });
check(/^[a-f0-9]{10}$/.test(idOwnSpin) && res(r) === 'counted;url;self', "owner's own spin-link click (owner soft key): its conversion is a test, not counted", res(r));
const ownSpin2 = await req('GET', '/r/' + rot.code, { ip: '10.77.0.99', cookie: cA }); // signed in on this host, another network
r = await req('GET', '/cv.gif?px=' + PX + '&c=' + lsclkOf(ownSpin2.headers.location) + '&m=url', { ip: '198.18.0.13' });
check(res(r) === 'counted;url;self', "owner's own spin-link click while signed in: a test", res(r));
// a stranger's spin click converted from the owner's own browser: a test too
const strangerSpin = await req('GET', '/r/' + rot.code, { ip: '203.0.113.28' });
r = await req('GET', '/cv.gif?px=' + PX + '&c=' + lsclkOf(strangerSpin.headers.location) + '&m=url', { ip: '10.77.0.1' });
check(res(r) === 'counted;url;self', "a goal finished in the owner's own browser is a test", res(r));
// fix 3: Banner Spin straight to a page carries lsclk; a stranger's goal counts under By Banner Spin, the owner's own is a test
const AUTH = { Authorization: 'Bearer localtest-cv' };
const gr = await req('POST', '/api/admin/bannerspins', { headers: AUTH, body: { email: A, grant: 'starter' } });
const bsc = await req('POST', '/api/my/bannerspins', { cookie: cA, body: { name: 'Conv QA banners', size: '468x60', fallback: 'https://landing.qa.test/fallback' } });
const BS = bsc.json && bsc.json.spin;
const bb1 = BS && await req('POST', '/api/my/bannerspins/' + BS.id + '/banner', { cookie: cA, body: { image: 'https://img.qa.invalid/b1.png', target: 'https://landing.qa.test/bs?utm_source=bs&q=a%2Cb#form', label: 'Direct', weight: 10 } });
check(gr.status === 200 && BS && BS.code && bb1 && bb1.status === 200, 'Banner Spin set up for the member (starter grant, one banner straight to a page)', [gr.status, bsc.text.slice(0, 120), bb1 && bb1.text.slice(0, 120)].join(' | '));
const bid = bb1 && bb1.json && ((bb1.json.banner && bb1.json.banner.id) || (bb1.json.spin && bb1.json.spin.banners && bb1.json.spin.banners.slice(-1)[0].id)) || 1;
const bk = await req('GET', '/c/' + BS.code + '?x=' + bid, { ip: '203.0.113.50' });
const idBs = lsclkOf(bk.headers.location);
check(bk.status === 302 && /^k[a-f0-9]{11}$/.test(idBs) && bk.headers.location === 'https://landing.qa.test/bs?utm_source=bs&q=a%2Cb&lsclk=' + idBs + '#form', 'Banner Spin click straight to a page: lsclk added, params kept byte for byte, before the #hash', bk.headers.location);
r = await req('GET', '/cv.gif?px=' + PX + '&c=' + idBs + '&m=stored', { ip: '198.18.0.14' });
check(res(r) === 'counted;stored', 'a goal on the Banner Spin click counts', res(r));
const tagBs = await req('GET', '/t.gif?px=' + PX + '&c=' + idBs, { ip: '198.18.0.15' });
check(res(tagBs) === 'stored', 'the landing tag accepts the Banner Spin click id', res(tagBs));
const bkOwn = await req('GET', '/c/' + BS.code + '?x=' + bid, { ip: '10.77.0.1' });
r = await req('GET', '/cv.gif?px=' + PX + '&c=' + lsclkOf(bkOwn.headers.location) + '&m=url', { ip: '198.18.0.16' });
check(res(r) === 'counted;url;self', "owner's own Banner Spin click: a test, not counted", res(r));
const bb2 = await req('POST', '/api/my/bannerspins/' + BS.id + '/banner', { cookie: cA, body: { image: 'https://img.qa.invalid/b2.png', link: rot.id, label: 'Via spin', weight: 10 } });
const bid2 = bb2.json && ((bb2.json.banner && bb2.json.banner.id) || (bb2.json.spin && bb2.json.spin.banners.slice(-1)[0].id));
const bkSpin = await req('GET', '/c/' + BS.code + '?x=' + bid2, { ip: '203.0.113.51' });
check(bkSpin.status === 302 && /\/r\/[a-z0-9]+$/.test(bkSpin.headers.location || ''), 'a banner pointed at a spin link gets no lsclk of its own (the spin link adds one)', bkSpin.headers.location);
const bkB = await req('GET', '/api/admin/bannerspins', { headers: AUTH });
check(bkB.status === 200, 'admin Banner Spin list still answers');
// the report: counts, methods, cost per goal (campaign 1: 300 credits spent / 4 subscribers = 75)
const rep = (await req('GET', '/api/my/conversions?days=30', { cookie: cA })).json;
const G = rep.byGoal.find(x => x.goal === 'subscriber');
const c1 = G.campaigns.find(c => c.key === 'ls:1'), c3 = G.campaigns.find(c => c.key === 'ls:3'), cI = G.campaigns.find(c => c.key === 'iap:77');
check(G.n === 6, 'report: 6 subscribers counted (4 on campaign 1, 1 via spin link, 1 IAP); self click left out', 'n=' + G.n);
check(G.n === 7, 'report: 7 subscribers counted (4 on campaign 1, 1 via spin link, 1 IAP, 1 Banner Spin); every own click left out (ad, spin link x3, Banner Spin)', 'n=' + G.n);
check(G.banners && G.banners.length === 1 && G.banners[0].code === BS.code && G.banners[0].n === 1, 'by Banner Spin: the straight-to-page banner shows its one goal', JSON.stringify(G.banners));
check(!G.links.some(x => x.n > 1), 'own spin-link clicks are not in the spin-link counts', JSON.stringify(G.links));
check(c1 && c1.n === 4 && c1.spent === 300 && c1.costPer === 75 && c1.clicks === 4, 'cost per goal: 300 credits / 4 = 75 credits, 4 clicks counted (own click left out)', JSON.stringify(c1));
check(c3 && c3.n === 1 && cI && cI.n === 1 && cI.costPer === 200 && cI.site === 'InstantAdPay', 'spin conversion credited to the ad campaign; IAP campaign shows its own cost per goal from the pushed spend', JSON.stringify([c3, cI]));
check(G.links.length === 1 && G.links[0].code === rot.code && G.links[0].n === 1, 'by spin link', JSON.stringify(G.links));
check(G.methods.url === 2 && G.methods.stored === 2 && G.methods.cookie === 1 && G.methods.soft === 1 && rep.selfTests === 1, 'match-method breakdown url 2 / stored 2 / cookie 1 / soft 1, one self test apart', JSON.stringify([G.methods, rep.selfTests]));
check(G.methods.url === 2 && G.methods.stored === 3 && G.methods.cookie === 1 && G.methods.soft === 1 && rep.selfTests === 5, 'match-method breakdown url 2 / stored 3 / cookie 1 / soft 1, five own-click tests apart (ad, spin x3, Banner Spin)', JSON.stringify([G.methods, rep.selfTests]));
check(G.dests.some(d => d.k === 'landing.qa.test/lp') && G.sources.length > 0, 'by destination page and traffic source', JSON.stringify([G.dests, G.sources]).slice(0, 200));
check(rep.goals.find(g => g.px === PX).lastTest > 0 && rep.goals.find(g => g.px === PX).conv === 6, 'goal row shows the last test and the 30-day count');
check(rep.goals.find(g => g.px === PX).lastTest > 0 && rep.goals.find(g => g.px === PX).conv === 7, 'goal row shows the last test and the 30-day count');
const sumSelf = await signed('/api/partner/conv', { op: 'summary', email: A, days: 30 });
check(sumSelf.json && sumSelf.json.selfTests === 5, 'IAP summary carries the own-click test count (selfTests) for the card', JSON.stringify(sumSelf.json && sumSelf.json.selfTests));
const ownI = 'i' + crypto.randomBytes(6).toString('hex').slice(0, 11), skOwnI = 's:' + crypto.randomBytes(10).toString('hex');
const pcOwn = await signed('/api/partner/clicks', { owners: [{ owner: A, sk: skOwnI, ts: Date.now() }], clicks: [{ id: ownI, camp: 77, cname: 'IAP QA banner', type: 'banner', owner: A, ts: Date.now(), sk: skOwnI, self: 0, spent: 200 }] });
r = await req('GET', '/cv.gif?px=' + PX + '&c=' + ownI + '&m=url', { ip: '198.18.0.17' });
check(pcOwn.json && pcOwn.json.owners === 1 && res(r) === 'counted;url;self', "an InstantAdPay click from the owner's InstantAdPay browser (owners pushed with the clicks) is a test", JSON.stringify(pcOwn.json) + ' ' + res(r));
const csv = await req('GET', '/api/my/conversions.csv?days=30', { cookie: cA });
check(csv.status === 200 && /text\/csv/.test(csv.headers['content-type']) && csv.text.trim().split('\n').length === 7, 'CSV export: header + 6 rows', String(csv.text.split('\n').length));
check(csv.status === 200 && /text\/csv/.test(csv.headers['content-type']) && csv.text.trim().split('\n').length === 8 && /,Banner Spin,/.test(csv.text), 'CSV export: header + 7 rows, one from a Banner Spin', String(csv.text.split('\n').length));
const csvB = await req('GET', '/api/my/conversions.csv?days=30', { cookie: await signIn(B, '10.77.0.2') });
check(csvB.text.trim().split('\n').length === 1, "another member's CSV has none of these rows");
// the goal postback was attempted with event = goal name
let plog = []; for (let i = 0; i < 30; i++) { await sleep(500); try { plog = JSON.parse(fs.readFileSync(path.join(DATA, 'postbacks.json'), 'utf8')).log.filter(l => l.event === 'subscriber'); } catch (e) {} if (plog.length >= 6) break; }
check(plog.length >= 6 && plog.every(l => /e=subscriber/.test(l.url)) && plog.some(l => l.lsid === id1), "goal postback fired for the counted conversions, {event} = the goal's name", plog.length + ' attempts ' + (plog[0] ? plog[0].url : ''));
let plog = []; for (let i = 0; i < 30; i++) { await sleep(500); try { plog = JSON.parse(fs.readFileSync(path.join(DATA, 'postbacks.json'), 'utf8')).log.filter(l => l.event === 'subscriber'); } catch (e) {} if (plog.length >= 7) break; }
check(plog.length >= 7 && plog.every(l => /e=subscriber/.test(l.url)) && plog.some(l => l.lsid === id1), "goal postback fired for the counted conversions, {event} = the goal's name", plog.length + ' attempts ' + (plog[0] ? plog[0].url : ''));
check(!plog.some(l => l.lsid === idSelf), "no postback for the advertiser's own click");
check(!plog.some(l => l.lsid === idOwnSpin || l.lsid === lsclkOf(bkOwn.headers.location)) && plog.some(l => l.lsid === idBs), 'no postback for own spin-link / Banner Spin clicks; the Banner Spin goal fired one');
const tjs = await req('GET', '/t.js'), cjs = await req('GET', '/cv.js');
let parses = true; try { new Function(tjs.text); new Function(cjs.text); } catch (e) { parses = false; }
check(tjs.status === 200 && /javascript/.test(tjs.headers['content-type']) && cjs.status === 200 && parses, 'the landing tag and script pixel are served and parse');