LinkSpin tracked links for text ads (Marty 2026-11-15): lstrack.js asks LinkSpin (POST LS_URL/api/partner/vab/links, net.v1 with NETWORK_SSO_SECRET, by network username) for a tracked link on the member's own LinkSpin account when they save their ad; /go/<ad> sends through it while it points at the ad's current link. "Track with LinkSpin" toggle on the ad form (default on), {clickid}/{placement} links not tracked, LinkSpin clicks on My page, counters in admin status. Fails soft (plain link) until LinkSpin ships the endpoint; a 2-minute sweep retries. Smoke 179/179 (17 new LinkSpin checks against a stand-in that starts down).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-15 06:20:32 -06:00
parent b71284e5c9
commit 4efc1239b0
18 changed files with 200 additions and 35 deletions
+17 -6
View File
@@ -30,6 +30,7 @@ const hubline = require('./hubline');
const proof = require('./proof');
const netsites = require('./netsites');
const vabnas = require('./vabnas');
const lstrack = require('./lstrack');
const PUB = path.join(__dirname, 'public');
const ADDR_RE = /^0x[0-9a-fA-F]{40}$/;
@@ -241,7 +242,7 @@ const server = http.createServer(async (req, res) => {
const a = store.ad(gm[1]); if (!a || a.status === 'removed') { res.writeHead(302, { Location: '/' }); return res.end(); }
const pl = String(u.searchParams.get('p') || '').slice(0, 20);
if (!isBot(req) && !limited(req, 'click', 600, 3600000)) { const vk = visitorKey(req); const s = session(req); wire.click(a, vk, wire.vtokenOk(vk, u.searchParams.get('v')), s ? s.address : null, pl); }
res.writeHead(302, { Location: clickLink(a, pl), 'Cache-Control': 'no-store', 'Referrer-Policy': 'origin' }); return res.end();
res.writeHead(302, { Location: lstrack.dest(a) || clickLink(a, pl), 'Cache-Control': 'no-store', 'Referrer-Policy': 'origin' }); return res.end(); // the member's LinkSpin tracked link when it is current (lstrack.js), else their own link
}
// a member page: viraladblitz.com/<network username>
const pm = PAGE_RE.exec(p);
@@ -350,7 +351,10 @@ const server = http.createServer(async (req, res) => {
const a = store.adOf(me); const lo = netVerified(m) ? await hubline.lineOf({ wallet: me }, C.lineSearch) : { ok: true, line: [] };
const line = []; for (const x of lo.line) { if (line.length >= C.levels) break; const la = x.wallet ? store.adOf(x.wallet) : null; line.push({ depth: x.depth, username: x.username, hasWallet: !!x.wallet, hasAd: !!(la && la.status === 'live') }); }
const page = m.username ? 'https://' + C.site + '/' + encodeURIComponent(m.username) : null;
return json(res, 200, { address: me, username: m.username, netVerified: netVerified(m), ad: a ? { id: a.id, headline: a.headline, line1: a.line1, line2: a.line2, link: a.link, status: a.status, views: a.views || 0, clicks: a.clicks || 0, vclicks: a.vclicks || 0, createdAt: a.createdAt } : null,
let ls = null; // LinkSpin tracking of the ad (lstrack.js): state, the tracked link, its clicks as LinkSpin counts them
if (a) { const stt = lstrack.state(a); ls = { on: lstrack.on(), track: a.track !== false, state: stt, link: stt === 'tracked' ? a.ls.link : null, clicks: null };
if (stt === 'tracked' && m.username) { const cs = await lstrack.clicks(m.username).catch(() => null); if (cs && cs[String(a.id)]) { const c0 = cs[String(a.id)]; ls.clicks = { hits: c0.hits || 0, hits30: c0.hits30 || 0, unique30: c0.unique30 || 0 }; } } }
return json(res, 200, { address: me, username: m.username, netVerified: netVerified(m), ad: a ? { id: a.id, headline: a.headline, line1: a.line1, line2: a.line2, link: a.link, status: a.status, views: a.views || 0, clicks: a.clicks || 0, vclicks: a.vclicks || 0, createdAt: a.createdAt, track: a.track !== false } : null, linkspin: ls,
boosts: wire.purchases().filter(b => b.buyer === me).sort((x, y) => (y.at || 0) - (x.at || 0)).map(wire.boostView), earned: myEarned(me), line: line.slice(0, 8), lineOk: lo.ok,
page, joinUrl: joinUrl(''), boost: C.boost });
}
@@ -367,10 +371,14 @@ const server = http.createServer(async (req, res) => {
const lk = safety.checkLink(b.link, 'Your link'); if (lk.error) return json(res, 400, lk);
const cur = store.adOf(me);
if (C.linkProbe && (!cur || cur.link !== lk.url)) { const pr = await safety.probeLink(lk.url, { frames: false }); if (pr.error) return json(res, 400, pr); }
if (cur) { Object.assign(cur, { headline, line1, line2, link: lk.url, status: cur.status === 'paused' ? 'paused' : 'live' }); store.saveAd(cur); return json(res, 200, { ok: true, ad: { id: cur.id }, created: false }); }
const a = store.addAd({ owner: me, headline, line1, line2, link: lk.url, status: 'live', views: 0, clicks: 0, vclicks: 0 }); store.bump('adsPosted');
// "Track with LinkSpin" (default on): the ad's public link goes through the member's own LinkSpin tracked link (lstrack.js).
// LinkSpin is asked right away (at most 4 s); if it does not answer, the ad goes live with its own link and the sweep retries.
const track = b.track === undefined ? (cur ? cur.track !== false : true) : b.track !== false && b.track !== 'off' && b.track !== 0;
const lsNow = async x => { if (!lstrack.on() || x.track === false) return lstrack.state(x); await Promise.race([lstrack.ensureAd(x).catch(() => {}), new Promise(r => setTimeout(r, 4000).unref())]); return lstrack.state(x); };
if (cur) { Object.assign(cur, { headline, line1, line2, link: lk.url, track, status: cur.status === 'paused' ? 'paused' : 'live' }); if (cur.link !== (cur.ls && cur.ls.url)) delete cur.lsTry; store.saveAd(cur); return json(res, 200, { ok: true, ad: { id: cur.id }, created: false, linkspin: await lsNow(cur) }); }
const a = store.addAd({ owner: me, headline, line1, line2, link: lk.url, track, status: 'live', views: 0, clicks: 0, vclicks: 0 }); store.bump('adsPosted');
wire.attachPending(me, a.id);
return json(res, 200, { ok: true, ad: { id: a.id }, created: true });
return json(res, 200, { ok: true, ad: { id: a.id }, created: true, linkspin: await lsNow(a) });
}
// a Boost: the buy() call for the member's own wallet, with a fresh line voucher when the line is not bound on chain yet
if (p === '/api/my/order' && req.method === 'POST') {
@@ -405,7 +413,7 @@ const server = http.createServer(async (req, res) => {
today: store.today(), totals: S.totals, members: store.members().length, ads: { live: store.liveAds().length, all: store.ads().length },
boosts: { orders: B.length, views: B.reduce((t, b) => t + b.views, 0), delivered: B.reduce((t, b) => t + b.delivered, 0), active: B.filter(b => b.remaining > 0).length, late: B.filter(b => b.status === 'finishing-in-network').length, waitingForAd: B.filter(b => b.status === 'waiting-for-ad').length },
rows: { visits: store.visits().length, clicks: store.clicks().length, boostViews: store.bviews().length },
shop: shop.view(), proof: proof.view(), hub: hubreport.view(), hubLookup: hubpeople.view(), nas: vabnas.view(), docstore: docstore.view(), oldrefs: Object.keys(oldRefMap()).length });
shop: shop.view(), proof: proof.view(), hub: hubreport.view(), hubLookup: hubpeople.view(), nas: vabnas.view(), linkspin: lstrack.view(), docstore: docstore.view(), oldrefs: Object.keys(oldRefMap()).length });
}
if (p === '/api/admin/boosts' && req.method === 'GET') return json(res, 200, { boosts: wire.purchases().map(x => Object.assign(wire.boostView(x), { buyer: x.buyer, usdCents: x.usdCents, weiPaid: x.weiPaid, pays: x.pays || null, over: x.over || null })).sort((a, b) => (b.at || 0) - (a.at || 0)) });
if (p === '/api/admin/oldrefs' && req.method === 'POST') {
@@ -458,6 +466,9 @@ const server = http.createServer(async (req, res) => {
shop.init(C);
vabnas.init({ boosts: () => wire.purchases(), remaining: b => wire.remaining(b), ad: id => store.ad(id) });
setInterval(() => { if (store.prune()) wire.rebuild(); }, 3600000).unref();
lstrack.init(C, store); // LinkSpin tracked links for text ads: retry sweep (fails soft while LinkSpin is down or does not know the endpoint)
{ let busy = false; const tick = () => { if (busy) return; busy = true; lstrack.sweep(25).catch(() => {}).finally(() => { busy = false; }); };
setTimeout(tick, Number(process.env.LS_SWEEP_FIRST_MS || 20000)).unref(); setInterval(tick, Number(process.env.LS_SWEEP_MS || 120000)).unref(); }
server.listen(C.port, () => console.log('ViralAdBlitz on :' + C.port + ', Boost $' + C.boost.usd + ' = ' + C.boost.views + ' views, store: ' + (docstore.isOn() ? 'MySQL documents' : 'files (prototype mode)')));
})().catch(e => { console.error('start failed:', e.message); process.exit(1); });
process.on('SIGINT', () => { store.flush(); process.exit(0); });