Conversion linkage, LinkSpin side (Marty 2026-11-07, "Yes ship these"): InstantAdPay's sign-ups, wallet links and package purchases on a click count for the click's owner, in one Conversions list. Reporting only: no sponsor, payout, credit or chain path changes.

The landing tag (t.js) adds the kept click id to links to linkspin.app, instantadpay.com and the share domains, also inside a member's own redirect link (Orlando's buttons are go.opgnetwerk.com/go?u=<encoded join link>). Spin and Banner Spin links are left alone and only LinkSpin's own id shapes travel. A spin link or Banner Spin pointed straight at those sites carries lsclk with no goal set up.

netconv.js: new partner op 'events' on /api/partner/conv. Append-only ledger DATA_DIR/netconv.jsonl so two app copies cannot overwrite each other, marks.claim plus the ledger keys for once-only, join and wallet once per root click, every purchase by its own key, 30 days from click to event, the first account on a click owns it, the click owner's own account and own clicks kept as tests, each row keeps what the click was so later events survive the hit ageing out of the rotator. Spin events mirror into rotator.conv (replayed on a timer) so per-link counts, sources and placements see them; postbacks fire as for LinkSpin's own conversions.

Reports > Conversions lists goals, joins, wallets, purchases, leads and partner postbacks with values, each once; per-link Conv. counts include goals. /join keeps lsclk as well as lsid. Guide, /conversions, privacy and chatbot (CANNED + FACTS) updated; reports.js and join.js tags bumped.

The false Pages webhook claim is gone from chatbot.js, join.js and the home page: leads go to the member's list and CSV, or into a pasted autoresponder form.

