Network sites as LinkSpin traffic sources (Marty 2026-11-14: "Make sure each of these sites is its own traffic source and link spun so we can track it"). Catalog: InstantAdPay, LinkSpin, Stack POL, Earners Corner network templates (next to Downline Banners and Viral Banner Blitz). A spin-link click with ?src=<site id> (iap, linkspin, dlb, vbb, stackpol, earnerscorner) counts under the link owner's source for that site, made from the template on first use (network templates only, no postback, so no network hears of a click it did not send; no referrer = the site's name as referrer). netlinks.js: at boot the admin account gets one fixed network link per site, made once when missing: nwiap, nwls, nwdlb, nwvbb, nwsp, nwec -> https://<site>/{s2}?ref={s1} (Earners Corner without ref), so every site links to the others as linkspin.app/r/<code>?src=<sender>&s1=<member>&s2=<page>. Health checks probe a destination with its {macros} empty, as a click with no params lands. netsites.js: /api/network-sites adds go (the tracked link with ?src=linkspin); common.js + netline.js footers use it (rel nofollow). common.js?v=20261114ns, netline.js?v=20261114ns. qa: netsrc 16/16 (new, bash qa/run.sh netsrc), member 57 passed 0 failed, partner-spins 13/13, netconv 57/57, lsid 31/31

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-14 11:39:34 -06:00
parent 9025057128
commit a630979a3a
35 changed files with 226 additions and 39 deletions
+16 -2
View File
@@ -142,6 +142,16 @@ async function update(owner, id, body) {
if (body.sourceId !== undefined) { const sid = String(body.sourceId || '').trim(); if (!sid) delete r.sourceId; else { if (!/^[a-f0-9]{10}$/.test(sid) || !SOURCES || !SOURCES.find(owner, sid)) return { error: 'No such source.' }; r.sourceId = sid; } }
J.save(); return { ok: true, rotation: pub(r) };
}
// a link with a fixed code for an internal owner (netlinks.js, 2026-11-14): made once with one destination, never changed after
// (the owner may edit it like any link). Fixed codes are 4-5 characters, so a random 6-character code can never take one.
function ensureFixed(owner, code, name, url) {
const c = norm(code); if (!/^[a-z0-9]{4,5}$/.test(c)) return { error: 'code' };
const have = J.db.rotations.find(r => r.code === c);
if (have) return have.owner === norm(owner) ? { ok: true, rotation: have, created: false } : { error: 'taken' };
const u = cleanUrl(url); if (!u) return { error: 'url' };
const r = { id: (J.db.rotations.reduce((m, x) => Math.max(m, x.id), 0) + 1), owner: norm(owner), name: String(name).slice(0, 80), code: c, fallback: '', destinations: [{ id: 1, url: u, label: '', weight: 1, active: true, added: Date.now() }], created: Date.now(), paused: false, nextDest: 2 };
J.db.rotations.push(r); J.save(); return { ok: true, rotation: r, created: true };
}
async function remove(owner, id) { const n = J.db.rotations.length; J.db.rotations = J.db.rotations.filter(r => !(r.id === Number(id) && r.owner === norm(owner))); J.save(); return n !== J.db.rotations.length ? { ok: true } : { error: 'No such rotation.' }; }
// opts.max: the admin import path only (BTC4Hits rotators, 2026-11-11) may go past the 25 a member can add, up to IMPORT_MAX
const DEST_MAX = 25, IMPORT_MAX = 2000;
@@ -196,9 +206,13 @@ async function resolve(code, req) {
const device = /mobile|android|iphone|ipad/i.test(ua) ? 'mobile' : 'desktop';
// click ids and sub ids that rode in on the link (tracker / traffic-network params), kept per click
const q = {}; try { const sp = new URL(req.url, 'http://x').searchParams; let n = 0; for (const [k, val] of sp) { const key = String(k).toLowerCase(); if (n >= 20) break; if (/^(clickid|click_id|cid|subid|sub_id|s[1-5]|sub[1-5]|t[1-5]|aff_sub[1-5]?|utm_(source|medium|campaign|term|content)|src|source|campaign|zone|placement|cost|creative|site|banner|keyword|geo|os|browser|device|carrier|format|external_id|visitor_id)$/.test(key)) { q[key] = String(val).slice(0, 200); n++; } } } catch (e) {}
// a network site sent this click (?src=dlb, 2026-11-14): it counts under the owner's source for that site, even on a link with
// another source attached (the network template has no postback, so no network is told about a click it did not send)
let sr = r.sourceId || undefined;
try { const ns = q.src && SOURCES && SOURCES.networkSource ? SOURCES.networkSource(r.owner, q.src) : null; if (ns) { sr = ns.id; if (src === 'direct' && ns.site) src = ns.site; } } catch (e) {}
const id = crypto.randomBytes(6).toString('hex').slice(0, 10);
// sr = the traffic source attached to the link at click time, so the network that sent this click is the one told about its conversion
J.db.hits.push({ id, r: r.id, d: d ? d.id : 0, ts: Date.now(), v, c: country, s: src, dv: device, bot: bot ? 1 : 0, oh: off ? 1 : undefined, q: Object.keys(q).length ? q : undefined, sr: r.sourceId || undefined, ac: ac || undefined });
J.db.hits.push({ id, r: r.id, d: d ? d.id : 0, ts: Date.now(), v, c: country, s: src, dv: device, bot: bot ? 1 : 0, oh: off ? 1 : undefined, q: Object.keys(q).length ? q : undefined, sr, ac: ac || undefined });
if (HIT_IX) HIT_IX.set(id, J.db.hits.length - 1);
if (docstore.isOn()) { const h = J.db.hits[J.db.hits.length - 1]; docstore.rowPut('rot_hits', h.id, h.ts, h); } // memory keeps the newest 200k, MySQL keeps every click
if (J.db.hits.length > 200000) { J.db.hits = J.db.hits.slice(-150000); HIT_IX = null; }
@@ -352,4 +366,4 @@ function adminAll() {
hits: o.hits, hits7: o.hits7, bots: o.bots, conversions: cv[r.id] || 0 }; });
}
module.exports = { init, convRows, adminAll, hitById, list, get, create, update, remove, addDest, updateDest, resolve, stats, totals, convert, summary, createDemo, claim, sweepDemos, servedToday, window24,
pub, rawRotations, save, findMine, setExternalConvert, PRESETS, cleanHours, cleanTz, cellAt, zoneFor, isOn, COUNTRY_TZ, sourceCounts, detachSource };
pub, rawRotations, save, findMine, setExternalConvert, PRESETS, cleanHours, cleanTz, cellAt, zoneFor, isOn, COUNTRY_TZ, sourceCounts, detachSource, ensureFixed };