Traffic sources: network macros, campaign URLs, per-source postbacks, Reports dimension
A Source is a first-class record of a network a member buys traffic on (PropellerAds,
Zeropark, Adsterra, ExoClick and 25 more from the shipped catalog, or defined by hand).
It remembers the network's macro tokens and conversion postback, attaches to spin links,
builds the exact campaign URL to paste into the network, fires that network's own
postback only for clicks that came through it, and shows up in Reports by source and
by the zone / placement / site the macro carried.
- data/traffic-sources.json: catalog of 29 networks (BeMob template harvest), un-ignored
via data/* + !data/traffic-sources.json; loader tolerates missing fields, null costModel,
{{slot}} labels with spaces and parentheses, optional slots, unknown single-brace macros
- sources.js: DATA_DIR/sources.json model, 30 per account, 20 params, key allow-list,
postbacks.validateUrl on the filled postback; list/create/update/get/urlFor/test
- rotator.js: update() takes sourceId (owner-checked), pub() exposes it, hits and conversions
are stamped with the source at click time (sr), wider query allow-list (cost, creative,
site, banner, keyword, geo, os, browser, device, carrier, format, external_id, visitor_id),
summary() adds sources[] and placements[], sourceCounts(), detachSource()
- postbacks.js: fire() delivers the matching source's postback after the manual ones through
the same deliver() (guards, retry, rate cap, auto-disable); log rows carry source; convertFor,
inbound and the page lead path pass sourceId; fill/deliver/logForSource exported
- routes (GET and POST): /api/sources/catalog, /api/my/sources, /api/my/sources/<id>,
/api/my/sources/<id>/url; /sources screen
- /sources Control Room screen (list + Campaign URL / Postback / Settings tabs, two-step
New source dialog); Links share kit gets a source select and a "Campaign URL for <network>"
first row; Reports gets Traffic sources and Placements; rail entry; chatbot canned answer,
FACTS line and KNOWLEDGE_DATE 2026-10-12
- cr.css: phone rail icons only at 34px so ten entries fit; cache tags bumped to 20261012a
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
+4
-2
@@ -1,4 +1,6 @@
|
||||
node_modules/
|
||||
data/
|
||||
data/*
|
||||
*.log
|
||||
qa/out/
|
||||
qa/out/
|
||||
|
||||
!data/traffic-sources.json
|
||||
|
||||
+4
-1
@@ -16,6 +16,7 @@ let DATA_DIR = null;
|
||||
let chain = null;
|
||||
const MODEL = process.env.OPENROUTER_MODEL || 'deepseek/deepseek-v4-flash:nitro';
|
||||
const CONTRACT = '0x26Bdc556b94399bEdd69ae3ACA5aA6c54D946e8b';
|
||||
const KNOWLEDGE_DATE = '2026-10-12'; // the day the CANNED answers and FACTS below were last checked against the site
|
||||
|
||||
function init(opts) { DATA_DIR = opts.dataDir; chain = opts.chain; }
|
||||
function key() {
|
||||
@@ -40,6 +41,8 @@ const CANNED = [
|
||||
a: 'Level 1, half of every package your direct referrals buy, pays from their first qualifying purchase once your payouts are on. Level 2 (20 percent) opens after two of your people buy a qualifying package, $25 or larger. Level 3 (10 percent) opens after five. The $10 door package is for trying the ads and does not count toward opening levels. Until a level opens, its share passes up the line to the next qualified member, then to the platform, and it never comes back, so leaders qualify before their teams\' teams buy. Qualification is counted by the contract, never expires and cannot be bought.' },
|
||||
{ re: /(what('s| is) (a |an )?(ad )?zone|zones?\b|embed|script tag|publisher|site owner|my (own )?(web)?site|ad slot|viewable)/i,
|
||||
a: 'A zone is an ad slot on your own site: one script tag, nine standard sizes (728x90, 468x60, 300x250, 336x280, 250x250, 125x125, 160x600, 120x600, 320x50). Each load shows a LinkSpin member campaign first, then a network ad, then our house banner if nothing paid fits. You earn ad credits per viewable impression (half the banner on screen for one second, bots never, 50 credited views per visitor per zone per day): 1 credit per 5 viewable member-ad views and 1 per 10 network-ad views, or 1 per 8 on a Verified zone the admin has reviewed. A new zone earns after its first 100 on-site views with at least 40 percent viewable, and paid ads serve only on the site you declared, so copying the tag elsewhere earns nothing. Everything is explained at ' + SITE_URL + '/publishers and you add zones under Zones in your Control Room.' },
|
||||
{ re: /(traffic ?sources?|postback|macros?|propeller ?ads|zeropark|adsterra|exoclick|hilltop ?ads|rich ?ads|traffic ?stars|pop ?ads|campaign url|buy(ing)? traffic|paid traffic|ad network|s2s|conversion (pixel|tracking))/i,
|
||||
a: 'Sources, in your Control Room, is for traffic you buy on networks like PropellerAds, Zeropark, Adsterra or ExoClick. Pick the network from the catalog (or define your own), fill in your account details, and the source remembers that network\'s macros and conversion postback. Point a spin link at it and the Share kit gives you the exact campaign URL to paste into the network, macros included. When a click from that source joins, leaves a lead, links a wallet or buys, LinkSpin fires the network\'s own postback with its click id, so the network learns what converts, and Reports breaks clicks and conversions down by source and by the zone or placement the macro carried. The older account-level Postbacks on the Links screen still work for your tracker.' },
|
||||
{ re: /(spin ?link|rotat|short link|one link|weights?|fallback|split test|sub ?id|click ?id|daypart|health check|dead link|redirect)/i,
|
||||
a: 'A spin link is one short link that rotates between every page you promote. Behind it you set destinations with weights, pause any of them, and name a fallback for when everything else is off. Every click is recorded in one hop with the day, country, source and device, bots are filtered on the server, and click ids and sub ids (clickid, subid, s1 to s4 and the usual tracker names) ride through to the destination, so you can split-test by tagging the same link with different sub ids. Reports show it per link and across all of them. Set the hours of the day and week a spin or a destination runs (the local time of your visitor by default), and automatic health checks pause a dead or parked destination for you. You can try a spin with no account on the home page.' },
|
||||
{ re: /(page builder|bridge page|squeeze page|review page|sales page|advertorial|press release|landing page|build (a|me a) page|my pages?|lead capture|leads?\b)/i,
|
||||
@@ -85,7 +88,7 @@ function systemPrompt() {
|
||||
return `You are the assistant on LinkSpin (${SITE_URL}), a link rotator, page builder and advertising network for marketers, a Crypto Team Build Network property.
|
||||
|
||||
FACTS:
|
||||
- PRODUCT, all free with an email account: SPIN LINKS (the rotator: one short link, /r/<code>, rotates between destinations by weight; pause any destination; a fallback for when all are off; one-hop redirect; every click recorded with day, country, source, device and a daily-salted visitor hash; bots filtered on the server; click ids and sub ids such as clickid, subid, s1 to s4 pass through to the destination; split tests by tagging the same link with different sub ids; a demo spin on the home page needs no account; DAYPARTING is live: a 7x24 hours grid per spin and per destination, time zone by name or the local time of the visitor, presets, and 'my best hours' from the clicks of the member after 200 clicks; automatic HEALTH CHECKS are live: every destination is checked every 30 minutes, a dead or parked one is paused after three failing checks and resumed when it passes twice, the owner is told once, and Check now runs it on demand). PAGES (page builder: scan any offer URL, get a bridge, review or squeeze page; designs, palettes, layouts and niche presets with hero images; leads to the member's own list, CSV or webhook; published on the pages domain lookfirst.page; sales, advertorial and press-release layouts are coming). ZONES (an ad slot on the member's own site: one async script tag, nine sizes 728x90, 468x60, 300x250, 336x280, 250x250, 125x125, 160x600, 120x600, 320x50; waterfall = LinkSpin member campaign, then a network ad for 728x90 and 468x60, then the LinkSpin house banner; pays ad credits per VIEWABLE impression, half the banner on screen for one second, bots never, 50 credited views per visitor per zone per day; rates 1 credit per 5 viewable member-ad views and 1 per 10 network-ad views, 1 per 8 on a Verified zone; warm-up: a zone earns after its first 100 on-site views with at least 40 percent viewable and goes on hold below that; origin lock: paid ads serve only on the declared site and its subdomains, elsewhere the house banner shows and nothing is earned; up to 50 zones per account; PUBLISHER PROGRAM at /publishers for site owners, tiers Standard (default) and Verified (admin-reviewed site, better network rate)). AUDIENCES (first-party retargeting: "My visitors" collects everyone who viewed the member's pages and zones for 30 days; a pixel tag /p.js for other sites; campaigns can "show only to" or "never show to" an audience; nothing personal stored). PROMO TOOLS at /tools#promo (social posts, text-a-friend, email swipes, banners, objection bank, hook videos; five hook angles with videos: links, pages, zones, audiences, stack; angle links are the invite link plus ?v=). REPORTS (every link in one view). BLOG at /blog with RSS at /blog/feed.xml.
|
||||
- PRODUCT, all free with an email account: SPIN LINKS (the rotator: one short link, /r/<code>, rotates between destinations by weight; pause any destination; a fallback for when all are off; one-hop redirect; every click recorded with day, country, source, device and a daily-salted visitor hash; bots filtered on the server; click ids and sub ids such as clickid, subid, s1 to s4 pass through to the destination; split tests by tagging the same link with different sub ids; a demo spin on the home page needs no account; DAYPARTING is live: a 7x24 hours grid per spin and per destination, time zone by name or the local time of the visitor, presets, and 'my best hours' from the clicks of the member after 200 clicks; automatic HEALTH CHECKS are live: every destination is checked every 30 minutes, a dead or parked one is paused after three failing checks and resumed when it passes twice, the owner is told once, and Check now runs it on demand). PAGES (page builder: scan any offer URL, get a bridge, review or squeeze page; designs, palettes, layouts and niche presets with hero images; leads to the member's own list, CSV or webhook; published on the pages domain lookfirst.page; sales, advertorial and press-release layouts are coming). ZONES (an ad slot on the member's own site: one async script tag, nine sizes 728x90, 468x60, 300x250, 336x280, 250x250, 125x125, 160x600, 120x600, 320x50; waterfall = LinkSpin member campaign, then a network ad for 728x90 and 468x60, then the LinkSpin house banner; pays ad credits per VIEWABLE impression, half the banner on screen for one second, bots never, 50 credited views per visitor per zone per day; rates 1 credit per 5 viewable member-ad views and 1 per 10 network-ad views, 1 per 8 on a Verified zone; warm-up: a zone earns after its first 100 on-site views with at least 40 percent viewable and goes on hold below that; origin lock: paid ads serve only on the declared site and its subdomains, elsewhere the house banner shows and nothing is earned; up to 50 zones per account; PUBLISHER PROGRAM at /publishers for site owners, tiers Standard (default) and Verified (admin-reviewed site, better network rate)). AUDIENCES (first-party retargeting: "My visitors" collects everyone who viewed the member's pages and zones for 30 days; a pixel tag /p.js for other sites; campaigns can "show only to" or "never show to" an audience; nothing personal stored). PROMO TOOLS at /tools#promo (social posts, text-a-friend, email swipes, banners, objection bank, hook videos; five hook angles with videos: links, pages, zones, audiences, stack; angle links are the invite link plus ?v=). REPORTS (every link in one view, plus Pages, Zones, and since 2026-10-12 Traffic sources and Placements). BLOG at /blog with RSS at /blog/feed.xml. TRAFFIC SOURCES at /sources (2026-10-12): a source is a record of a network the member buys traffic on, created from a catalog of networks (PropellerAds, Zeropark, Adsterra, ExoClick, HilltopAds, TrafficStars, PopAds and more, with each network's macro tokens and conversion postback URL; account-specific slots such as a goal id are filled in at creation) or defined by hand; a spin link is pointed at one source (Share kit on the Links screen, or the Sources screen), and then the Share kit's first row is the exact campaign URL for that network with its macros already in place; when a click that came through that source converts (join, lead, wallet, purchase, or a partner-reported conversion; the member picks which) LinkSpin fires that network's own postback with the network's click id and the payout, server to server, and only the network that sent the click is told; Reports show clicks, uniques and conversions by source and by placement (the value the network's zone, placement, site, campaign, creative, banner or keyword macro carried); up to 30 sources per account, 20 params each; a source with no postback still builds the campaign URL and shows in Reports; the account-level Postbacks list on the Links screen (for the member's own tracker) still works alongside. Knowledge checked on ${KNOWLEDGE_DATE}.
|
||||
- PACKAGES (priced in dollars, settled in POL at the live rate, 1 credit = 1 cent of ad delivery): $10 door = 1,000 credits, for trying the ads, does NOT count toward qualification; $25 Starter = 2,500; $50 Builder = 5,000; $100 Growth = 10,000; $250 Leader = 25,000; $500 Network = 50,000. Any package of $25 or more makes the buyer a qualifying buyer for their sponsor.
|
||||
- THE SPLIT, same transaction on Polygon, fixed in the contract: 50 percent direct sponsor, 20 percent level 2, 10 percent level 3, 10 percent + 10 percent to the two admin wallets. Level 1 pays from a referral's first qualifying purchase once the sponsor's payouts are on. Level 2 opens after two of the member's people buy a qualifying ($25 or larger) package, level 3 after five. An unfilled tier passes up the line to the next qualified member, then to the platform. Nothing is held, there are no withdrawals, no pending balances. Contract ${CONTRACT} on Polygon, verified on Polygonscan; plain-language review at ${SITE_URL}/contract; live ledger at ${SITE_URL}/ledger with a verify link on every row.
|
||||
- CREDITS VS POL: every member, free ones included, earns CREDITS (zones, the daily ad set with a claim streak, watch-to-earn videos, verified visits, a daily sign-in bonus). Credits buy the member's own banner and text ads (the login spot takes purchased credits) and NEVER cash out or convert to crypto. POL only reaches a wallet through the contract split when a package sells in the member's line. Never promise or estimate income.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+21
-9
@@ -11,11 +11,11 @@ const crypto = require('crypto');
|
||||
const dns = require('dns').promises;
|
||||
const net = require('net');
|
||||
|
||||
let DATA_DIR = null, ownHosts = () => [], rotator = null;
|
||||
let DATA_DIR = null, ownHosts = () => [], rotator = null, SOURCES = null; // SOURCES = sources.js: a traffic source's own postback fires for its own clicks (2026-10-12)
|
||||
const J = { db: null, FILE: () => path.join(DATA_DIR, 'postbacks.json'),
|
||||
load() { try { this.db = JSON.parse(fs.readFileSync(this.FILE(), 'utf8')); } catch (e) { this.db = { v: 1, items: [], log: [], keys: {}, clicks: {} }; } for (const k of ['items', 'log']) if (!Array.isArray(this.db[k])) this.db[k] = []; for (const k of ['keys', 'clicks']) if (!this.db[k]) this.db[k] = {}; },
|
||||
save() { try { fs.writeFileSync(this.FILE(), JSON.stringify(this.db)); } catch (e) {} } };
|
||||
function init(opts) { DATA_DIR = opts.dataDir; ownHosts = opts.ownHosts || (() => []); rotator = opts.rotator; J.load(); }
|
||||
function init(opts) { DATA_DIR = opts.dataDir; ownHosts = opts.ownHosts || (() => []); rotator = opts.rotator; SOURCES = opts.sources || null; J.load(); }
|
||||
const norm = e => String(e || '').trim().toLowerCase();
|
||||
const EVENTS = ['join', 'lead', 'wallet', 'purchase', 'external'];
|
||||
const MACRO = /\{([a-z0-9_]{1,24})\}/gi;
|
||||
@@ -67,6 +67,7 @@ async function update(owner, id, body) {
|
||||
J.save(); return { ok: true, postback: pubItem(p) };
|
||||
}
|
||||
async function logFor(owner, n) { return J.db.log.filter(l => l.owner === norm(owner)).slice(-(n || 50)).reverse(); }
|
||||
async function logForSource(owner, sid, n) { return J.db.log.filter(l => l.owner === norm(owner) && l.source === String(sid)).slice(-(n || 30)).reverse(); }
|
||||
|
||||
// -- partner key (inbound)
|
||||
function partnerKey(owner) { const o = norm(owner); if (!J.db.keys[o]) { J.db.keys[o] = crypto.randomBytes(12).toString('hex'); J.save(); } return J.db.keys[o]; }
|
||||
@@ -91,23 +92,34 @@ async function deliver(p, url, ctx) {
|
||||
}
|
||||
} catch (e) { note = String(e && e.message || e).slice(0, 120); }
|
||||
p.lastStatus = status || note.slice(0, 40); p.lastAt = Date.now(); if (ok) { p.sent = (p.sent || 0) + 1; p.fails = 0; } else { p.fails = (p.fails || 0) + 1; if (p.fails >= 10) p.enabled = false; }
|
||||
J.db.log.push({ ts: t0, owner: p.owner, pb: p.id, name: p.name, event: ctx.event, lsid: ctx.lsid || '', url: url.slice(0, 300), status, ok, ms: Date.now() - t0, note, test: !!ctx.test });
|
||||
J.db.log.push({ ts: t0, owner: p.owner, pb: p.id, name: p.name, event: ctx.event, lsid: ctx.lsid || '', url: url.slice(0, 300), status, ok, ms: Date.now() - t0, note, test: !!ctx.test, source: ctx.viaSource || undefined });
|
||||
if (J.db.log.length > 2000) J.db.log = J.db.log.slice(-1500);
|
||||
J.save(); return { ok, status, note };
|
||||
}
|
||||
// fire every enabled postback of `owner` that listens to `event`; ctx carries the click's params and the event facts
|
||||
async function fire(owner, event, ctx) {
|
||||
const o = norm(owner); const out = [];
|
||||
const q = (ctx.q || {});
|
||||
const vals = { clickid: q.clickid || q.cid || q.click_id || q.external_id || q.visitor_id || '', subid: q.subid || q.sub_id || q.s1 || '', s1: q.s1 || q.sub1 || '', s2: q.s2 || q.sub2 || '', s3: q.s3 || q.sub3 || '', s4: q.s4 || q.sub4 || '', s5: q.s5 || q.sub5 || '', source: ctx.source || '', event, payout: ctx.payout != null ? ctx.payout : '', currency: ctx.currency || 'USD', txid: ctx.txid || '', lsid: ctx.lsid || '', code: ctx.code || '', country: ctx.country || '', device: ctx.device || '' };
|
||||
for (const [k, v] of Object.entries(q)) if (/^(utm_[a-z]+|sub\d|s\d|aff_sub\d?|t\d|cost|zone|placement|site|campaign|creative|banner|keyword|geo|os|browser|carrier|format)$/.test(k) && vals[k] == null) vals[k] = v;
|
||||
for (const p of J.db.items.filter(x => x.owner === o && x.enabled && x.events.includes(event))) {
|
||||
if (!rateOk(o)) break;
|
||||
const q = (ctx.q || {});
|
||||
const vals = { clickid: q.clickid || q.cid || q.click_id || '', subid: q.subid || q.sub_id || q.s1 || '', s1: q.s1 || q.sub1 || '', s2: q.s2 || q.sub2 || '', s3: q.s3 || q.sub3 || '', s4: q.s4 || q.sub4 || '', s5: q.s5 || q.sub5 || '', source: ctx.source || '', event, payout: ctx.payout != null ? ctx.payout : '', currency: ctx.currency || 'USD', txid: ctx.txid || '', lsid: ctx.lsid || '', code: ctx.code || '', country: ctx.country || '', device: ctx.device || '' };
|
||||
for (const [k, v] of Object.entries(q)) if (/^(utm_[a-z]+|sub\d|s\d|aff_sub\d?|t\d)$/.test(k) && vals[k] == null) vals[k] = v;
|
||||
const url = fill(p.url, vals);
|
||||
let r = await deliver(p, url, Object.assign({}, ctx, { event }));
|
||||
if (!r.ok && !ctx.test) { await new Promise(res => setTimeout(res, 4000)); r = await deliver(p, url, Object.assign({}, ctx, { event })); }
|
||||
out.push({ id: p.id, name: p.name, ok: r.ok, status: r.status, note: r.note });
|
||||
}
|
||||
// the traffic source that sent this click (and only that one) hears about it through its own postback
|
||||
if (ctx.sourceId && SOURCES) {
|
||||
const s = SOURCES.forFire(o, ctx.sourceId);
|
||||
if (s && (s.events || []).includes(event) && rateOk(o)) {
|
||||
const url = fill(s.postbackUrl, vals);
|
||||
let r = await deliver(s, url, Object.assign({}, ctx, { event, viaSource: s.id }));
|
||||
if (!r.ok && !ctx.test) { await new Promise(res => setTimeout(res, 4000)); r = await deliver(s, url, Object.assign({}, ctx, { event, viaSource: s.id })); }
|
||||
SOURCES.save();
|
||||
out.push({ id: s.id, name: s.name, source: true, ok: r.ok, status: r.status, note: r.note });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
async function test(owner, id) {
|
||||
@@ -122,7 +134,7 @@ async function convertFor(email, event, facts) {
|
||||
const c = clickOf(email); if (!c) return null;
|
||||
const hit = rotator && rotator.convert ? await rotator.convert(c.lsid, event, facts || {}) : null;
|
||||
if (!hit) return null;
|
||||
const ctx = Object.assign({ q: hit.q || {}, source: hit.s, country: hit.c, device: hit.dv, lsid: c.lsid, code: hit.code }, facts || {});
|
||||
const ctx = Object.assign({ q: hit.q || {}, source: hit.s, country: hit.c, device: hit.dv, lsid: c.lsid, code: hit.code, sourceId: hit.sourceId || '' }, facts || {});
|
||||
try { await fire(hit.owner, event, ctx); } catch (e) {}
|
||||
return hit;
|
||||
}
|
||||
@@ -134,8 +146,8 @@ async function inbound(key, body) {
|
||||
const hit = rotator && rotator.convert ? await rotator.convert(lsid, event, { payout: value, label }) : null;
|
||||
if (!hit) return { error: 'No click with that lsid.' };
|
||||
if (hit.owner !== owner) return { error: 'That click is not yours.' };
|
||||
const ctx = { q: hit.q || {}, source: hit.s, country: hit.c, device: hit.dv, lsid, code: hit.code, payout: value, currency: String(body.currency || 'USD').slice(0, 6), txid: String(body.txid || '').slice(0, 80), label };
|
||||
const ctx = { q: hit.q || {}, source: hit.s, country: hit.c, device: hit.dv, lsid, code: hit.code, sourceId: hit.sourceId || '', payout: value, currency: String(body.currency || 'USD').slice(0, 6), txid: String(body.txid || '').slice(0, 80), label };
|
||||
try { await fire(owner, event, ctx); } catch (e) {}
|
||||
return { ok: true, recorded: event, lsid };
|
||||
}
|
||||
module.exports = { init, EVENTS, validateUrl, list, create, update, logFor, partnerKey, rotateKey, bindClick, clickOf, fire, test, convertFor, inbound };
|
||||
module.exports = { init, EVENTS, validateUrl, fill, deliver, list, create, update, logFor, logForSource, partnerKey, rotateKey, bindClick, clickOf, fire, test, convertFor, inbound };
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Ads · LinkSpin</title>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Manrope:wght@400;500;700&family=JetBrains+Mono:wght@500;700&display=swap">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261011b">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261012a">
|
||||
<style>
|
||||
.body{padding:16px 24px;display:grid;gap:16px}
|
||||
.two{display:grid;grid-template-columns:minmax(0,1fr) 380px;gap:16px}
|
||||
@@ -61,7 +61,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/cr-shell.js?v=20261011b"></script>
|
||||
<script src="/assets/cr-shell.js?v=20261012a"></script>
|
||||
<script src="/assets/ads-screen.js?v=20261008b"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -8,6 +8,7 @@ window.CR = (function () {
|
||||
const fmt = n => Number(n || 0).toLocaleString();
|
||||
const NAV = [
|
||||
['links', 'Links', '/links', '<path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"/><path d="M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"/>'],
|
||||
['sources', 'Sources', '/sources', '<path d="M3 5h18l-7 8v6l-4-2v-4z"/>'],
|
||||
['pages', 'Pages', '/pages', '<rect x="4" y="4" width="16" height="16" rx="2"/><path d="M8 9h8M8 13h6"/>'],
|
||||
['zones', 'Zones', '/zones', '<rect x="3" y="5" width="18" height="14" rx="2"/><path d="M3 10h18"/>'],
|
||||
['ads', 'Ads', '/ads', '<path d="M3 11l14-5v12L3 13v-2z"/><path d="M17 8a4 4 0 0 1 0 8"/>'],
|
||||
@@ -23,7 +24,7 @@ window.CR = (function () {
|
||||
];
|
||||
// screens not built yet fall back to the classic dashboard pane so nothing is a dead end
|
||||
const FALLBACK = {}; // the classic /my dashboard is retired (2026-10-08); its leftover panes live at /tools
|
||||
const BUILT = new Set(['links', 'pages', 'zones', 'ads', 'credits', 'reports', 'team', 'wallet', 'tools', 'promo', 'training', 'pipeline', 'profile']); // Training, Pipeline and Profile on the rail, not behind More (Marty 2026-10-11)
|
||||
const BUILT = new Set(['links', 'sources', 'pages', 'zones', 'ads', 'credits', 'reports', 'team', 'wallet', 'tools', 'promo', 'training', 'pipeline', 'profile']); // Training, Pipeline and Profile on the rail, not behind More (Marty 2026-10-11)
|
||||
let ME = null, toastT;
|
||||
function toast(msg, bad) { let t = $('crToast'); if (!t) { t = document.createElement('div'); t.id = 'crToast'; t.className = 'toast'; t.setAttribute('role', 'status'); document.body.appendChild(t); } t.textContent = msg; t.classList.toggle('bad', !!bad); t.classList.add('on'); clearTimeout(toastT); toastT = setTimeout(() => t.classList.remove('on'), 2000); }
|
||||
async function api(path, body) { const r = await (await fetch(path, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) })).json(); if (r.error) throw new Error(r.error); return r; }
|
||||
|
||||
@@ -176,6 +176,7 @@ label.lbl{display:grid;gap:5px;font-size:10.5px;font-weight:700;letter-spacing:.
|
||||
.rail{position:fixed;top:auto;bottom:0;left:0;right:0;height:auto;flex-direction:row;justify-content:space-around;padding:6px 6px calc(6px + env(safe-area-inset-bottom,0px));border-right:0;border-top:1px solid var(--chrome-line);z-index:30}
|
||||
.rail .mark,.rail .sp,.railtog,.rail .lbl,.rail a.rsec{display:none} .rail a.on::before{display:none}
|
||||
.app.wide{grid-template-columns:1fr} .app.wide .rail{align-items:center;padding:6px 6px calc(6px + env(safe-area-inset-bottom,0px))} .app.wide .rail a{width:40px;justify-content:center;padding:0}
|
||||
.app.wide .rail a .lbl{display:none} .rail a,.app.wide .rail a{width:34px;height:38px} /* ten entries since Sources joined the rail (2026-10-12): icons only, 34px each, so the bar fits a 360px phone */
|
||||
.main{padding-bottom:64px;min-height:auto}
|
||||
.topbar{padding:10px 16px;flex-wrap:wrap;gap:10px 14px} .topbar .readout{display:none}
|
||||
.strip{flex-wrap:wrap;gap:8px 16px;padding:8px 16px}
|
||||
|
||||
+10
-4
@@ -1,7 +1,7 @@
|
||||
// LinkSpin Links workspace (Control Room). Rotator API + postbacks + share kit. Uses the shared shell (cr-shell.js).
|
||||
(function () {
|
||||
const $ = id => document.getElementById(id); const esc = CR.esc, fmt = CR.fmt, api = CR.api, toast = CR.toast, dialog = CR.dialog;
|
||||
let ROT = [], HOSTS = [], SEL = null, STATS = {}, FILTER = '', PB = null;
|
||||
let ROT = [], HOSTS = [], SEL = null, STATS = {}, FILTER = '', PB = null, SRC = []; // SRC = the member's traffic sources (sources.js, 2026-10-12)
|
||||
CR.mount({ active: 'links', title: 'Links', sub: 'loading', actions: '<button class="btn pri" id="newBtn" type="button">+ New spin</button>' });
|
||||
const linkUrl = r => 'https://' + (HOSTS[0] || location.host) + '/r/' + r.code;
|
||||
const clicks7 = r => r.hits7 || 0;
|
||||
@@ -72,6 +72,7 @@
|
||||
let r; try { r = await CR.get('/api/my/rotations'); } catch (e) { CR.sub('could not load'); return; }
|
||||
ROT = (r.rotations || []).slice().sort((a, b) => clicks7(b) - clicks7(a)); HOSTS = r.hosts || [];
|
||||
try { const lh = await api('/api/my/link-hosts'); LH = (lh && lh.hosts) || []; } catch (e) { LH = []; } // link domains by channel (domains.js, 2026-10-10)
|
||||
try { SRC = (await CR.get('/api/my/sources')).sources || []; } catch (e) { SRC = []; }
|
||||
const tot7 = ROT.reduce((n, x) => n + clicks7(x), 0);
|
||||
CR.sub(ROT.length + ' link' + (ROT.length === 1 ? '' : 's') + ' · ' + fmt(tot7) + ' clicks in 7 days');
|
||||
renderList();
|
||||
@@ -137,14 +138,19 @@
|
||||
function renderShare(r) {
|
||||
const url = linkUrl(r);
|
||||
const byChannel = LH.filter(h => h.channel !== 'reserve').map(h => ['Best link for ' + (h.label || h.channel), 'https://' + h.host + '/r/' + r.code + (h.note ? ' (' + h.note + ')' : '')]);
|
||||
const kit = byChannel.concat([
|
||||
// traffic source (2026-10-12): when the link is pointed at one, the first row is the exact campaign URL for that network
|
||||
const src = SRC.find(s => s.id === r.sourceId) || null;
|
||||
const campaign = src ? [['Campaign URL for ' + src.name, url + ((src.params || []).length ? '?' + src.params.map(p => p.key + '=' + p.token).join('&') : '')]] : [['Tracker-ready link', url + '?clickid={clickid}&s1={source} (replace the braces with your network\'s macros)']];
|
||||
const kit = campaign.concat(byChannel, [
|
||||
['Short post', 'One link, every page I promote, in turn. Take a look: ' + url],
|
||||
['Email or Telegram line', 'Here is the link I use for everything: ' + url + ' (it always sends you to the right page).'],
|
||||
['Tracker-ready link', url + '?clickid={clickid}&s1={source} (replace the braces with your network\'s macros)'],
|
||||
['Sub-id split test', url + '?s1=email-A and ' + url + '?s1=email-B (each shows up under Sources)'],
|
||||
]);
|
||||
$('shareKit').innerHTML = kit.map(([t, body], i) => '<div class="panel" style="padding:10px 12px"><div style="display:flex;justify-content:space-between;align-items:center;gap:8px"><b>' + esc(t) + '</b><button class="btn sm" type="button" data-cp="' + i + '">Copy</button></div><div class="mono muted" style="font-size:12px;overflow-wrap:anywhere;margin-top:6px" id="kit-' + i + '">' + esc(body) + '</div></div>').join('');
|
||||
const picker = '<div class="panel" style="padding:10px 12px"><div style="display:grid;grid-template-columns:minmax(0,1fr) auto;gap:10px;align-items:end"><label class="lbl" style="margin:0">Traffic source for this link<select class="field" id="srcSel"><option value="">None (generic tracker macros)</option>' + SRC.map(s => '<option value="' + s.id + '"' + (s.id === r.sourceId ? ' selected' : '') + '>' + esc(s.name) + (s.site ? ' · ' + esc(s.site) : '') + '</option>').join('') + '</select></label><a class="btn sm" href="/sources">Manage sources</a></div>'
|
||||
+ '<div class="muted" style="font-size:11.5px;margin-top:6px">' + (src ? 'Paste the campaign URL below as the destination in ' + esc(src.site || src.name) + '. Conversions from this link fire ' + esc(src.name) + '\'s postback' + (src.postbackUrl ? '' : ' once one is set under Sources') + '.' : 'A source fills in the network\'s macros for you and tells that network when a click converts. Pick one, or make one under Sources.') + '</div></div>';
|
||||
$('shareKit').innerHTML = picker + kit.map(([t, body], i) => '<div class="panel" style="padding:10px 12px"><div style="display:flex;justify-content:space-between;align-items:center;gap:8px"><b>' + esc(t) + '</b><button class="btn sm" type="button" data-cp="' + i + '">Copy</button></div><div class="mono muted" style="font-size:12px;overflow-wrap:anywhere;margin-top:6px" id="kit-' + i + '">' + esc(body) + '</div></div>').join('');
|
||||
$('shareKit').querySelectorAll('[data-cp]').forEach(b => b.addEventListener('click', () => CR.copy($('kit-' + b.dataset.cp).textContent)));
|
||||
$('srcSel').addEventListener('change', async () => { try { await api('/api/my/rotations/' + r.id, { sourceId: $('srcSel').value }); toast($('srcSel').value ? 'Source saved' : 'Source removed'); load(true); } catch (e) { toast(e.message, true); } });
|
||||
}
|
||||
// the rotation's own hours editor on the Hours tab. Not redrawn while the member is mid-edit (the 60 s refresh would eat their taps).
|
||||
let RH = null; // { rid, dirty }
|
||||
|
||||
@@ -48,6 +48,10 @@
|
||||
$('pgBars').querySelectorAll('i b').forEach(b => { b.style.background = 'var(--sig)'; });
|
||||
$('pgTiles').innerHTML = mini([['Views', fmt(pg.views)], ['Unique', fmt(pg.uniques)], ['Clicks through', fmt(pg.clicks)], ['Leads', fmt(pg.leads)]]);
|
||||
$('pgRows').innerHTML = (pg.byPage || []).length ? pg.byPage.map(x => '<div class="rw"><a href="/pages" style="text-decoration:none;color:var(--ink)"><b>' + esc(x.title) + '</b><br><span class="mono muted" style="font-size:11px">' + esc(x.type) + ' · ' + (x.status === 'published' ? '<span class="ok">live</span>' : 'draft') + '</span></a><span class="r num">' + fmt(x.views) + '</span><span class="r num">' + fmt(x.uniques) + '</span><span class="r num">' + fmt(x.clicks) + '</span><span class="r num">' + fmt(x.leads) + '</span></div>').join('') : '<div class="rw"><span class="muted">No pages yet. <a href="/pages">Make one</a>.</span></div>';
|
||||
// -- Traffic sources (2026-10-12): per source, and per placement value the network's macro carried
|
||||
const ts = s.sources || [], pl = s.placements || [];
|
||||
$('tsRows').innerHTML = ts.length ? ts.map(x => '<div class="rw"><a href="/sources#' + esc(x.id) + '" style="text-decoration:none;color:var(--ink)"><b>' + esc(x.name) + '</b>' + (x.site ? '<br><span class="mono muted" style="font-size:11px">' + esc(x.site) + '</span>' : '') + '</a><span class="r num">' + fmt(x.hits) + '</span><span class="r num">' + fmt(x.unique) + '</span><span class="r num">' + fmt(x.conv) + (x.unique ? ' <span class="muted" style="font-size:10px">' + (x.conv / x.unique * 100).toFixed(1) + '%</span>' : '') + '</span></div>').join('') : '<div class="rw"><span class="muted">No clicks from a traffic source yet. Point a link at one under <a href="/sources">Sources</a>.</span></div>';
|
||||
$('plRows').innerHTML = pl.length ? pl.map(x => '<div class="rw"><span><b>' + esc(x.source) + '</b><br><span class="mono muted" style="font-size:11px">' + esc(x.key) + ' = ' + esc(x.k) + '</span></span><span class="r num">' + fmt(x.n) + '</span><span class="r num">' + fmt(x.conv) + '</span></div>').join('') : '<div class="rw"><span class="muted">Nothing yet. Placements appear once a source\'s zone or placement macro rides in on clicks.</span></div>';
|
||||
const zn = s.zones || { byDay: [], byZone: [] };
|
||||
// bar = all views, lighter inner share = the ones that were NOT viewable
|
||||
dayBars('znBars', 'znAxis', zn.byDay, d => d.views, d => d.views - d.viewable, 'no zone views yet');
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
// LinkSpin Traffic sources screen (Control Room, 2026-10-12): the networks a member buys traffic on.
|
||||
// Left: the member's sources with 30-day clicks and conversions. Right: Campaign URL (the exact URL to paste
|
||||
// into the network, macros included), Postback (the network's own conversion URL, test, log), Settings.
|
||||
// New source = pick a network from the catalog (or Custom), then a short form with one input per {{slot}}.
|
||||
(function () {
|
||||
const $ = id => document.getElementById(id); const esc = CR.esc, fmt = CR.fmt, api = CR.api, toast = CR.toast, dialog = CR.dialog;
|
||||
let S = [], CAT = [], ROT = [], SEL = null, DET = null, FILTER = '', KEYS = [], EVENTS = ['join', 'lead', 'wallet', 'purchase', 'external'], LIMITS = {}, URL_ROT = null, PE = [];
|
||||
CR.mount({ active: 'sources', title: 'Traffic sources', sub: 'loading', actions: '<button class="btn pri" type="button" id="newBtn">+ New source</button>' });
|
||||
const ago = ts => { if (!ts) return 'never'; const s = Math.max(0, Math.round((Date.now() - ts) / 1000)); return s < 60 ? 'just now' : s < 3600 ? Math.round(s / 60) + ' min ago' : s < 86400 ? Math.round(s / 3600) + ' h ago' : Math.round(s / 86400) + ' d ago'; };
|
||||
const netOf = s => CAT.find(c => c.key === s.template) || null;
|
||||
const netName = s => { const n = netOf(s); return n ? n.name : (s.template === 'custom' ? 'Custom' : s.template); };
|
||||
const EV_LABEL = { join: 'Join', lead: 'Lead', wallet: 'Wallet', purchase: 'Purchase', external: 'Partner-reported' };
|
||||
|
||||
async function load(keep) {
|
||||
let r; try { r = await CR.get('/api/my/sources'); } catch (e) { CR.sub('could not load'); return; }
|
||||
S = (r.sources || []).slice().sort((a, b) => (b.hits30 || 0) - (a.hits30 || 0)); KEYS = r.keys || KEYS; EVENTS = r.events || EVENTS; LIMITS = r.limits || {};
|
||||
if (!CAT.length) { try { CAT = (await CR.get('/api/sources/catalog')).catalog || []; } catch (e) { CAT = []; } }
|
||||
if (!ROT.length) { try { ROT = (await CR.get('/api/my/rotations')).rotations || []; } catch (e) { ROT = []; } }
|
||||
const tot = S.reduce((n, x) => n + (x.hits30 || 0), 0), conv = S.reduce((n, x) => n + (x.conv30 || 0), 0);
|
||||
CR.sub(S.length + ' source' + (S.length === 1 ? '' : 's') + ' · ' + fmt(tot) + ' clicks · ' + fmt(conv) + ' conversions in 30 days');
|
||||
renderList();
|
||||
const want = SEL != null ? SEL : (location.hash.slice(1) || null);
|
||||
if (want && S.find(x => x.id === want)) return select(want, true);
|
||||
if (!S.length) { $('noSel').hidden = false; $('sel').hidden = true; SEL = null; return; }
|
||||
select(S[0].id, true);
|
||||
}
|
||||
function renderList() {
|
||||
const q = FILTER.trim().toLowerCase();
|
||||
const rows = S.filter(x => !q || x.name.toLowerCase().includes(q) || netName(x).toLowerCase().includes(q) || (x.site || '').toLowerCase().includes(q));
|
||||
$('listCount').textContent = S.length + ' source' + (S.length === 1 ? '' : 's');
|
||||
$('items').innerHTML = rows.length ? rows.map(x => '<div class="item' + (x.id === SEL ? ' on' : '') + '" data-id="' + x.id + '" role="button" tabindex="0">'
|
||||
+ '<div><div class="nm">' + esc(x.name) + (x.enabled ? '' : ' <span class="tag warn">OFF</span>') + (x.conv30 ? ' <span class="tag ok">' + fmt(x.conv30) + ' conv</span>' : '') + '</div><div class="cd">' + esc(netName(x)) + (x.site ? ' · ' + esc(x.site) : '') + (x.links ? ' · ' + x.links + ' link' + (x.links === 1 ? '' : 's') : '') + '</div></div>'
|
||||
+ '<div class="rt"><span class="n">' + fmt(x.hits30 || 0) + '</span><span class="muted" style="font-size:10px">clicks 30 d</span></div></div>').join('')
|
||||
: '<div class="empty"><div class="muted">' + (S.length ? 'No source matches that filter.' : 'No sources yet.') + '</div></div>';
|
||||
$('items').querySelectorAll('.item').forEach(el => { const go = () => select(el.dataset.id); el.addEventListener('click', go); el.addEventListener('keydown', e => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); go(); } }); });
|
||||
}
|
||||
async function select(id, quiet) {
|
||||
SEL = id; const s = S.find(x => x.id === id); if (!s) return;
|
||||
if (location.hash.slice(1) !== id) history.replaceState(null, '', '#' + id);
|
||||
$('noSel').hidden = true; $('sel').hidden = false; $('ws').classList.add('focus');
|
||||
$('items').querySelectorAll('.item').forEach(el => el.classList.toggle('on', el.dataset.id === id));
|
||||
$('dName').textContent = s.name; $('dNet').textContent = netName(s) + (s.site ? ' · ' + s.site : '') + (s.costModel ? ' · ' + s.costModel : '');
|
||||
$('dOn').innerHTML = s.enabled ? '<span class="ok"><span class="dot"></span>ON</span>' : '<span class="warn"><span class="dot"></span>OFF' + (s.fails >= 10 ? ' (postback failed 10 times)' : '') + '</span>';
|
||||
$('togBtn').textContent = s.enabled ? 'Disable' : 'Enable';
|
||||
$('tiles').innerHTML = [CR.tile({ k: 'Clicks, 30 d', v: fmt(s.hits30 || 0), hi: true }), CR.tile({ k: 'Unique, 30 d', v: fmt(s.unique30 || 0) }), CR.tile({ k: 'Conversions, 30 d', v: fmt(s.conv30 || 0) }), CR.tile({ k: 'Postbacks sent', v: fmt(s.sent || 0), note: s.lastAt ? 'last ' + ago(s.lastAt) + ' · ' + s.lastStatus : 'none yet' }), CR.tile({ k: 'Links using it', v: fmt(s.links || 0) })].join('');
|
||||
renderUrl(s); renderPb(s, null); renderSettings(s);
|
||||
if (!quiet) window.scrollTo({ top: 0 });
|
||||
try { DET = await CR.get('/api/my/sources/' + id); } catch (e) { DET = null; }
|
||||
if (SEL === id && DET) renderPb(DET.source, DET.log || []);
|
||||
}
|
||||
// -- Campaign URL
|
||||
function renderUrl(s) {
|
||||
const sel = $('urlRot');
|
||||
sel.innerHTML = ROT.length ? ROT.map(r => '<option value="' + r.id + '"' + (r.sourceId === s.id ? ' data-att="1"' : '') + '>' + esc(r.name) + (r.sourceId === s.id ? ' (uses this source)' : '') + '</option>').join('') : '<option value="">No links yet</option>';
|
||||
const att = ROT.find(r => r.sourceId === s.id); const pick = (URL_ROT && ROT.find(r => r.id === URL_ROT)) ? URL_ROT : (att ? att.id : (ROT[0] ? ROT[0].id : null));
|
||||
if (pick != null) sel.value = String(pick);
|
||||
$('prmRows').innerHTML = (s.params || []).length ? s.params.map(p => '<div class="rw"><span class="mono">' + esc(p.key) + '</span><span class="mono" style="overflow-wrap:anywhere">' + esc(p.token) + '</span><span class="muted">' + esc(p.label || (p.role === 'externalId' ? 'click id' : p.role === 'cost' ? 'cost of the click' : '')) + '</span></div>').join('') : '<div class="rw"><span class="muted">No params. Add the network\'s macros under Settings.</span></div>';
|
||||
buildUrl(s);
|
||||
}
|
||||
async function buildUrl(s) {
|
||||
const rid = $('urlRot').value; const r = ROT.find(x => String(x.id) === String(rid));
|
||||
if (!r) { $('urlOut').textContent = 'Make a link first, then come back for its campaign URL.'; $('urlNote').innerHTML = '<a href="/links">Open Links</a>'; return; }
|
||||
URL_ROT = r.id;
|
||||
try { const out = await api('/api/my/sources/' + s.id + '/url', { rotationId: r.id }); $('urlOut').textContent = out.url; }
|
||||
catch (e) { $('urlOut').textContent = e.message; }
|
||||
const attached = r.sourceId === s.id;
|
||||
$('urlNote').innerHTML = 'Paste this as the destination URL in ' + esc(netName(s) === 'Custom' ? (s.site || s.name) : netName(s)) + '. ' + (attached ? 'This link is pointed at this source, so its conversions reach the network\'s postback.' : 'This link is not pointed at this source yet: <button class="btn sm" type="button" id="urlAttach">Point it here</button> so its conversions reach the network\'s postback.');
|
||||
const b = $('urlAttach'); if (b) b.addEventListener('click', async () => { try { await api('/api/my/rotations/' + r.id, { sourceId: s.id }); r.sourceId = s.id; toast('Link now uses ' + s.name); ROT = []; await load(true); } catch (e) { toast(e.message, true); } });
|
||||
}
|
||||
$('urlRot').addEventListener('change', () => { const s = S.find(x => x.id === SEL); if (s) buildUrl(s); });
|
||||
$('urlCopy').addEventListener('click', () => { const t = $('urlOut').textContent; if (/^https?:/.test(t)) CR.copy(t); });
|
||||
// -- Postback
|
||||
function renderPb(s, log) {
|
||||
$('pbUrl').textContent = s.postbackUrl || 'No postback URL yet. Add the network\'s conversion URL under Settings; until then this source still tags your campaign URL and shows up in Reports.';
|
||||
$('pbEvents').innerHTML = EVENTS.map(e => '<button type="button" class="chip' + ((s.events || []).includes(e) ? ' on' : '') + '" data-ev="' + e + '">' + esc(EV_LABEL[e] || e) + '</button>').join('');
|
||||
$('pbEvents').querySelectorAll('[data-ev]').forEach(b => b.addEventListener('click', async () => { const ev = (s.events || []).slice(); const i = ev.indexOf(b.dataset.ev); if (i >= 0) ev.splice(i, 1); else ev.push(b.dataset.ev); if (!ev.length) return toast('Keep at least one event', true); try { await api('/api/my/sources/' + s.id, { events: ev }); toast('Saved'); load(true); } catch (e) { toast(e.message, true); } }));
|
||||
$('pbTest').disabled = !s.postbackUrl;
|
||||
$('pbStatus').textContent = s.lastAt ? 'last delivery ' + ago(s.lastAt) + ': ' + s.lastStatus + ' · ' + fmt(s.sent || 0) + ' sent' + (s.fails ? ' · ' + s.fails + ' failing in a row' : '') : (s.postbackUrl ? 'nothing sent yet' : '');
|
||||
if (log == null) { $('logRows').innerHTML = '<div class="rw"><span class="muted">loading</span></div>'; return; }
|
||||
$('logRows').innerHTML = log.length ? log.map(l => '<div class="rw"><span class="mono muted" style="font-size:11px">' + new Date(l.ts).toLocaleString() + '</span><span>' + esc(l.event) + (l.test ? ' <span class="tag dim">test</span>' : '') + '</span><span class="mono" style="font-size:11px;overflow-wrap:anywhere">' + esc(l.url) + '</span><span class="' + (l.ok ? 'ok' : 'bad') + '">' + (l.ok ? 'ok ' + l.status : 'failed ' + (l.status || esc(l.note || ''))) + '</span><span class="r num">' + fmt(l.ms) + '</span></div>').join('') : '<div class="rw"><span class="muted">No deliveries yet. Send a test, or wait for the first conversion from this source.</span></div>';
|
||||
}
|
||||
$('pbTest').addEventListener('click', async () => { const s = S.find(x => x.id === SEL); if (!s) return; const b = $('pbTest'); b.disabled = true; try { const r = await api('/api/my/sources/' + s.id, { test: true }); toast(r.ok ? 'Test delivered, HTTP ' + r.status : 'Test failed: ' + (r.status || r.note), !r.ok); } catch (e) { toast(e.message, true); } b.disabled = false; await load(true); });
|
||||
// -- Settings (params editor rows live in PE until Save)
|
||||
function renderSettings(s) {
|
||||
$('sName').value = s.name; $('sSite').value = s.site || ''; $('sCost').value = s.costModel || ''; $('sMethod').value = s.method || 'GET'; $('sPb').value = s.postbackUrl || '';
|
||||
PE = (s.params || []).map(p => ({ key: p.key, token: p.token, label: p.label || '' }));
|
||||
renderPe();
|
||||
}
|
||||
function renderPe() {
|
||||
$('peRows').innerHTML = PE.length ? PE.map((p, i) => '<div class="rw"><select class="field" data-k="' + i + '">' + KEYS.map(k => '<option value="' + k + '"' + (k === p.key ? ' selected' : '') + '>' + k + '</option>').join('') + '</select><input class="field mono" data-t="' + i + '" value="' + esc(p.token) + '" placeholder="{click_id}" maxlength="60" aria-label="Macro token"><input class="field" data-l="' + i + '" value="' + esc(p.label) + '" placeholder="Label" maxlength="40" aria-label="Label"><button class="btn sm danger" type="button" data-x="' + i + '" aria-label="Remove">×</button></div>').join('')
|
||||
: '<div class="rw"><span class="muted">No params yet. Add clickid with the network\'s click id macro first.</span></div>';
|
||||
$('peRows').querySelectorAll('[data-k]').forEach(el => el.addEventListener('change', () => { PE[el.dataset.k].key = el.value; }));
|
||||
$('peRows').querySelectorAll('[data-t]').forEach(el => el.addEventListener('input', () => { PE[el.dataset.t].token = el.value; }));
|
||||
$('peRows').querySelectorAll('[data-l]').forEach(el => el.addEventListener('input', () => { PE[el.dataset.l].label = el.value; }));
|
||||
$('peRows').querySelectorAll('[data-x]').forEach(el => el.addEventListener('click', () => { PE.splice(Number(el.dataset.x), 1); renderPe(); }));
|
||||
}
|
||||
$('peAdd').addEventListener('click', () => { if (PE.length >= (LIMITS.params || 20)) return toast('Up to ' + (LIMITS.params || 20) + ' params', true); const used = new Set(PE.map(p => p.key)); const k = KEYS.find(x => !used.has(x)) || 's1'; PE.push({ key: k, token: '', label: '' }); renderPe(); const last = $('peRows').querySelector('[data-t="' + (PE.length - 1) + '"]'); if (last) last.focus(); });
|
||||
$('sSave').addEventListener('click', async () => { const s = S.find(x => x.id === SEL); if (!s) return; try { await api('/api/my/sources/' + s.id, { name: $('sName').value, site: $('sSite').value, costModel: $('sCost').value, method: $('sMethod').value, postbackUrl: $('sPb').value.trim(), params: PE }); toast('Saved'); load(true); } catch (e) { toast(e.message, true); } });
|
||||
$('togBtn').addEventListener('click', async () => { const s = S.find(x => x.id === SEL); if (!s) return; try { await api('/api/my/sources/' + s.id, { enabled: !s.enabled }); toast(s.enabled ? 'Source off: its postback will not fire' : 'Source on'); load(true); } catch (e) { toast(e.message, true); } });
|
||||
$('delBtn').addEventListener('click', async () => { const s = S.find(x => x.id === SEL); if (!s) return; if (!await dialog({ title: 'Delete ' + s.name + '?', text: 'Links pointed at it keep working but lose the source; its click history stays in Reports as a deleted source.', ok: 'Delete', danger: true })) return; try { await api('/api/my/sources/' + s.id, { remove: true }); SEL = null; history.replaceState(null, '', location.pathname); toast('Deleted'); ROT = []; load(); } catch (e) { toast(e.message, true); } });
|
||||
// -- New source: step 1 pick a network, step 2 the short form
|
||||
async function newSource() {
|
||||
if (!CAT.length) { try { CAT = (await CR.get('/api/sources/catalog')).catalog || []; } catch (e) {} }
|
||||
let chosen = null;
|
||||
const row = c => '<div class="cat" data-key="' + esc(c.key) + '" role="button" tabindex="0"><div><b>' + esc(c.name) + '</b><span class="site">' + esc(c.site || '') + (c.costModel ? ' · ' + esc(c.costModel) : '') + '</span></div><div class="tags">' + (c.hasClickId ? '' : '<span class="tag warn" title="This network has no click id macro and no postback. The source still tags your campaign URL and shows in Reports.">no click id</span>') + (c.hasPostback ? '<span class="tag ok">postback</span>' : (c.hasClickId ? '<span class="tag dim">no postback</span>' : '')) + (c.verified ? '' : '<span class="tag dim" title="Macros copied from public docs, not yet checked against a live account">unverified</span>') + '</div></div>';
|
||||
const p1 = dialog({ title: 'New source', text: 'Pick the network you buy traffic on. Its macros and postback come prefilled; you can change anything later under Settings.',
|
||||
html: '<input class="field catf" id="catFilter" type="search" placeholder="Search ' + CAT.length + ' networks by name or site" aria-label="Search networks"><div class="catlist" id="catList">' + CAT.map(row).join('') + '</div>', ok: 'Custom (define your own)', no: 'Cancel' });
|
||||
const host = $('crModalHost');
|
||||
const wire = () => host.querySelectorAll('.cat').forEach(el => { const go = () => { chosen = el.dataset.key; host.querySelector('#dlgOk').click(); }; el.addEventListener('click', go); el.addEventListener('keydown', e => { if (e.key === 'Enter') { e.preventDefault(); go(); } }); });
|
||||
wire();
|
||||
const flt = host.querySelector('#catFilter'); flt.focus();
|
||||
flt.addEventListener('input', () => { const q = flt.value.trim().toLowerCase(); const list = CAT.filter(c => !q || c.name.toLowerCase().includes(q) || (c.site || '').toLowerCase().includes(q) || c.key.includes(q)); host.querySelector('#catList').innerHTML = list.length ? list.map(row).join('') : '<div class="cat"><span class="muted">No network by that name. Use Custom and paste its macros yourself.</span></div>'; wire(); });
|
||||
flt.addEventListener('keydown', e => { if (e.key === 'Enter') { e.preventDefault(); e.stopPropagation(); const first = host.querySelector('.cat[data-key]'); if (first) first.click(); } });
|
||||
const ok = await p1; if (!ok) return;
|
||||
const tpl = chosen ? CAT.find(c => c.key === chosen) : null;
|
||||
let v, body;
|
||||
if (tpl) {
|
||||
const fields = [{ k: 'name', label: 'Name for you', value: tpl.name, max: 60 }].concat((tpl.slots || []).map((sl, i) => ({ k: 'slot' + i, label: sl + (/\(optional\)/i.test(sl) ? '' : ' (from your ' + tpl.name + ' account)'), mono: true, max: 120 })));
|
||||
const prev = '<div class="prev"><div><b>' + esc(tpl.name) + '</b> <span class="muted">' + esc(tpl.site || '') + '</span></div>'
|
||||
+ (tpl.params.length ? '<dl>' + tpl.params.map(p => '<dt>' + esc(p.key) + '</dt><dd>' + esc(p.token) + (p.label ? ' <span class="muted">' + esc(p.label) + '</span>' : '') + '</dd>').join('') + '</dl>' : '<div class="muted">No macros listed for this network.</div>')
|
||||
+ (tpl.hasPostback ? '<div class="mono">' + esc(tpl.postbackUrl) + '</div>' : '<div class="warn">' + (tpl.hasClickId ? 'No postback known for this network: it tags the campaign URL and shows in Reports. Paste its conversion URL under Settings if it has one.' : 'This network has no click id macro and no postback. The source tags your campaign URL and shows in Reports, nothing more.') + '</div>')
|
||||
+ (tpl.notes ? '<div class="muted">' + esc(tpl.notes) + '</div>' : '') + '</div>';
|
||||
v = await dialog({ title: 'New source: ' + tpl.name, html: prev, fields, ok: 'Create source' }); if (!v) return;
|
||||
const slots = {}; (tpl.slots || []).forEach((sl, i) => { slots[sl] = v['slot' + i]; });
|
||||
body = { template: tpl.key, name: v.name, slots };
|
||||
} else {
|
||||
v = await dialog({ title: 'New source: custom', text: 'Paste the macros exactly as the network expands them. One row for the click id is set up; add more under Settings.', fields: [{ k: 'name', label: 'Name', placeholder: 'My push network', max: 60 }, { k: 'site', label: 'Network site', placeholder: 'network.com', mono: true, max: 80 }, { k: 'clickid', label: 'Click id macro', value: '{clickid}', mono: true, max: 60 }, { k: 'postbackUrl', label: 'Postback URL (optional), {clickid} and {payout} where the network wants them', placeholder: 'https://network.example/postback?cid={clickid}&payout={payout}', mono: true }], ok: 'Create source' }); if (!v) return;
|
||||
body = { template: 'custom', name: v.name, site: v.site, params: v.clickid.trim() ? [{ key: 'clickid', token: v.clickid.trim(), label: 'Click id' }] : [], postbackUrl: v.postbackUrl.trim() };
|
||||
}
|
||||
try { const r = await api('/api/my/sources', body); SEL = r.source.id; toast('Source created. Copy its campaign URL.'); await load(true); } catch (e) { toast(e.message, true); }
|
||||
}
|
||||
$('newBtn').addEventListener('click', newSource); $('newBtn2').addEventListener('click', newSource);
|
||||
$('filter').addEventListener('input', e => { FILTER = e.target.value; renderList(); });
|
||||
$('backBtn').addEventListener('click', () => { $('ws').classList.remove('focus'); });
|
||||
$('backBtn').hidden = !window.matchMedia('(max-width:760px)').matches;
|
||||
const showTab = name => { $('tabs').querySelectorAll('button').forEach(x => x.classList.toggle('on', x.dataset.tab === name)); ['url', 'pb', 'settings'].forEach(t => { $('tab-' + t).hidden = t !== name; }); };
|
||||
$('tabs').querySelectorAll('button').forEach(b => b.addEventListener('click', () => showTab(b.dataset.tab)));
|
||||
CR.requireSession(() => { load(); });
|
||||
})();
|
||||
+2
-2
@@ -6,7 +6,7 @@
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Credits · LinkSpin</title>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Manrope:wght@400;500;700&family=JetBrains+Mono:wght@500;700&display=swap">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261011b">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261012a">
|
||||
<style>
|
||||
.body{padding:16px 24px;display:grid;gap:16px}
|
||||
.two{display:grid;grid-template-columns:minmax(0,1fr) 360px;gap:16px;align-items:start}
|
||||
@@ -80,7 +80,7 @@
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261009a"></script>
|
||||
<script src="/assets/wallet.js?v=20261008a"></script>
|
||||
<script src="/assets/cr-shell.js?v=20261011b"></script>
|
||||
<script src="/assets/cr-shell.js?v=20261012a"></script>
|
||||
<script src="/assets/credits-screen.js?v=20261007a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Links · LinkSpin</title>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Manrope:wght@400;500;700&family=JetBrains+Mono:wght@500;700&display=swap">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261011b">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261012a">
|
||||
<style>
|
||||
.ws{display:grid;grid-template-columns:320px minmax(0,1fr);min-height:calc(100vh - 94px)}
|
||||
.dbody .tiles{grid-template-columns:repeat(auto-fit,minmax(128px,1fr))}
|
||||
@@ -135,7 +135,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/cr-shell.js?v=20261011b"></script>
|
||||
<script src="/assets/links.js?v=20261010b"></script>
|
||||
<script src="/assets/cr-shell.js?v=20261012a"></script>
|
||||
<script src="/assets/links.js?v=20261012a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@
|
||||
<title>More · LinkSpin</title>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Manrope:wght@400;500;700;800&family=JetBrains+Mono:wght@500;700&display=swap">
|
||||
<link rel="icon" type="image/png" href="/logo-icon.png">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261011b">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261012a">
|
||||
<style>@import url("/assets/site.css?v=ls20260916a") layer(legacy);</style>
|
||||
<link rel="stylesheet" href="/assets/tools.css?v=20261008a">
|
||||
</head>
|
||||
@@ -1008,7 +1008,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/common.js?v=20261009a"></script>
|
||||
<script src="/assets/cr-shell.js?v=20261011b"></script>
|
||||
<script src="/assets/cr-shell.js?v=20261012a"></script>
|
||||
<script src="/assets/tools.js?v=20261011a"></script>
|
||||
<script src="/assets/wallet.js?v=20261008a"></script>
|
||||
<script src="/assets/promo.js?v=20261009b"></script>
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Pages · LinkSpin</title>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Manrope:wght@400;500;700&family=JetBrains+Mono:wght@500;700&display=swap">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261011b">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261012a">
|
||||
<style>
|
||||
.look{display:grid;gap:10px;margin:6px 0 10px}.lk-row{display:flex;gap:10px;align-items:flex-start}.lk-k{flex:none;width:64px;font:700 11px var(--mono);letter-spacing:.1em;text-transform:uppercase;color:var(--muted);padding-top:9px}
|
||||
.lk-opts{display:flex;gap:6px;flex-wrap:wrap}.lk-opts button{font:600 12px var(--body);padding:7px 10px;border-radius:7px;border:1px solid var(--line);background:transparent;color:var(--fg);cursor:pointer}.lk-opts button.on{border-color:var(--accent);background:rgba(59,157,255,.12)}
|
||||
@@ -72,7 +72,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/cr-shell.js?v=20261011b"></script>
|
||||
<script src="/assets/cr-shell.js?v=20261012a"></script>
|
||||
<script src="/assets/pages-screen.js?v=20261011a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+10
-3
@@ -6,7 +6,7 @@
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Reports · LinkSpin</title>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Manrope:wght@400;500;700&family=JetBrains+Mono:wght@500;700&display=swap">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261011b">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261012a">
|
||||
<style>
|
||||
.body{padding:16px 24px;display:grid;gap:16px}
|
||||
.two{display:grid;grid-template-columns:minmax(0,1fr) 340px;gap:16px}
|
||||
@@ -19,6 +19,7 @@
|
||||
.bars.stack i{position:relative}.bars.stack i b{position:absolute;left:0;right:0;bottom:0;display:block;background:var(--line);border-radius:2px 2px 0 0}.bars i.ghost{background:var(--line)}
|
||||
.mini{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:8px;margin-top:10px}.mini .m{background:var(--panel-2);border:1px solid var(--line);border-radius:6px;padding:8px 10px;display:grid;gap:2px}.mini .m .k{font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.08em;color:var(--muted)}.mini .m .v{font-family:var(--display);font-weight:700;font-size:20px;color:var(--ink);font-variant-numeric:tabular-nums}
|
||||
.pages .hd,.pages .rw,.zones .hd,.zones .rw{grid-template-columns:minmax(0,1fr) 60px 60px 60px 60px;gap:8px}
|
||||
.srcs .hd,.srcs .rw{grid-template-columns:minmax(0,1fr) 70px 70px 60px;gap:8px} .plc .hd,.plc .rw{grid-template-columns:minmax(0,1fr) 70px 60px;gap:8px}
|
||||
@media (max-width:900px){.two,.grid2,.sect{grid-template-columns:1fr}.body{padding:12px 16px}.mini{grid-template-columns:repeat(2,minmax(0,1fr))}.pages .hd,.pages .rw,.zones .hd,.zones .rw{grid-template-columns:minmax(0,1fr) 48px 48px 48px 48px;gap:6px;padding:10px 12px;font-size:12px}}
|
||||
</style>
|
||||
</head>
|
||||
@@ -51,6 +52,12 @@
|
||||
</div>
|
||||
<div class="panel"><h2>By page</h2><div class="tbl pages"><div class="hd"><span>Page</span><span class="r">Views</span><span class="r">Unique</span><span class="r">Clicks</span><span class="r">Leads</span></div><div id="pgRows"></div></div><div class="muted" style="margin-top:8px">Views exclude bots. Clicks are people who pressed the button on the page. Leads came in through the page's own form. <a href="/pages">Open Pages</a></div></div>
|
||||
</div>
|
||||
<!-- Traffic sources: clicks and conversions by the network a link is pointed at, and by the zone / placement / site its macro carried (2026-10-12) -->
|
||||
<div class="sec">Traffic sources</div>
|
||||
<div class="two sect">
|
||||
<div class="panel"><h2>By traffic source</h2><div class="tbl srcs"><div class="hd"><span>Source</span><span class="r">Clicks</span><span class="r">Unique</span><span class="r">Conv.</span></div><div id="tsRows"></div></div><div class="muted" style="margin-top:8px">A click counts for a source when the link it hit was pointed at that source at the time. Conversions are joins, leads, wallets, purchases and partner reports matched to those clicks. <a href="/sources">Open Sources</a></div></div>
|
||||
<div class="panel"><h2>Placements</h2><div class="tbl plc"><div class="hd"><span>Source · placement</span><span class="r">Clicks</span><span class="r">Conv.</span></div><div id="plRows"></div></div><div class="muted" style="margin-top:8px">The value the network's zone, placement, site, campaign, creative, banner or keyword macro carried on the click, top 12. Use it to cut the placements that click and never convert.</div></div>
|
||||
</div>
|
||||
<!-- Zones: ad-slot impressions on the member's own sites and the credits they earned (2026-10-10) -->
|
||||
<div class="sec">Zones</div>
|
||||
<div class="two sect">
|
||||
@@ -63,7 +70,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/cr-shell.js?v=20261011b"></script>
|
||||
<script src="/assets/reports.js?v=20261010a"></script>
|
||||
<script src="/assets/cr-shell.js?v=20261012a"></script>
|
||||
<script src="/assets/reports.js?v=20261012a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Traffic sources · LinkSpin</title>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Manrope:wght@400;500;700&family=JetBrains+Mono:wght@500;700&display=swap">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261012a">
|
||||
<style>
|
||||
.ws{display:grid;grid-template-columns:320px minmax(0,1fr);min-height:calc(100vh - 94px)}
|
||||
.list{border-right:1px solid var(--line);display:flex;flex-direction:column;min-height:0;background:rgba(255,255,255,.55)}
|
||||
.list .hd{display:flex;justify-content:space-between;align-items:center;padding:12px 16px;border-bottom:1px solid var(--line)}
|
||||
.list .hd h2{font-family:var(--display);font-size:20px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;margin:0}
|
||||
.list .flt{padding:8px 16px;border-bottom:1px solid var(--line)}
|
||||
.list .items{overflow:auto}
|
||||
.item{display:grid;grid-template-columns:minmax(0,1fr) 72px;gap:8px;padding:11px 16px;border-bottom:1px solid var(--line);border-left:3px solid transparent;cursor:pointer}
|
||||
.item:hover{background:rgba(31,111,235,.05)} .item.on{background:var(--panel);border-left-color:var(--sig)}
|
||||
.item .nm{font-weight:700;display:flex;gap:8px;align-items:center;flex-wrap:wrap} .item .cd{font-family:var(--mono);font-size:11px;color:var(--muted)}
|
||||
.item .rt{display:grid;justify-items:end;gap:3px} .item .rt .n{font-family:var(--mono)}
|
||||
.detail{display:flex;flex-direction:column;min-width:0}
|
||||
.dhead{display:flex;align-items:center;gap:14px;padding:12px 24px;border-bottom:1px solid var(--line);background:var(--panel);flex-wrap:wrap}
|
||||
.dhead h2{font-family:var(--display);font-size:24px;font-weight:700;letter-spacing:.02em;margin:0}
|
||||
.dbody{padding:16px 24px;display:grid;gap:14px}
|
||||
.dbody .tiles{grid-template-columns:repeat(auto-fit,minmax(128px,1fr))}
|
||||
.empty{padding:40px 24px;color:var(--muted);text-align:center;display:grid;gap:10px;justify-items:center}
|
||||
.empty .lead{max-width:520px}
|
||||
.urlbox{display:grid;gap:10px;align-content:start}
|
||||
.urlbox .code{display:block;font-size:12px;line-height:1.6;padding:10px 12px}
|
||||
.pick{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:10px;align-items:end}
|
||||
.prm .hd,.prm .rw{grid-template-columns:120px minmax(0,1fr) minmax(0,1fr)}
|
||||
.pe .hd,.pe .rw{grid-template-columns:150px minmax(0,1.3fr) minmax(0,1fr) 40px}
|
||||
.pe select.field{width:auto;min-width:130px}
|
||||
.log .hd,.log .rw{grid-template-columns:150px 90px minmax(0,1fr) 110px 50px}
|
||||
.chips .chip{user-select:none}
|
||||
.form{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
|
||||
.form .full{grid-column:1 / -1}
|
||||
.two{display:grid;grid-template-columns:minmax(0,1fr) 340px;gap:16px}
|
||||
.catf{margin:4px 0 8px}
|
||||
.catlist{max-height:46vh;overflow:auto;border:1px solid var(--line);border-radius:8px}
|
||||
.cat{display:flex;justify-content:space-between;align-items:center;gap:10px;padding:9px 12px;border-bottom:1px solid var(--line);cursor:pointer}
|
||||
.cat:last-child{border-bottom:0} .cat:hover{background:rgba(31,111,235,.05)} .cat b{display:block} .cat .site{font-family:var(--mono);font-size:11px;color:var(--muted)}
|
||||
.cat .tags{display:flex;gap:4px;flex-wrap:wrap;justify-content:flex-end}
|
||||
.prev{background:var(--panel-2);border:1px solid var(--line);border-radius:8px;padding:10px 12px;display:grid;gap:6px;font-size:12px}
|
||||
.prev .mono{font-size:11px;overflow-wrap:anywhere}
|
||||
.prev dl{display:grid;grid-template-columns:auto minmax(0,1fr);gap:3px 10px;margin:0} .prev dt{font-family:var(--mono);font-size:11px;color:var(--ink-2)} .prev dd{margin:0;font-family:var(--mono);font-size:11px;overflow-wrap:anywhere}
|
||||
@media (max-width:900px){.two{grid-template-columns:1fr}.form{grid-template-columns:1fr}.prm .hd,.log .hd,.pe .hd{display:none}.prm .rw{grid-template-columns:1fr}.log .rw{grid-template-columns:1fr 1fr}.pe .rw{grid-template-columns:1fr 1fr}}
|
||||
@media (max-width:760px){.ws{grid-template-columns:minmax(0,1fr)}.tabs{flex-wrap:wrap}.list{border-right:0;border-bottom:1px solid var(--line);max-height:44vh}.ws.focus .list{display:none}.ws:not(.focus) .detail{display:none}
|
||||
.dhead{padding:12px 16px}.dbody{padding:12px 16px}.pick{grid-template-columns:1fr}.tiles{grid-template-columns:repeat(2,minmax(0,1fr))}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="page">
|
||||
<div class="ws" id="ws">
|
||||
<div class="list">
|
||||
<div class="hd"><h2 id="listCount">Sources</h2><span class="muted mono">30 days</span></div>
|
||||
<div class="flt"><input class="field" id="filter" type="search" placeholder="Filter sources" aria-label="Filter sources"></div>
|
||||
<div class="items" id="items"></div>
|
||||
</div>
|
||||
<div class="detail" id="detail">
|
||||
<div class="empty" id="noSel">
|
||||
<div class="h-disp" style="font-size:18px">No traffic sources yet</div>
|
||||
<div class="muted lead">A source remembers a network's macros and postback so every link you point at it is tracked and the network learns what converts.</div>
|
||||
<button class="btn pri" type="button" id="newBtn2">+ New source</button>
|
||||
</div>
|
||||
<div id="sel" hidden>
|
||||
<div class="dhead">
|
||||
<button class="btn sm" type="button" id="backBtn" hidden>← Sources</button>
|
||||
<h2 id="dName">Source</h2>
|
||||
<span class="mono muted" id="dNet"></span>
|
||||
<span class="mono" id="dOn"></span>
|
||||
<span class="grow"></span>
|
||||
<button class="btn sm" type="button" id="togBtn">Disable</button>
|
||||
<button class="btn sm danger" type="button" id="delBtn">Delete</button>
|
||||
</div>
|
||||
<div class="dbody">
|
||||
<div class="tiles" id="tiles"></div>
|
||||
<div class="tabs" id="tabs">
|
||||
<button type="button" class="on" data-tab="url">Campaign URL</button>
|
||||
<button type="button" data-tab="pb">Postback</button>
|
||||
<button type="button" data-tab="settings">Settings</button>
|
||||
</div>
|
||||
<div id="tab-url">
|
||||
<div class="two">
|
||||
<div class="panel urlbox">
|
||||
<h2>Campaign URL</h2>
|
||||
<div class="pick"><label class="lbl">Which of your links<select class="field" id="urlRot"></select></label><button class="btn pri sm" type="button" id="urlCopy">Copy URL</button></div>
|
||||
<div class="code" id="urlOut">pick a link</div>
|
||||
<div class="muted" id="urlNote"></div>
|
||||
</div>
|
||||
<div class="panel"><h2>Params on the link</h2><div class="tbl prm"><div class="hd"><span>LinkSpin key</span><span>Network macro</span><span>Meaning</span></div><div id="prmRows"></div></div><div class="muted" style="font-size:11.5px">The network replaces each macro when it sends the click. LinkSpin keeps the values with the click and shows them under Reports and the link's Sources tab.</div></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="tab-pb" hidden>
|
||||
<div style="display:grid;gap:16px">
|
||||
<div class="panel urlbox">
|
||||
<h2>Postback to the network</h2>
|
||||
<div class="muted">Fires server to server when a click that came from this source converts. LinkSpin fills <span class="mono">{clickid}</span> with the id the network sent and <span class="mono">{payout}</span> with the value.</div>
|
||||
<div class="code" id="pbUrl">none set</div>
|
||||
<div><div class="sec" style="margin-bottom:6px">Fires on</div><div class="chips" id="pbEvents"></div></div>
|
||||
<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap"><button class="btn sm" type="button" id="pbTest">Send a test</button><span class="mono muted" id="pbStatus" style="font-size:11px"></span></div>
|
||||
</div>
|
||||
<div class="panel"><h2>Recent deliveries</h2><div class="tbl log"><div class="hd"><span>When</span><span>Event</span><span>URL</span><span>Result</span><span class="r">ms</span></div><div id="logRows"></div></div></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="tab-settings" hidden>
|
||||
<div class="panel">
|
||||
<h2>Settings</h2>
|
||||
<div class="form">
|
||||
<label class="lbl">Name<input class="field" id="sName" type="text" maxlength="60"></label>
|
||||
<label class="lbl">Network site<input class="field mono" id="sSite" type="text" maxlength="80" placeholder="network.com"></label>
|
||||
<label class="lbl">Cost model<input class="field mono" id="sCost" type="text" maxlength="20" placeholder="CPC, CPM, CPV"></label>
|
||||
<label class="lbl">Postback method<select class="field" id="sMethod"><option value="GET">GET</option><option value="POST">POST</option></select></label>
|
||||
<label class="lbl full">Postback URL, with {clickid} and {payout} where the network expects them (leave empty for URL tagging and reports only)<input class="field mono" id="sPb" type="text" placeholder="https://network.example/postback?cid={clickid}&payout={payout}"></label>
|
||||
</div>
|
||||
<div class="sec">Params</div>
|
||||
<div class="tbl pe"><div class="hd"><span>LinkSpin key</span><span>Network macro</span><span>Label</span><span></span></div><div id="peRows"></div><div class="ft">clickid is the network's click id; cost is what the click cost; the rest tag the click for reports. Tokens are pasted exactly as the network expands them.</div></div>
|
||||
<div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center"><button class="btn sm" type="button" id="peAdd">+ Add a param</button><span class="grow"></span><button class="btn pri" type="button" id="sSave">Save settings</button></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/cr-shell.js?v=20261012a"></script>
|
||||
<script src="/assets/sources-screen.js?v=20261012a"></script>
|
||||
</body>
|
||||
</html>
|
||||
+2
-2
@@ -6,7 +6,7 @@
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Team · LinkSpin</title>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Manrope:wght@400;500;700&family=JetBrains+Mono:wght@500;700&display=swap">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261011b">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261012a">
|
||||
<style>
|
||||
.body{padding:16px 24px;display:grid;gap:16px}
|
||||
.two{display:grid;grid-template-columns:minmax(0,1fr) 340px;gap:16px}
|
||||
@@ -37,7 +37,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/cr-shell.js?v=20261011b"></script>
|
||||
<script src="/assets/cr-shell.js?v=20261012a"></script>
|
||||
<script src="/assets/team.js?v=20260929a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Wallet · LinkSpin</title>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Manrope:wght@400;500;700&family=JetBrains+Mono:wght@500;700&display=swap">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261011b">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261012a">
|
||||
<style>
|
||||
.body{padding:16px 24px;display:grid;gap:16px}
|
||||
.two{display:grid;grid-template-columns:minmax(0,1fr) 380px;gap:16px}
|
||||
@@ -31,7 +31,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/cr-shell.js?v=20261011b"></script>
|
||||
<script src="/assets/cr-shell.js?v=20261012a"></script>
|
||||
<script src="/assets/wallet-screen.js?v=20261009a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+2
-2
@@ -6,7 +6,7 @@
|
||||
<meta name="robots" content="noindex, nofollow">
|
||||
<title>Zones · LinkSpin</title>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Manrope:wght@400;500;700&family=JetBrains+Mono:wght@500;700&display=swap">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261011b">
|
||||
<link rel="stylesheet" href="/assets/cr.css?v=20261012a">
|
||||
<style>
|
||||
.body{padding:16px 24px;display:grid;gap:16px}
|
||||
.two{display:grid;grid-template-columns:minmax(0,1fr) 380px;gap:16px}
|
||||
@@ -41,7 +41,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/cr-shell.js?v=20261011b"></script>
|
||||
<script src="/assets/cr-shell.js?v=20261012a"></script>
|
||||
<script src="/assets/zones-screen.js?v=20261010a"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+33
-9
@@ -11,7 +11,7 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
|
||||
let DATA_DIR = null, geo = null, OWN_HOSTS = () => [];
|
||||
let DATA_DIR = null, geo = null, OWN_HOSTS = () => [], SOURCES = null; // SOURCES = sources.js (traffic sources, 2026-10-12)
|
||||
const DAY = 86400000;
|
||||
const J = {
|
||||
db: null,
|
||||
@@ -19,7 +19,7 @@ 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 || (() => []); J.load(); }
|
||||
function init(opts) { DATA_DIR = opts.dataDir; geo = opts.geo || null; OWN_HOSTS = opts.ownHosts || (() => []); SOURCES = opts.sources || null; J.load(); }
|
||||
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;
|
||||
@@ -77,7 +77,7 @@ function pub(r) {
|
||||
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 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,
|
||||
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 || '',
|
||||
destinations: r.destinations.map(d => Object.assign({ hours: null, health: null, autoPaused: 0 }, d, { hits: (perDest[d.id] || { hits: 0 }).hits, hits7: (perDest[d.id] || { hits7: 0 }).hits7, uniques: (perDest[d.id] || { uniques: new Set() }).uniques.size })),
|
||||
hits: hits.length, hits7: hits.filter(h => h.ts >= since7).length, uniques: new Set(hits.map(h => h.v)).size, bots: hits.filter(h => h.bot).length };
|
||||
}
|
||||
@@ -114,6 +114,8 @@ async function update(owner, id, body) {
|
||||
if (body.paused != null) r.paused = !!body.paused;
|
||||
if (body.hours !== undefined) { const h = cleanHours(body.hours); if (h.error) return h; if (h.hours) r.hours = h.hours; else delete r.hours; }
|
||||
if (body.tz !== undefined) { const t = cleanTz(body.tz); if (t.error) return t; if (t.tz === 'visitor') delete r.tz; else r.tz = t.tz; }
|
||||
// traffic source attachment: '' detaches; otherwise it must be one of the owner's own sources
|
||||
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) };
|
||||
}
|
||||
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.' }; }
|
||||
@@ -160,9 +162,10 @@ async function resolve(code, req) {
|
||||
const ref = String(req.headers.referer || ''); let src = 'direct'; try { if (ref) src = new URL(ref).hostname.replace(/^www\./, ''); } catch (e) {}
|
||||
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)$/.test(key)) { q[key] = String(val).slice(0, 200); n++; } } } catch (e) {}
|
||||
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) {}
|
||||
const id = crypto.randomBytes(6).toString('hex').slice(0, 10);
|
||||
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 = 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 });
|
||||
if (J.db.hits.length > 200000) J.db.hits = J.db.hits.slice(-150000);
|
||||
J.save();
|
||||
let out = url;
|
||||
@@ -179,9 +182,22 @@ async function resolve(code, req) {
|
||||
async function convert(lsid, ev, facts) {
|
||||
const h = J.db.hits.find(x => x.id === String(lsid)); if (!h) return 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 }); 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 };
|
||||
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(); }
|
||||
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 || '' };
|
||||
}
|
||||
// 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));
|
||||
const since = Date.now() - (Number(days) || 30) * DAY; const out = {};
|
||||
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 k in out) out[k].unique = out[k].unique.size;
|
||||
return out;
|
||||
}
|
||||
// a source was deleted: its links go back to having none
|
||||
async function detachSource(owner, sid) { let n = 0; for (const r of J.db.rotations) if (r.owner === norm(owner) && r.sourceId === String(sid)) { delete r.sourceId; n++; } if (n) J.save(); return n; }
|
||||
const ctDay = ts => new Date(ts).toLocaleDateString('en-CA', { timeZone: 'America/Chicago' });
|
||||
// one view across everything a member owns, for Reports
|
||||
async function summary(owner, days) {
|
||||
@@ -194,8 +210,16 @@ async function summary(owner, days) {
|
||||
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 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) : {};
|
||||
const srcMap = {}; for (const h of hits) if (h.sr) { const o = srcMap[h.sr] = srcMap[h.sr] || { hits: 0, u: new Set(), conv: 0 }; o.hits++; o.u.add(h.v); }
|
||||
for (const c of conv) if (c.sr) { const o = srcMap[c.sr] = srcMap[c.sr] || { hits: 0, u: new Set(), conv: 0 }; o.conv++; }
|
||||
const sources = Object.entries(srcMap).map(([id, o]) => ({ id, name: (meta[id] || {}).name || 'Deleted source', site: (meta[id] || {}).site || '', hits: o.hits, unique: o.u.size, conv: o.conv })).sort((a, b) => b.hits - a.hits);
|
||||
const convByHit = {}; for (const c of conv) convByHit[c.lsid] = (convByHit[c.lsid] || 0) + 1;
|
||||
const plMap = {}; for (const h of hits) { if (!h.sr || !h.q) continue; const pk = (meta[h.sr] || {}).placementKey; if (!pk || h.q[pk] == null || h.q[pk] === '') continue; const key = h.sr + '\u0000' + h.q[pk]; const o = plMap[key] = plMap[key] || { source: (meta[h.sr] || {}).name || 'Deleted source', sourceId: h.sr, key: pk, k: h.q[pk], n: 0, conv: 0 }; o.n++; o.conv += convByHit[h.id] || 0; }
|
||||
const placements = Object.values(plMap).sort((a, b) => b.n - a.n).slice(0, 12);
|
||||
return { links: mine.length, totals: { served: hits.length, unique: new Set(hits.map(h => h.v)).size, bots: all.length - hits.length, joins: convBy.join || 0, wallets: convBy.wallet || 0, purchases: convBy.purchase || 0, external: convBy.external || 0 },
|
||||
days: dlist, source: by('s'), country: by('c'), device: by('dv'), hours, top, conversions: Object.entries(convBy).map(([k, n]) => ({ k, n })).sort((a, b) => b.n - a.n) };
|
||||
days: dlist, source: by('s'), country: by('c'), device: by('dv'), hours, top, conversions: Object.entries(convBy).map(([k, n]) => ({ k, n })).sort((a, b) => b.n - a.n), sources, placements };
|
||||
}
|
||||
async function stats(owner, id) {
|
||||
const r = J.db.rotations.find(r => r.id === Number(id) && r.owner === norm(owner)); if (!r) return null;
|
||||
@@ -249,4 +273,4 @@ const rawRotations = () => J.db.rotations;
|
||||
const save = () => J.save();
|
||||
const findMine = (owner, id) => J.db.rotations.find(r => r.id === Number(id) && r.owner === norm(owner)) || null;
|
||||
module.exports = { init, list, get, create, update, remove, addDest, updateDest, resolve, stats, totals, convert, summary, createDemo, claim, sweepDemos, servedToday,
|
||||
pub, rawRotations, save, findMine, PRESETS, cleanHours, cleanTz, cellAt, zoneFor, isOn, COUNTRY_TZ };
|
||||
pub, rawRotations, save, findMine, PRESETS, cleanHours, cleanTz, cellAt, zoneFor, isOn, COUNTRY_TZ, sourceCounts, detachSource };
|
||||
|
||||
@@ -41,6 +41,7 @@ const carry = require('./carry'); // sponsor carry-over: engine acti
|
||||
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 sources = require('./sources'); // traffic sources: network macros, campaign URLs, per-source postbacks, Reports dimension (2026-10-12)
|
||||
const pages = require('./pages'); // member pages: bridge / review / squeeze, served at /p/<slug> (2026-09-29)
|
||||
const domains = require('./domains'); // link-domain pool by channel + six-hourly safety checks; burned domains leave the pool (2026-10-10)
|
||||
const zonereport = require('./zonereport'); // read-only zone numbers for member Reports (2026-10-10)
|
||||
@@ -415,13 +416,14 @@ async function boot() {
|
||||
registry.init({ dataDir: DATA_DIR });
|
||||
carry.init({ dataDir: DATA_DIR, accounts, registry, chain, mailer, messages, siteConfig, adminEmail: ADMIN_EMAIL, host: SITE_HOST });
|
||||
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 });
|
||||
rotator.init({ dataDir: DATA_DIR, geo, ownHosts, sources });
|
||||
// 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)
|
||||
health.init({ rotator, dataDir: DATA_DIR, notify: (email, subject, html) => messages.deliver(1, ADMIN_EMAIL || 'house@' + SITE_HOST, [email], subject, html) });
|
||||
setTimeout(() => health.tick().catch(e => console.error('health', e.message)), 2 * 60 * 1000);
|
||||
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 });
|
||||
postbacks.init({ dataDir: DATA_DIR, ownHosts, rotator, sources });
|
||||
sources.init({ dataDir: DATA_DIR, postbacks, rotator, catalogFile: path.join(ROOT, 'data', '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 ''; } } });
|
||||
audiences.init({ dataDir: DATA_DIR });
|
||||
@@ -991,7 +993,7 @@ const server = http.createServer(async (req, res) => {
|
||||
const b = {}; try { const ct = String(req.headers['content-type'] || ''); if (/json/.test(ct)) Object.assign(b, JSON.parse(raw)); else for (const [k, v] of new URLSearchParams(raw)) b[k] = v; } catch (e) {}
|
||||
const r = await pages.lead(pm[1], b, req);
|
||||
if (r.error) { res.writeHead(400, { 'Content-Type': 'text/html; charset=utf-8' }); return res.end('<!doctype html><title>Try again</title><p style="font-family:system-ui;padding:40px">' + r.error + ' <a href="javascript:history.back()">Go back</a></p>'); }
|
||||
if (r.owner && r.lsid) { try { postbacks.bindClick(String(b.email || '').toLowerCase(), r.lsid); const hit = await rotator.convert(r.lsid, 'lead', {}); if (hit) postbacks.fire(hit.owner, 'lead', Object.assign({ q: hit.q || {}, source: hit.s, country: hit.c, device: hit.dv, lsid: r.lsid, code: hit.code })).catch(() => {}); } catch (e) {} }
|
||||
if (r.owner && r.lsid) { try { postbacks.bindClick(String(b.email || '').toLowerCase(), r.lsid); const hit = await rotator.convert(r.lsid, 'lead', {}); if (hit) postbacks.fire(hit.owner, 'lead', Object.assign({ q: hit.q || {}, source: hit.s, country: hit.c, device: hit.dv, lsid: r.lsid, code: hit.code, sourceId: hit.sourceId || '' })).catch(() => {}); } catch (e) {} }
|
||||
res.writeHead(302, { Location: r.next || '/', 'Cache-Control': 'no-store' }); return res.end();
|
||||
}
|
||||
if (p.startsWith('/api/p/') && req.method === 'POST' && /\/hit$/.test(p)) { const sl = p.split('/')[3]; const pg = pages.bySlug(sl); if (pg) pages.view(pg, req, 'cta'); res.writeHead(204); return res.end(); }
|
||||
@@ -2076,6 +2078,22 @@ 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)]);
|
||||
return json(res, 200, Object.assign({}, spins, { spins, pages: pg, zones: zn, days: spins.days, range: days }), { 'Cache-Control': 'no-store' });
|
||||
}
|
||||
// -- traffic sources (2026-10-12). Every route takes GET and POST: the shell's api() helper always POSTs.
|
||||
if (p === '/api/sources/catalog' && (req.method === 'GET' || req.method === 'POST')) return json(res, 200, { catalog: sources.catalog(), keys: sources.KEYS }, { 'Cache-Control': 'public, max-age=300' });
|
||||
if (p === '/api/my/sources' && (req.method === 'GET' || req.method === 'POST')) {
|
||||
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
|
||||
const b = req.method === 'POST' ? await readBody(req) : {};
|
||||
if (req.method === 'GET' || b.list || !Object.keys(b).length) return json(res, 200, await sources.list(s.email), { 'Cache-Control': 'no-store' });
|
||||
const r = await sources.create(s.email, b); return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
m = /^\/api\/my\/sources\/([a-f0-9]{10})(\/url)?$/.exec(p);
|
||||
if (m && (req.method === 'GET' || req.method === 'POST')) {
|
||||
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
|
||||
const b = req.method === 'POST' ? await readBody(req) : {}; for (const [k, v] of u.searchParams) if (b[k] == null) b[k] = v;
|
||||
if (m[2]) { const r = await sources.urlFor(s.email, m[1], b.rotationId); return json(res, r.error ? 400 : 200, r, { 'Cache-Control': 'no-store' }); }
|
||||
if (req.method === 'GET' || !Object.keys(b).length) { const r = await sources.get(s.email, m[1]); return r ? json(res, 200, r, { 'Cache-Control': 'no-store' }) : json(res, 404, { error: 'No such source.' }); }
|
||||
const r = b.test ? await sources.test(s.email, m[1]) : await sources.update(s.email, m[1], b); return json(res, r.error ? 400 : 200, r);
|
||||
}
|
||||
if (p === '/api/my/postbacks' && req.method === 'GET') {
|
||||
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
|
||||
return json(res, 200, { postbacks: await postbacks.list(s.email), events: postbacks.EVENTS, key: postbacks.partnerKey(s.email), inboundUrl: 'https://' + SITE_HOST + '/pb/in', log: await postbacks.logFor(s.email, 40) }, { 'Cache-Control': 'no-store' });
|
||||
@@ -3160,6 +3178,7 @@ const server = http.createServer(async (req, res) => {
|
||||
if (p === '/reports') return sendFile(res, path.join(PUBLIC_DIR, 'reports.html'));
|
||||
if (p === '/pages') return sendFile(res, path.join(PUBLIC_DIR, 'pages.html'));
|
||||
if (p === '/zones') return sendFile(res, path.join(PUBLIC_DIR, 'zones.html'));
|
||||
if (p === '/sources') return sendFile(res, path.join(PUBLIC_DIR, 'sources.html')); // Control Room: traffic sources, network macros + postbacks (2026-10-12)
|
||||
if (p === '/ads') return sendFile(res, path.join(PUBLIC_DIR, 'ads.html'));
|
||||
if (p === '/team') return sendFile(res, path.join(PUBLIC_DIR, 'team.html'));
|
||||
if (p === '/wallet') return sendFile(res, path.join(PUBLIC_DIR, 'wallet.html'));
|
||||
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
// Traffic sources (LinkSpin, 2026-10-12): a first-class record of the network a member buys traffic on.
|
||||
// A source remembers the network's macro tokens (so the campaign URL to paste into the network is built for
|
||||
// the member), the network's own conversion postback (fired only for clicks that came through that source),
|
||||
// and shows up in Reports as a dimension (clicks and conversions by source, and by zone / placement / site when
|
||||
// the macro carried it). Sources are created from a template catalog (data/traffic-sources.json, shipped in the
|
||||
// repo, read at boot) or defined by hand. JSON store on the volume, same pattern as postbacks.js.
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const crypto = require('crypto');
|
||||
|
||||
let DATA_DIR = null, postbacks = null, rotator = null, linkHost = () => '', CATALOG = [];
|
||||
const J = { db: null, FILE: () => path.join(DATA_DIR, 'sources.json'),
|
||||
load() { try { this.db = JSON.parse(fs.readFileSync(this.FILE(), 'utf8')); } catch (e) { this.db = { v: 1, items: [] }; } if (!Array.isArray(this.db.items)) this.db.items = []; },
|
||||
save() { try { fs.writeFileSync(this.FILE(), JSON.stringify(this.db)); } catch (e) {} } };
|
||||
const norm = e => String(e || '').trim().toLowerCase();
|
||||
// the query keys a LinkSpin link understands (rotator.resolve keeps these per click)
|
||||
const KEYS = ['clickid', 'cost', 'zone', 'placement', 'site', 'campaign', 'creative', 'banner', 'keyword', 'geo', 'os', 'browser', 'device', 'carrier', 'format', 'source', 's1', 's2', 's3', 's4', 's5'];
|
||||
// which of those count as "a placement" for the Reports breakdown, first match per source wins
|
||||
const PLACEMENT_KEYS = ['zone', 'placement', 'site', 'campaign', 'creative', 'banner', 'keyword'];
|
||||
const LIMITS = { perAccount: 30, params: 20, token: 60, name: 60, site: 80 };
|
||||
const SLOT = /\{\{([^{}]{1,60})\}\}/g; // account-specific slots in a catalog postback, filled by the member at create time; labels may carry spaces and parentheses, e.g. {{member_id (optional)}}
|
||||
const OPTIONAL = /\(optional\)/i; // an optional slot left empty is dropped rather than refused
|
||||
const str = (v, max) => (v == null ? '' : String(v)).trim().slice(0, max);
|
||||
|
||||
// catalog: tolerant loader (a later harvest replaces the file with ~100 networks in the same shape; missing fields are fine)
|
||||
function loadCatalog(file) {
|
||||
let raw = []; try { raw = JSON.parse(fs.readFileSync(file, 'utf8')); } catch (e) { raw = []; }
|
||||
if (!Array.isArray(raw)) raw = Array.isArray(raw.networks) ? raw.networks : [];
|
||||
const seen = new Set(); const out = [];
|
||||
for (const n of raw) {
|
||||
if (!n || typeof n !== 'object') continue;
|
||||
const key = str(n.key, 40).toLowerCase().replace(/[^a-z0-9_-]/g, ''); const name = str(n.name, LIMITS.name);
|
||||
if (!key || !name || seen.has(key)) continue; seen.add(key);
|
||||
const params = cleanParams(n.params).params || [];
|
||||
const postbackUrl = str(n.postbackUrl, 1500);
|
||||
out.push({ key, name, site: str(n.site, LIMITS.site), costModel: str(n.costModel, 20), params, postbackUrl, notes: str(n.notes, 300), verified: !!n.verified, source: str(n.source, 80),
|
||||
hasClickId: params.some(p => p.key === 'clickid'), hasPostback: !!postbackUrl, slots: Array.from(new Set((postbackUrl.match(SLOT) || []).map(s => s.slice(2, -2).trim()))) });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
function init(opts) { DATA_DIR = opts.dataDir; postbacks = opts.postbacks; rotator = opts.rotator; linkHost = opts.linkHost || linkHost; CATALOG = loadCatalog(opts.catalogFile || path.join(__dirname, 'data', 'traffic-sources.json')); J.load(); }
|
||||
function catalog() { return CATALOG; }
|
||||
const template = key => CATALOG.find(c => c.key === key) || null;
|
||||
|
||||
function cleanParams(list) {
|
||||
if (list == null) return { params: [] };
|
||||
if (!Array.isArray(list)) return { error: 'Params must be a list.' };
|
||||
const out = []; const used = new Set();
|
||||
for (const p of list) {
|
||||
if (!p || typeof p !== 'object') continue;
|
||||
const key = String(p.key || '').trim().toLowerCase(); const token = String(p.token || '').trim();
|
||||
if (!key && !token) continue;
|
||||
if (!KEYS.includes(key)) return { error: 'Unknown param key "' + key.slice(0, 20) + '". Use one of: ' + KEYS.join(', ') + '.' };
|
||||
if (!token) return { error: 'Give the ' + key + ' param the network\'s macro token.' };
|
||||
if (token.length > LIMITS.token) return { error: 'A macro token can be at most ' + LIMITS.token + ' characters.' };
|
||||
if (/[\s"'<>]/.test(token)) return { error: 'A macro token cannot contain spaces or quotes.' };
|
||||
if (used.has(key)) return { error: 'The key ' + key + ' is listed twice.' };
|
||||
used.add(key);
|
||||
out.push({ key, token, label: String(p.label || '').trim().slice(0, 40), role: p.role === 'externalId' || p.role === 'cost' ? p.role : (key === 'clickid' ? 'externalId' : key === 'cost' ? 'cost' : 'param') });
|
||||
if (out.length > LIMITS.params) return { error: 'Up to ' + LIMITS.params + ' params per source.' };
|
||||
}
|
||||
return { params: out };
|
||||
}
|
||||
function cleanEvents(ev) { const list = (Array.isArray(ev) ? ev : String(ev || '').split(',')).map(x => String(x).trim().toLowerCase()).filter(x => postbacks.EVENTS.includes(x)); return Array.from(new Set(list)); }
|
||||
// a postback template may be empty (URL builder + reports only); when set it must be a public URL with no {{slot}} left
|
||||
function cleanPostback(url) {
|
||||
const t = String(url || '').trim(); if (!t) return { url: '' };
|
||||
if (SLOT.test(t)) { SLOT.lastIndex = 0; return { error: 'Fill in every {{...}} slot of the postback first.' } } SLOT.lastIndex = 0;
|
||||
const bad = postbacks.validateUrl(t); if (bad) return { error: bad };
|
||||
return { url: t };
|
||||
}
|
||||
// fill {{Label}} slots from body.slots ({ Label: value }); an empty required slot stays so cleanPostback can refuse it, an empty optional one becomes ''
|
||||
function fillSlots(tpl, slots) { const s = slots && typeof slots === 'object' ? slots : {}; return String(tpl || '').replace(SLOT, (m, label) => { const k = label.trim(); const v = s[k] != null ? String(s[k]).trim() : ''; return v ? encodeURIComponent(v.slice(0, 120)) : (OPTIONAL.test(k) ? '' : m); }); }
|
||||
|
||||
function mine(owner) { return J.db.items.filter(s => s.owner === norm(owner)); }
|
||||
function pub(s) {
|
||||
return { id: s.id, name: s.name, template: s.template, site: s.site || '', costModel: s.costModel || '', params: (s.params || []).map(p => ({ key: p.key, token: p.token, label: p.label || '', role: p.role })),
|
||||
postbackUrl: s.postbackUrl || '', method: s.method || 'GET', events: s.events || [], enabled: !!s.enabled, created: s.created, sent: s.sent || 0, fails: s.fails || 0, lastStatus: s.lastStatus || null, lastAt: s.lastAt || 0,
|
||||
placementKey: placementKey(s) };
|
||||
}
|
||||
const placementKey = s => { const p = (s.params || []).find(x => PLACEMENT_KEYS.includes(x.key)); return p ? p.key : ''; };
|
||||
const find = (owner, id) => J.db.items.find(s => s.id === String(id) && s.owner === norm(owner)) || null;
|
||||
|
||||
async function list(owner) {
|
||||
const items = mine(owner);
|
||||
const counts = rotator && rotator.sourceCounts ? await rotator.sourceCounts(owner, 30) : {};
|
||||
return { sources: items.map(s => Object.assign(pub(s), { hits30: (counts[s.id] || {}).hits || 0, unique30: (counts[s.id] || {}).unique || 0, conv30: (counts[s.id] || {}).conv || 0, links: (counts[s.id] || {}).links || 0 })),
|
||||
inUse: Array.from(new Set(items.map(s => s.template).filter(k => k && k !== 'custom'))), keys: KEYS, events: postbacks.EVENTS, limits: LIMITS };
|
||||
}
|
||||
async function create(owner, body) {
|
||||
if (mine(owner).length >= LIMITS.perAccount) return { error: 'Up to ' + LIMITS.perAccount + ' sources per account.' };
|
||||
const tplKey = String(body.template || 'custom').trim().toLowerCase(); const tpl = tplKey !== 'custom' ? template(tplKey) : null;
|
||||
if (tplKey !== 'custom' && !tpl) return { error: 'No such network template.' };
|
||||
const name = String(body.name || (tpl ? tpl.name : '')).trim().slice(0, LIMITS.name); if (!name) return { error: 'Give the source a name.' };
|
||||
const pr = cleanParams(body.params != null ? body.params : (tpl ? tpl.params : [{ key: 'clickid', token: '{clickid}', label: 'Click id' }])); if (pr.error) return pr;
|
||||
const pbIn = body.postbackUrl != null ? String(body.postbackUrl) : (tpl ? fillSlots(tpl.postbackUrl, body.slots) : '');
|
||||
const pb = cleanPostback(pbIn); if (pb.error) return pb;
|
||||
const events = cleanEvents(body.events != null ? body.events : ['join', 'lead', 'purchase']);
|
||||
const s = { id: crypto.randomBytes(5).toString('hex'), owner: norm(owner), name, template: tpl ? tpl.key : 'custom', site: String(body.site != null ? body.site : (tpl ? tpl.site : '')).trim().slice(0, LIMITS.site),
|
||||
costModel: String(body.costModel != null ? body.costModel : (tpl ? tpl.costModel : '')).trim().slice(0, 20), params: pr.params, postbackUrl: pb.url, method: String(body.method || 'GET').toUpperCase() === 'POST' ? 'POST' : 'GET',
|
||||
events: events.length ? events : ['join', 'lead', 'purchase'], enabled: body.enabled != null ? !!body.enabled : true, created: Date.now(), sent: 0, fails: 0 };
|
||||
J.db.items.push(s); J.save(); return { ok: true, source: pub(s) };
|
||||
}
|
||||
async function update(owner, id, body) {
|
||||
const s = find(owner, id); if (!s) return { error: 'No such source.' };
|
||||
if (body.remove) { J.db.items = J.db.items.filter(x => x !== s); J.save(); if (rotator && rotator.detachSource) await rotator.detachSource(owner, s.id); return { ok: true, removed: true }; }
|
||||
if (body.name != null) s.name = String(body.name).trim().slice(0, LIMITS.name) || s.name;
|
||||
if (body.site != null) s.site = String(body.site).trim().slice(0, LIMITS.site);
|
||||
if (body.costModel != null) s.costModel = String(body.costModel).trim().slice(0, 20);
|
||||
if (body.params != null) { const pr = cleanParams(body.params); if (pr.error) return pr; s.params = pr.params; }
|
||||
if (body.postbackUrl != null) { const pb = cleanPostback(body.postbackUrl); if (pb.error) return pb; s.postbackUrl = pb.url; s.fails = 0; }
|
||||
if (body.events != null) { const ev = cleanEvents(body.events); if (ev.length) s.events = ev; }
|
||||
if (body.method != null) s.method = String(body.method).toUpperCase() === 'POST' ? 'POST' : 'GET';
|
||||
if (body.enabled != null) { s.enabled = !!body.enabled; if (s.enabled) s.fails = 0; }
|
||||
J.save(); return { ok: true, source: pub(s) };
|
||||
}
|
||||
async function get(owner, id) { const s = find(owner, id); if (!s) return null; return { source: pub(s), log: await postbacks.logForSource(owner, s.id, 30) }; }
|
||||
// the campaign URL for one of the member's links: the link + every param as key=token (tokens are macros, never encoded)
|
||||
async function urlFor(owner, id, rotationId) {
|
||||
const s = find(owner, id); if (!s) return { error: 'No such source.' };
|
||||
const r = rotator.findMine(owner, rotationId); if (!r) return { error: 'No such link.' };
|
||||
const base = 'https://' + (linkHost() || 'linkspin.app') + '/r/' + r.code;
|
||||
const qs = (s.params || []).map(p => p.key + '=' + p.token).join('&');
|
||||
return { url: qs ? base + '?' + qs : base, params: s.params, network: s.name, site: s.site || '' };
|
||||
}
|
||||
// test delivery with sample values, same shape as postbacks.test
|
||||
async function test(owner, id) {
|
||||
const s = find(owner, id); if (!s) return { error: 'No such source.' };
|
||||
if (!s.postbackUrl) return { error: 'This source has no postback URL yet. Add one under Settings.' };
|
||||
const ev = (s.events || [])[0] || 'join';
|
||||
const url = postbacks.fill(s.postbackUrl, { clickid: 'test-click-123', subid: 'test-sub', s1: 'test-s1', s2: '', s3: '', s4: '', s5: '', source: 'test', event: ev, payout: '0.00', currency: 'USD', txid: '0xtest', lsid: 'testlsid', code: 'test', country: 'US', device: 'desktop' });
|
||||
const r = await postbacks.deliver(s, url, { event: ev, lsid: 'testlsid', test: true, viaSource: s.id }); J.save();
|
||||
return { ok: r.ok, status: r.status, note: r.note, url };
|
||||
}
|
||||
// for postbacks.fire: the raw record (deliver() writes sent/fails/lastStatus straight onto it), then save()
|
||||
function forFire(owner, id) { const s = find(owner, id); return s && s.enabled && s.postbackUrl ? s : null; }
|
||||
function save() { J.save(); }
|
||||
// name + placement key per source, for rotator.summary
|
||||
function meta(owner) { const m = {}; for (const s of mine(owner)) m[s.id] = { name: s.name, placementKey: placementKey(s), site: s.site || '' }; return m; }
|
||||
module.exports = { init, catalog, list, create, update, get, urlFor, test, find, forFire, save, meta, KEYS, PLACEMENT_KEYS, LIMITS };
|
||||
Reference in New Issue
Block a user