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:
+19
-9
@@ -13,6 +13,7 @@ const crypto = require('crypto');
|
||||
|
||||
let DATA_DIR = null, geo = null, OWN_HOSTS = () => [], SOURCES = null; // SOURCES = sources.js (traffic sources, 2026-10-12)
|
||||
let WANTS_CLICK_ID = () => false; // conversion pixel (2026-10-23): owner -> true when they have a goal, so their destinations get ?lsclk=
|
||||
let IS_NETWORK = () => false, GOAL_ROWS = () => []; // 2026-11-07: a page on a network host always gets the click id (InstantAdPay reports joins, wallets, purchases against it); goal conversions as rotator-shaped rows for per-link counts
|
||||
const DAY = 86400000;
|
||||
const J = {
|
||||
db: null,
|
||||
@@ -20,7 +21,8 @@ const J = {
|
||||
load() { try { this.db = JSON.parse(fs.readFileSync(this.FILE(), 'utf8')); } catch (e) { this.db = { v: 1, rotations: [], hits: [], conv: [] }; } if (!this.db.conv) this.db.conv = []; },
|
||||
save() { try { fs.writeFileSync(this.FILE(), JSON.stringify(this.db)); } catch (e) {} }
|
||||
};
|
||||
function init(opts) { DATA_DIR = opts.dataDir; geo = opts.geo || null; OWN_HOSTS = opts.ownHosts || (() => []); SOURCES = opts.sources || null; if (opts.wantsClickId) WANTS_CLICK_ID = opts.wantsClickId; J.load(); }
|
||||
function init(opts) { DATA_DIR = opts.dataDir; geo = opts.geo || null; OWN_HOSTS = opts.ownHosts || (() => []); SOURCES = opts.sources || null; if (opts.wantsClickId) WANTS_CLICK_ID = opts.wantsClickId; if (opts.isNetworkHost) IS_NETWORK = opts.isNetworkHost; if (opts.goalRows) GOAL_ROWS = opts.goalRows; J.load(); }
|
||||
const convOf = (rid) => J.db.conv.filter(c => c.r === rid).concat(GOAL_ROWS().filter(c => c.r === rid)); // a link's conversions: site and network events, and goals
|
||||
const norm = e => String(e || '').trim().toLowerCase();
|
||||
const newCode = () => { const a = 'abcdefghjkmnpqrstuvwxyz23456789'; let s = ''; for (let i = 0; i < 6; i++) s += a[crypto.randomInt(a.length)]; return s; };
|
||||
const BOT = /bot|crawl|spider|slurp|facebookexternalhit|preview|telegrambot|whatsapp|curl|wget|python-requests|headless/i;
|
||||
@@ -83,7 +85,7 @@ function pub(r) {
|
||||
const since7 = Date.now() - 7 * DAY;
|
||||
const perDest = {};
|
||||
for (const h of hits) { const d = perDest[h.d] = perDest[h.d] || { hits: 0, hits7: 0, uniques: new Set() }; d.hits++; if (h.ts >= since7) d.hits7++; d.uniques.add(h.v); }
|
||||
const conv = J.db.conv.filter(c => c.r === r.id); const convBy = {}; for (const c of conv) convBy[c.ev] = (convBy[c.ev] || 0) + 1;
|
||||
const conv = convOf(r.id); const convBy = {}; for (const c of conv) convBy[c.ev] = (convBy[c.ev] || 0) + 1;
|
||||
const since30 = Date.now() - 30 * DAY;
|
||||
return { id: r.id, code: r.code, name: r.name, owner: r.owner, created: r.created, fallback: r.fallback || '', paused: !!r.paused, conversions: conv.length, convBy,
|
||||
hours: r.hours || null, tz: r.tz || 'visitor', offHours30: hits.filter(h => h.oh && h.ts >= since30 && !h.bot).length, fallbackHealth: r.fallbackHealth || null, sourceId: r.sourceId || '',
|
||||
@@ -191,19 +193,27 @@ async function resolve(code, req) {
|
||||
try { const t = new URL(out); if (OWN_HOSTS().includes(t.hostname.toLowerCase()) && !t.searchParams.has('lsid')) { t.searchParams.set('lsid', id); out = t.toString(); } } catch (e) {}
|
||||
// conversion pixel (2026-10-23): when the owner tracks goals, or the click came from an ad, the destination also gets
|
||||
// ?lsclk=<this click id> for the landing tag (/t.js) to keep. Existing params stay; an lsclk already there is left alone.
|
||||
if (!bot && (ac || WANTS_CLICK_ID(r.owner))) { try { const t = new URL(out); if (!t.searchParams.has('lsclk')) { t.searchParams.set('lsclk', id); out = t.toString(); } } catch (e) {} }
|
||||
if (!bot) { try { const t = new URL(out); if ((ac || WANTS_CLICK_ID(r.owner) || IS_NETWORK(t.hostname)) && !t.searchParams.has('lsclk')) { t.searchParams.set('lsclk', id); out = t.toString(); } } catch (e) {} }
|
||||
}
|
||||
return { url: out, dest: d, rotation: r, lsid: id };
|
||||
}
|
||||
// conversions: record an event against the click that brought the person (dedupe per click + event)
|
||||
// Banner Spin clicks (bannerspin.js, 2026-10-18) carry their own click ids ('k' + 11 hex); an id we do not know is handed to it
|
||||
let EXT_CONVERT = null; function setExternalConvert(fn) { EXT_CONVERT = fn; }
|
||||
// facts.key (netconv.js, 2026-11-07): every purchase InstantAdPay reports counts by its own key, not once per click; facts.bound =
|
||||
// the click as first recorded, so an event still lands on its link after the hit aged out of the array
|
||||
async function convert(lsid, ev, facts) {
|
||||
const h = J.db.hits.find(x => x.id === String(lsid)); if (!h) return EXT_CONVERT ? EXT_CONVERT(lsid, ev, facts) : null;
|
||||
const f = facts || {}; const key = f.key ? String(f.key) : ''; const id = String(lsid);
|
||||
let h = J.db.hits.find(x => x.id === id);
|
||||
if (!h && f.bound && f.bound.r) h = { id, r: f.bound.r, d: f.bound.d, sr: f.bound.sr };
|
||||
if (!h) return EXT_CONVERT ? EXT_CONVERT(lsid, ev, facts) : null;
|
||||
const r = J.db.rotations.find(x => x.id === h.r); if (!r) return null;
|
||||
if (!J.db.conv.some(c => c.lsid === h.id && c.ev === ev)) { J.db.conv.push({ lsid: h.id, r: r.id, d: h.d, ev, ts: Date.now(), value: Number(facts && facts.payout || 0) || 0, label: facts && facts.label ? String(facts.label).slice(0, 40) : undefined, sr: h.sr || undefined }); if (J.db.conv.length > 100000) J.db.conv = J.db.conv.slice(-80000); J.save(); }
|
||||
const dup = J.db.conv.some(c => key && ev === 'purchase' ? c.key === key : (c.lsid === h.id && c.ev === ev && (ev !== 'purchase' || !c.key)));
|
||||
if (!dup) { J.db.conv.push({ lsid: h.id, r: r.id, d: h.d, ev, ts: Number(f.ts) || Date.now(), value: Number(f.payout || 0) || 0, label: f.label ? String(f.label).slice(0, 40) : undefined, sr: h.sr || undefined, key: key || undefined }); if (J.db.conv.length > 100000) J.db.conv = J.db.conv.slice(-80000); J.save(); }
|
||||
return { owner: r.owner, code: r.code, rotationId: r.id, q: h.q || {}, s: h.s, c: h.c, dv: h.dv, sourceId: h.sr || '' };
|
||||
}
|
||||
// a member's conversions as rows (Reports' one Conversions panel, netconv.unified): goals are added there, never here
|
||||
function convRows(owner, since) { const ids = new Set(J.db.rotations.filter(r => r.owner === norm(owner)).map(r => r.id)); return J.db.conv.filter(c => ids.has(c.r) && c.ts >= since); }
|
||||
// clicks, uniques and conversions per traffic source over `days` (non-bot), keyed by source id; for the Sources screen and Reports
|
||||
async function sourceCounts(owner, days) {
|
||||
const mine = J.db.rotations.filter(r => r.owner === norm(owner)); const ids = new Set(mine.map(r => r.id));
|
||||
@@ -211,7 +221,7 @@ async function sourceCounts(owner, days) {
|
||||
const at = sid => (out[sid] = out[sid] || { hits: 0, unique: new Set(), conv: 0, links: 0 });
|
||||
for (const r of mine) if (r.sourceId) at(r.sourceId).links++;
|
||||
for (const h of J.db.hits) if (h.sr && ids.has(h.r) && h.ts >= since && !h.bot) { const o = at(h.sr); o.hits++; o.unique.add(h.v); }
|
||||
for (const c of J.db.conv) if (c.sr && ids.has(c.r) && c.ts >= since) at(c.sr).conv++;
|
||||
for (const c of J.db.conv.concat(GOAL_ROWS())) if (c.sr && ids.has(c.r) && c.ts >= since) at(c.sr).conv++;
|
||||
for (const k in out) out[k].unique = out[k].unique.size;
|
||||
return out;
|
||||
}
|
||||
@@ -229,7 +239,7 @@ async function summary(owner, days) {
|
||||
const dayMap = {}; for (const h of all) { const k = ctDay(h.ts); const d = dayMap[k] = dayMap[k] || { day: k, u: new Set(), b: 0 }; if (h.bot) d.b++; else d.u.add(h.v); }
|
||||
const dlist = Object.values(dayMap).sort((a, b) => a.day < b.day ? -1 : 1).map(d => ({ day: d.day, u: d.u.size, b: d.b }));
|
||||
const hours = new Array(24).fill(0); for (const h of hits) hours[new Date(h.ts).getUTCHours()]++;
|
||||
const conv = J.db.conv.filter(c => ids.has(c.r) && c.ts >= since); const convBy = {}; for (const c of conv) convBy[c.ev] = (convBy[c.ev] || 0) + 1;
|
||||
const conv = J.db.conv.concat(GOAL_ROWS()).filter(c => ids.has(c.r) && c.ts >= since); const convBy = {}; for (const c of conv) convBy[c.ev] = (convBy[c.ev] || 0) + 1;
|
||||
const top = mine.map(r => { const hs = hits.filter(h => h.r === r.id); return { id: r.id, name: r.name, code: r.code, hits: hs.length, unique: new Set(hs.map(h => h.v)).size, conv: conv.filter(c => c.r === r.id).length }; }).sort((a, b) => b.unique - a.unique).slice(0, 10);
|
||||
// traffic sources (2026-10-12): per source, and per placement = the value the network's zone / placement / site macro carried
|
||||
const meta = SOURCES && SOURCES.meta ? SOURCES.meta(owner) : {};
|
||||
@@ -249,7 +259,7 @@ async function stats(owner, id) {
|
||||
const days = {}; for (const h of hits) { const k = new Date(h.ts).toISOString().slice(0, 10); days[k] = (days[k] || 0) + 1; }
|
||||
const hours = new Array(24).fill(0); for (const h of hits) hours[new Date(h.ts).getUTCHours()]++;
|
||||
const subs = {}; for (const h of hits) if (h.q) for (const [k, v] of Object.entries(h.q)) { const key = k + '=' + v; subs[key] = (subs[key] || 0) + 1; }
|
||||
const conv = J.db.conv.filter(c => c.r === r.id); const convBy = {}; for (const c of conv) { const k = c.ev + (c.label ? ' · ' + c.label : ''); convBy[k] = (convBy[k] || 0) + 1; }
|
||||
const conv = convOf(r.id); const convBy = {}; for (const c of conv) { const k = c.ev + (c.label ? ' · ' + c.label : ''); convBy[k] = (convBy[k] || 0) + 1; }
|
||||
return { rotation: pub(r), country: by('c'), source: by('s'), device: by('dv'), days: Object.entries(days).sort().slice(-30).map(([k, n]) => ({ day: k, n })), hours, bots: J.db.hits.filter(h => h.r === r.id && h.bot).length, best: bestHours(r), offHours: hits.filter(h => h.oh).length,
|
||||
subs: Object.entries(subs).sort((a, b) => b[1] - a[1]).slice(0, 12).map(([k, n]) => ({ k, n })), conversions: Object.entries(convBy).sort((a, b) => b[1] - a[1]).map(([k, n]) => ({ k, n })) };
|
||||
}
|
||||
@@ -322,5 +332,5 @@ function adminAll() {
|
||||
destinations: (r.destinations || []).map(d => ({ id: d.id, url: d.url, label: d.label || '', weight: d.weight, active: !!d.active, autoPaused: d.autoPaused || 0, health: d.health ? { state: d.health.state, note: d.health.note || '', checkedAt: d.health.checkedAt || 0 } : null })),
|
||||
hits: o.hits, hits7: o.hits7, bots: o.bots, conversions: cv[r.id] || 0 }; });
|
||||
}
|
||||
module.exports = { init, adminAll, hitById, list, get, create, update, remove, addDest, updateDest, resolve, stats, totals, convert, summary, createDemo, claim, sweepDemos, servedToday, window24,
|
||||
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 };
|
||||
|
||||
Reference in New Issue
Block a user