QA: bash qa/run.sh netconv (57 checks, also runs in member).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-07 07:46:43 -06:00
parent 01ef4e9260
commit eedc15bc13
18 changed files with 456 additions and 34 deletions
+16 -7
View File
@@ -65,6 +65,7 @@ const rotator = require('./rotator');
const health = require('./health'); // destination health checks + auto-pause (2026-10-10)
const postbacks = require('./postbacks'); // outbound + inbound conversion postbacks on rotator clicks (2026-09-29)
const convtrack = require('./convtrack'); // conversion pixel: goals, ad click ids, landing tag + goal pixel, per-goal reports (2026-10-23)
const netconv = require('./netconv'); // network conversions: InstantAdPay's joins, wallets, purchases counted for the click's owner, reporting only (2026-11-07)
const marks = require('./marks'); // one-time claims shared by both app copies during a deploy (event_marks or exclusive files), 2026-10-24
const refill = require('./refill');
const refuel = require('./refuel');
@@ -706,7 +707,7 @@ async function boot() {
setTimeout(() => iapsync.tick().catch(e => console.error('iapsync', e.message)), 2 * 60 * 1000);
setInterval(() => iapsync.tick().catch(e => console.error('iapsync', e.message)), 2 * 60 * 1000);
const ownHosts = () => [SITE_HOST].concat(String(siteConfig().linkDomains || '').split(',').map(x => x.trim().toLowerCase()).filter(Boolean), pagesHost() ? [pagesHost()] : []);
rotator.init({ dataDir: DATA_DIR, geo, ownHosts, sources, wantsClickId: owner => convtrack.goalsOf(owner).length > 0 });
rotator.init({ dataDir: DATA_DIR, geo, ownHosts, sources, wantsClickId: owner => convtrack.goalsOf(owner).length > 0, isNetworkHost: h => networkHosts().includes(String(h || '').toLowerCase().replace(/^www\./, '')), goalRows: () => convtrack.goalRows() });
convtrack.init({ dataDir: DATA_DIR, rotator, bannerspin, campaignOf: id => ads.campaignById(id) });
auth.onSeen((email, req) => convtrack.noteSession(email, req)); // own-click tests (2026-10-26): the soft keys a member signs in from
// destination health: every 30 min, first pass 2 min after boot; a pause lands in the owner's on-site inbox (same path as the payment notices)
@@ -715,8 +716,9 @@ async function boot() {
setInterval(() => health.tick().catch(e => console.error('health', e.message)), 30 * 60 * 1000);
setInterval(() => { try { rotator.sweepDemos(); } catch (e) {} }, 60 * 60 * 1000); // unclaimed home-page demo spins expire after 24 h
postbacks.init({ dataDir: DATA_DIR, ownHosts, rotator, sources });
bannerspin.init({ dataDir: DATA_DIR, uploadsDir: UPLOADS_DIR, rotator, geo, sources, ownHosts, adminEmail: ADMIN_EMAIL, facts: bannerFacts, wantsClickId: owner => convtrack.goalsOf(owner).length > 0, withClickId: convtrack.withClickId });
rotator.setExternalConvert((lsid, ev, facts) => bannerspin.convert(lsid, ev, facts)); // Banner Spin click ids convert like spin-link clicks
bannerspin.init({ dataDir: DATA_DIR, uploadsDir: UPLOADS_DIR, rotator, geo, sources, ownHosts, adminEmail: ADMIN_EMAIL, facts: bannerFacts, wantsClickId: (owner, url) => { if (convtrack.goalsOf(owner).length > 0) return true; try { return networkHosts().includes(new URL(url).hostname.toLowerCase().replace(/^www\./, '')); } catch (e) { return false; } }, withClickId: convtrack.withClickId });
rotator.setExternalConvert((lsid, ev, facts) => /^[ai]/.test(String(lsid)) ? netconv.fromLinkSpin(lsid, ev, facts) : bannerspin.convert(lsid, ev, facts)); // Banner Spin click ids convert like spin-link clicks; ad clicks through the ledger
netconv.init({ dataDir: DATA_DIR, convtrack, rotator, bannerspin, postbacks, marks });
sources.init({ dataDir: DATA_DIR, postbacks, rotator, catalogFile: path.join(ROOT, 'catalog', 'traffic-sources.json'), linkHost: () => { const hs = String(siteConfig().linkDomains || '').split(',').map(x => x.trim()).filter(Boolean); return hs[0] || SITE_HOST; } });
zones.init({ dataDir: DATA_DIR, ads, siteHost: SITE_HOST });
pages.init({ dataDir: DATA_DIR, ownHosts, imageBase: () => (IS_PROD ? 'https' : 'http') + '://' + SITE_HOST, openrouterKey: () => { if (process.env.OPENROUTER_API_KEY) return process.env.OPENROUTER_API_KEY.trim(); try { return fs.readFileSync(path.join(DATA_DIR, 'openrouter.key'), 'utf8').trim(); } catch (e) { return ''; } } });
@@ -881,6 +883,9 @@ function readRaw(req, maxBytes) {
// on the member's thank-you page) can still send it where the browser allows third-party cookies; 30 days like the window.
// the image pixel cannot read the thank-you page's address, but a browser that sends the full referrer hands it to us
function refClickId(req) { try { const r = new URL(String(req.headers.referer || '')); const v = r.searchParams.get('lsclk') || r.searchParams.get('lsid') || ''; return /^[a-z0-9]{6,24}$/i.test(v) ? v : ''; } catch (e) { return ''; } }
// the sites of the network a click id may travel to (the landing tag's list, 2026-11-07): this site, InstantAdPay, its share domains
const NETWORK_HOSTS = String(process.env.NETWORK_HOSTS || 'instantadpay.com,instantadpay.link,ctbgo.com,mylinehq.com').split(',').map(x => x.trim().toLowerCase()).filter(Boolean);
function networkHosts() { return [...new Set([String(SITE_HOST || '').toLowerCase().replace(/:\d+$/, '').replace(/^www\./, '')].concat(NETWORK_HOSTS))].filter(Boolean); }
function clickCookie(id) { return 'ls.clk=' + id + '; Path=/; Max-Age=2592000; ' + (IS_PROD ? 'SameSite=None; Secure' : 'SameSite=Lax'); }
// an ad click: record a click id for the campaign and append ?lsclk=<id> to the target (existing params kept, an lsclk
// already there left alone). A spin-link target passes it on, so the spin-link click inherits the ad as its source.
@@ -1434,7 +1439,7 @@ const server = http.createServer(async (req, res) => {
// -- conversion pixel (2026-10-23): /t.js the landing tag, /t.gif its beacon, /cv.gif + /cv.js the goal pixel. Any origin,
// never cached, always a 1x1 gif (the member's page never sees an error). X-LS-Result says what happened (tests, debugging).
if ((p === '/t.js' || p === '/cv.js') && (req.method === 'GET' || req.method === 'HEAD')) {
try { const body = fs.readFileSync(path.join(PUBLIC_DIR, p.slice(1))); res.writeHead(200, { 'Content-Type': 'application/javascript; charset=utf-8', 'Cache-Control': 'public, max-age=300', 'Access-Control-Allow-Origin': '*', 'X-Content-Type-Options': 'nosniff' }); return res.end(req.method === 'HEAD' ? '' : body); } catch (e) { res.writeHead(404); return res.end(); }
try { let body = fs.readFileSync(path.join(PUBLIC_DIR, p.slice(1))); if (p === '/t.js') body = String(body).replace(/\/\*ls-net\*\/.*?\/\*ls-net\*\//, JSON.stringify(networkHosts())); res.writeHead(200, { 'Content-Type': 'application/javascript; charset=utf-8', 'Cache-Control': 'public, max-age=300', 'Access-Control-Allow-Origin': '*', 'X-Content-Type-Options': 'nosniff' }); return res.end(req.method === 'HEAD' ? '' : body); } catch (e) { res.writeHead(404); return res.end(); }
}
if ((p === '/t.gif' || p === '/cv.gif') && req.method === 'GET') {
const h = { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store, private', 'Content-Length': String(PIXEL_GIF.length), 'Access-Control-Allow-Origin': '*', 'Access-Control-Expose-Headers': 'X-LS-Result', 'X-Robots-Tag': 'noindex' };
@@ -1570,7 +1575,7 @@ const server = http.createServer(async (req, res) => {
const cookieTail = `; Path=/; SameSite=Lax; Max-Age=${30 * 24 * 3600}${IS_PROD ? '; Secure' : ''}`; // 30 days: whoever brings them back gets the credit
const set = [];
set.push('iap.sponsor=' + tok + cookieTail); // last touch wins
{ const lsid = String(u.searchParams.get('lsid') || ''); if (/^[a-z0-9]{6,20}$/i.test(lsid)) set.push('ls.click=' + lsid + cookieTail); } // the rotator click that brought them (postback attribution)
{ const lsid = String(u.searchParams.get('lsid') || u.searchParams.get('lsclk') || ''); if (/^[a-z0-9]{6,20}$/i.test(lsid)) set.push('ls.click=' + lsid + cookieTail); } // the rotator click that brought them (postback attribution); lsclk is what the landing tag carries from a bridge page (2026-11-07)
const promo = promos.norm(u.searchParams.get('promo')); if (promo) set.push('iap.promo=' + promo + cookieTail); // partner code, redeemed at signup
if (ang) set.push('iap.angle=' + angle + cookieTail);
if (!cookies['iap.ref']) set.push('iap.ref=' + encodeURIComponent(coach.refHost(req.headers.referer)) + cookieTail); // first-touch source
@@ -2850,7 +2855,9 @@ const server = http.createServer(async (req, res) => {
const [spins, pg, zn] = await Promise.all([rotator.summary(s.email, days), pages.summary(s.email, days), zonereport.summary(s.email, days)]);
// Banner Spins beside spin links (phase 3, 2026-10-20)
let bsum = null; try { bsum = await bannerspin.summary(s.email, days); } catch (e) { console.error('bannerspin summary', e.message); }
return json(res, 200, Object.assign({}, spins, { spins, pages: pg, zones: zn, bannerSpins: bsum, days: spins.days, range: days }), { 'Cache-Control': 'no-store' });
// one Conversions panel (2026-11-07): site + network events and goals, each once; the tiles follow the same counts
const uni = netconv.unified(s.email, days);
return json(res, 200, Object.assign({}, spins, { spins, pages: pg, zones: zn, bannerSpins: bsum, days: spins.days, range: days, conversions: uni.rows, totals: Object.assign({}, spins.totals, { joins: uni.joins, wallets: uni.wallets, purchases: uni.buyers, purchaseCount: uni.purchases, goals: uni.goals }) }), { 'Cache-Control': 'no-store' });
}
// -- conversion pixel (2026-10-23): goals, per-goal reports, CSV, test. GET and POST (the shell's api() always POSTs).
if (p === '/api/my/conversions' && (req.method === 'GET' || req.method === 'POST')) {
@@ -2992,9 +2999,11 @@ const server = http.createServer(async (req, res) => {
if (p === '/api/partner/conv' && req.method === 'POST') {
const sg = await readPartnerSigned(req, 64000); if (!sg.body) return json(res, sg.status, { error: sg.error });
const b = sg.body; const email = String(b.email || '').trim().toLowerCase();
// InstantAdPay's sign-ups, wallet links and purchases on a LinkSpin click (2026-11-07, reporting only): one answer per event
if (b.op === 'events') { const results = []; for (const ev of (Array.isArray(b.events) ? b.events.slice(0, 200) : [])) { let r = { result: 'bad' }; try { r = await netconv.record(ev); } catch (e) { console.error('netconv', e.message); return json(res, 500, { error: 'not recorded' }); } results.push({ k: String(ev && ev.k || '').slice(0, 120), result: r.result }); } return json(res, 200, { ok: true, results }); }
if (!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email) || email.length > 190) return json(res, 400, { error: 'Which member?' });
let r;
if (b.op === 'summary') r = Object.assign(convtrack.partnerSummary(email, b.days), { host: SITE_HOST });
if (b.op === 'summary') r = Object.assign(convtrack.partnerSummary(email, b.days), { host: SITE_HOST, network: netconv.partner(email, b.days) });
else if (b.op === 'create') r = convtrack.createGoal(email, { name: b.name, value: b.value });
else if (b.op === 'update') r = convtrack.updateGoal(email, b.px, { name: b.name, value: b.value === null ? 0 : b.value }); // null = clear the default (InstantAdPay sends it for an empty box)
else if (b.op === 'remove') r = convtrack.updateGoal(email, b.px, { remove: true });