diff --git a/ads.js b/ads.js index 90d278e..15bbd9c 100644 Binary files a/ads.js and b/ads.js differ diff --git a/audiences.js b/audiences.js new file mode 100644 index 0000000..d1411e3 --- /dev/null +++ b/audiences.js @@ -0,0 +1,100 @@ +// First-party retargeting (Marty 2026-10-08): audiences a member can target or exclude with their campaigns. +// - An audience is a list of visitors. Visitors are keyed by the ls.vid cookie (set by the pixel and by zone serves), +// with a soft fallback key (hash of IP + user agent, 24 h) for browsers that refuse the cross-site cookie. +// - Every member has one automatic audience, "My visitors": fed by views of their LinkSpin pages and by any zone they +// run. Extra audiences come from the pixel tag ('; + return head + body + foot + '' + (opts.pixel ? '' : '') + ''; } module.exports = { render, PALETTE_NAMES, knobs, catalog: S.catalog }; diff --git a/public/ads.html b/public/ads.html index 9a5330e..3899d3a 100644 --- a/public/ads.html +++ b/public/ads.html @@ -33,6 +33,8 @@ + +
@@ -60,6 +62,6 @@
- + diff --git a/public/assets/ads-screen.js b/public/assets/ads-screen.js index 8f0c6f6..cbf5483 100644 --- a/public/assets/ads-screen.js +++ b/public/assets/ads-screen.js @@ -13,6 +13,7 @@ async function load() { try { [D, EARN] = await Promise.all([CR.get('/api/my/campaigns'), CR.get('/api/my/earn')]); } catch (e) { CR.sub('could not load'); return; } const cs = D.campaigns || []; const live = cs.filter(c => c.status === 'active'); + { const sel = $('fAud'); if (sel) { const keep = sel.value; sel.innerHTML = '' + (D.audiences || []).map(a => '').join(''); sel.value = keep; sel.onchange = () => { $('fAudModeRow').hidden = !sel.value; }; } } const views = cs.reduce((n, c) => n + (c.imps || 0) + (c.impsNas || 0), 0); CR.sub(live.length + ' live · ' + fmt(D.availableCredits) + ' credits available'); const hours = new Array(24).fill(0); Object.values(D.hours || {}).forEach(a => (a || []).forEach((n, i) => { hours[i] += Number(n) || 0; })); // last 7 days by UTC hour, all campaigns @@ -26,7 +27,7 @@ $('rateLine').textContent = 'Rates: ' + r.bannerCreditsPerBatch + ' credits per ' + r.bannerBatch + ' banner views, ' + r.textCreditsPerBatch + ' per ' + r.textBatch + ' text views, ' + r.loginCreditsPerDay + ' per day for the login spot. Viewing pays ' + EARN.claimCredits + ' credits for ' + EARN.target + ' timed views a day.'; const st = c => c.scheduled ? 'Scheduled' : c.status === 'active' ? 'Live' : c.status === 'paused' ? 'Paused' : c.status === 'out' ? 'Out of credits' : c.status === 'done' ? 'Ended' : '' + esc(c.status) + ''; const cr = c => c.type === 'banner' ? (c.imageUrl ? '' : '') + '' + c.width + 'x' + c.height + '' : c.type === 'text' ? '' + esc(c.title) + '
' + esc(c.body || '') + '' : 'full page'; - $('rows').innerHTML = cs.length ? cs.map(c => '
' + esc(c.name) + ' ' + esc(c.type) + '
#' + c.id + ' · ' + esc(host(c.targetUrl)) + (c.geo ? ' · tiers ' + esc(c.geo) : '') + (c.dailyCap ? ' · cap ' + c.dailyCap + '/day' : '') + '
' + cr(c) + '
' + fmt(c.spent) + ' / ' + fmt(c.budget) + '
' + fmt(c.imps) + (c.impsNas ? '
+' + fmt(c.impsNas) + ' network' : '') + '
' + fmt(c.clicks) + '' + st(c) + '' + $('rows').innerHTML = cs.length ? cs.map(c => '
' + esc(c.name) + ' ' + esc(c.type) + '' + (c.audience ? ' ' + esc((((D && D.audiences) || []).find(a => a.id === c.audience) || {}).name || 'audience') + (c.audienceMode === 'exclude' ? ' · excluded' : '') + '' : '') + '
#' + c.id + ' · ' + esc(host(c.targetUrl)) + (c.geo ? ' · tiers ' + esc(c.geo) : '') + (c.dailyCap ? ' · cap ' + c.dailyCap + '/day' : '') + '
' + cr(c) + '
' + fmt(c.spent) + ' / ' + fmt(c.budget) + '
' + fmt(c.imps) + (c.impsNas ? '
+' + fmt(c.impsNas) + ' network' : '') + '
' + fmt(c.clicks) + '' + st(c) + '' + (c.status === 'active' ? '' : c.status === 'paused' ? '' : '') + (['active', 'paused', 'out'].includes(c.status) ? '' : '') + '
').join('') : '
No ads yet. Launch one: a banner, a text ad or the login spot.
'; @@ -90,6 +91,7 @@ $('fGo').addEventListener('click', async () => { const body = { type: TYPE, name: $('fName').value, targetUrl: $('fTarget').value.trim(), budget: Number($('fBudget').value), geo: $('fGeo').value }; if (TYPE !== 'login' && $('fCap').value) body.dailyCap = Number($('fCap').value); + if ($('fAud') && $('fAud').value) { body.audience = $('fAud').value; body.audienceMode = $('fAudMode').value; } if (TYPE === 'banner') { body.size = $('fSize').value; body.imageUrl = $('fImage').value.trim(); } if (TYPE === 'text') { body.title = $('fTitle').value; body.body = $('fBody').value; } $('fGo').disabled = true; diff --git a/public/assets/zones-screen.js b/public/assets/zones-screen.js index 3049003..162938e 100644 --- a/public/assets/zones-screen.js +++ b/public/assets/zones-screen.js @@ -26,5 +26,21 @@ const v = await dialog({ title: 'Add a zone', text: 'One zone per spot on a page. Paid ads only serve on the site you name here; anywhere else the tag shows the house banner.', fields: [{ k: 'name', label: 'Name', placeholder: 'My blog · sidebar', max: 60 }, { k: 'site', label: 'Site it lives on (required)', placeholder: 'myblog.com', max: 80 }, { k: 'size', label: 'Size: ' + (SIZES.join(', ') || '728x90, 468x60, 300x250, 160x600, 320x50'), value: '728x90', mono: true }], ok: 'Create' }); if (!v) return; try { const r = await api('/api/my/zones', v); SEL = r.zone.id; toast('Zone created. Copy the tag.'); load(); } catch (e) { toast(e.message, true); } }); - CR.requireSession(load); + // ---- audiences (first-party retargeting) + const ptag = a => ''; + async function loadAudiences() { + let r; try { r = await CR.get('/api/my/audiences'); } catch (e) { return; } + const A = r.audiences || []; HOST = r.host || HOST; + $('audList').innerHTML = A.map(a => '
' + esc(a.name) + '' + + '' + fmt(a.size30) + ' in 30 d · ' + fmt(a.size7) + ' in 7 d' + (a.soft ? ' · ' + fmt(a.soft) + ' without cookie (24 h)' : '') + '
' + + (a.auto ? '
Automatic: your pages and your zones feed it. You can also paste its pixel elsewhere.
' : '') + + '
' + esc(ptag(a)) + '
' + + '
' + + (a.auto ? '' : '') + '
').join(''); + $('audList').querySelectorAll('[data-copy]').forEach(b => b.addEventListener('click', () => CR.copy(ptag(A.find(a => a.id === b.dataset.copy))))); + $('audList').querySelectorAll('[data-ren]').forEach(b => b.addEventListener('click', async () => { const a = A.find(x => x.id === b.dataset.ren); const v = await dialog({ title: 'Rename audience', fields: [{ k: 'name', label: 'Name', value: a.name }], ok: 'Save' }); if (!v) return; try { await api('/api/my/audiences', { id: a.id, name: v.name }); toast('Renamed'); loadAudiences(); } catch (e) { toast(e.message, true); } })); + $('audList').querySelectorAll('[data-del]').forEach(b => b.addEventListener('click', async () => { const a = A.find(x => x.id === b.dataset.del); if (!await dialog({ title: 'Remove ' + a.name + '?', text: 'Its visitor list is deleted. Campaigns that used it stop matching anyone.', ok: 'Remove', danger: true })) return; try { await api('/api/my/audiences', { id: a.id, remove: true }); toast('Removed'); loadAudiences(); } catch (e) { toast(e.message, true); } })); + } + $('audNew').addEventListener('click', async () => { const v = await dialog({ title: 'New audience', text: 'Name it after where the pixel will go, like "Blog readers" or "Checkout page".', fields: [{ k: 'name', label: 'Name', placeholder: 'Blog readers' }], ok: 'Create' }); if (!v) return; try { await api('/api/my/audiences', { name: v.name }); toast('Created. Paste its pixel on the site.'); loadAudiences(); } catch (e) { toast(e.message, true); } }); + CR.requireSession(() => { load(); loadAudiences(); }); })(); diff --git a/public/p.js b/public/p.js new file mode 100644 index 0000000..e899915 --- /dev/null +++ b/public/p.js @@ -0,0 +1,13 @@ +/* LinkSpin audience pixel. One line on any page you control: + + Adds the visitor to that audience for 30 days so your LinkSpin campaigns can target (or exclude) them. Optional + data-ev="lead" names the event. It stores a random visitor id cookie on linkspin.app and nothing else. */ +(function () { + var s = document.currentScript; if (!s) return; + var a = s.getAttribute('data-aud') || ''; if (!/^la-[a-f0-9]{6}$/.test(a)) return; + var base = (s.src || '').replace(/\/p\.js.*$/, ''); + var e = s.getAttribute('data-ev') || ''; + var q = 'a=' + encodeURIComponent(a) + (e ? '&e=' + encodeURIComponent(e.slice(0, 24)) : '') + + '&u=' + encodeURIComponent(String(location.href).slice(0, 300)) + '&r=' + encodeURIComponent(String(document.referrer).slice(0, 200)) + '&t=' + Date.now(); + var img = new Image(1, 1); img.alt = ''; img.referrerPolicy = 'strict-origin-when-cross-origin'; img.src = base + '/p.gif?' + q; +})(); diff --git a/public/z.js b/public/z.js index 956d01b..b26fbcc 100644 --- a/public/z.js +++ b/public/z.js @@ -7,7 +7,7 @@ var base = (s.src || '').replace(/\/z\.js.*$/, ''); var box = document.createElement('div'); box.style.cssText = 'display:inline-block;line-height:0;max-width:100%'; s.parentNode.insertBefore(box, s); function load() { - var r = new XMLHttpRequest(); r.open('GET', base + '/api/zone/serve?z=' + encodeURIComponent(zone), true); + var r = new XMLHttpRequest(); r.open('GET', base + '/api/zone/serve?z=' + encodeURIComponent(zone), true); r.withCredentials = true; r.onload = function () { if (r.status !== 200) return; var ad; try { ad = JSON.parse(r.responseText).ad; } catch (e) { return; } if (!ad || (!ad.img && !ad.frame)) return; var el; diff --git a/public/zones.html b/public/zones.html index 494fed4..e9e607c 100644 --- a/public/zones.html +++ b/public/zones.html @@ -25,12 +25,13 @@
ZoneSizeViewsViewableCreditsQuality
+

Audiences

Your own retargeting. Every visitor to your LinkSpin pages and your zones lands in My visitors for 30 days, no setup. For any other site you control, paste an audience pixel. Then, on any banner or text campaign, choose "show only to" or "never show to" an audience.
loading
Counts are visitors seen in the last 30 days. The match uses a LinkSpin cookie, with a 24-hour fallback where a browser blocks cross-site cookies, so Safari and Firefox visitors on other sites match less often. Nothing personal is stored.

What runs here

Three tiers, in order: a LinkSpin member campaign (the same pool the ad viewer serves), then a Network Ad Space ad for 728x90 and 468x60 zones, then a LinkSpin house banner. Your site carries the whole network, not just LinkSpin.
- + diff --git a/server.js b/server.js index afb953b..e069a58 100644 --- a/server.js +++ b/server.js @@ -42,7 +42,8 @@ const rotator = require('./rotator'); const postbacks = require('./postbacks'); // outbound + inbound conversion postbacks on rotator clicks (2026-09-29) const pages = require('./pages'); // member pages: bridge / review / squeeze, served at /p/ (2026-09-29) const zones = require('./zones'); // ad zones on members' own sites (2026-09-29) -const nas = require('./nas'); // only asked whether syndication is on (the status strip) +const nas = require('./nas'); +const audiences = require('./audiences'); // first-party retargeting (2026-10-08) // only asked whether syndication is on (the status strip) const MEMBER_AD_TYPES = ['banner', 'text', 'login']; // the formats LinkSpin members can buy (video, visits, featured, solo stay off) // the rotator: rotations, weighted destinations, /r/ const snapshot = require('./snapshot'); // daily growth snapshot -> Telegram payments feed (Marty, 2026-09-15) const pipeline = require('./pipeline'); // sponsor follow-up board (coming soon until site setting pipelineMode = on) (Marty, 2026-09-15) @@ -202,6 +203,9 @@ const codeGlobal = { minute: 0, n: 0 }; const codeAlert = { last: 0, trips: 0, ips: new Set() }; function clientIp(req) { return String(req.headers['x-forwarded-for'] || req.socket.remoteAddress || '').split(',')[0].trim() || 'unknown'; } // the viewer's country and tier for ad targeting (null tier = unknown: never matches a restricted campaign) +// CORS for the zone tag: echo the calling origin and allow credentials, so the browser may send the ls.vid cookie +function corsCreds(req) { const o = String(req.headers.origin || ''); return o ? { 'Access-Control-Allow-Origin': o, 'Access-Control-Allow-Credentials': 'true', 'Vary': 'Origin' } : { 'Access-Control-Allow-Origin': '*' }; } +const PIXEL_GIF = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64'); function viewerGeo(req) { const cc = geo.countryOf(clientIp(req)); return { cc, tier: geo.tierOf(cc, siteConfig()) }; } function codeChallenge(rec) { const pick = CAPTCHA.slice().sort(() => Math.random() - 0.5).slice(0, 5); @@ -407,6 +411,7 @@ async function boot() { postbacks.init({ dataDir: DATA_DIR, ownHosts, rotator }); zones.init({ dataDir: DATA_DIR, ads, siteHost: SITE_HOST }); pages.init({ dataDir: DATA_DIR, ownHosts, 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 }); snapshot.init({ dataDir: DATA_DIR, db, chain, siteConfig, send: async (c, t, th) => { await telegramSend(c, t, th); return true; } }); setInterval(() => snapshot.tick().catch(e => console.error('snapshot', e.message)), 10 * 60 * 1000); tank.init({ dataDir: DATA_DIR, chain, accounts, messages, mailer, site: SITE_URL }); @@ -888,7 +893,7 @@ const server = http.createServer(async (req, res) => { const u = new URL(req.url, 'http://x'); const p = u.pathname; // zone endpoints run on other people's sites and show only ad creatives, so they pass the curtain - const zonePath = p === '/z.js' || p === '/z/nas' || p.startsWith('/api/zone/') || p.startsWith('/banners/linkspin-') || p.startsWith('/art/house-'); + const zonePath = p === '/z.js' || p === '/z/nas' || p === '/p.js' || p === '/p.gif' || p.startsWith('/api/zone/') || p.startsWith('/banners/linkspin-') || p.startsWith('/art/house-'); if (!zonePath && curtained(req, res, u)) return; // nothing below this line runs for an uninvited visitor // -- the rotator redirect: one hop, recorded, on any host (LinkSpin) @@ -901,15 +906,26 @@ const server = http.createServer(async (req, res) => { // -- ad zones on members' sites: the tag, the ad, the viewable beacon, the click. Any origin may call these. if (p === '/z.js') { const zf = path.join(PUBLIC_DIR, 'z.js'); try { const body = fs.readFileSync(zf); res.writeHead(200, { 'Content-Type': 'application/javascript; charset=utf-8', 'Cache-Control': 'public, max-age=300', 'Access-Control-Allow-Origin': '*' }); return res.end(body); } catch (e) {} } if (p === '/api/zone/serve' && req.method === 'GET') { - const ad = await zones.serve(u.searchParams.get('z'), req, viewerGeo(req)); - res.writeHead(200, { 'Content-Type': 'application/json', 'Cache-Control': 'no-store', 'Access-Control-Allow-Origin': '*' }); return res.end(JSON.stringify({ ad })); + const am = audiences.matcher(req); // ls.vid cookie (when the browser sends it cross-site) + soft key + const ad = await zones.serve(u.searchParams.get('z'), req, Object.assign(viewerGeo(req), am)); + const h = Object.assign({ 'Content-Type': 'application/json', 'Cache-Control': 'no-store' }, corsCreds(req)); + if (!am.vid) h['Set-Cookie'] = audiences.cookieHeader(audiences.newVid(), IS_PROD); + res.writeHead(200, h); return res.end(JSON.stringify({ ad })); } + // audience pixel: 1x1 gif, sets/refreshes the visitor cookie, records the hit (30-day membership) + if (p === '/p.gif' && req.method === 'GET') { + const a = String(u.searchParams.get('a') || ''); let vid = audiences.cookieVid(req); const h = { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store, private', 'Content-Length': String(PIXEL_GIF.length) }; + if (!vid) { vid = audiences.newVid(); h['Set-Cookie'] = audiences.cookieHeader(vid, IS_PROD); } + if (audiences.isId(a)) audiences.hit(a, vid, audiences.softKey(req)); + res.writeHead(200, h); return res.end(PIXEL_GIF); + } + if (p === '/p.js') { try { const body = fs.readFileSync(path.join(PUBLIC_DIR, 'p.js')); res.writeHead(200, { 'Content-Type': 'application/javascript; charset=utf-8', 'Cache-Control': 'public, max-age=300' }); return res.end(body); } catch (e) { res.writeHead(404); return res.end(); } } if (p === '/z/nas' && req.method === 'GET') { // the frame a Network Ad Space fallback renders in const html = zones.nasFrame(String(u.searchParams.get('s') || '')); if (!html) { res.writeHead(404); return res.end(); } res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store', 'Content-Security-Policy': "default-src 'none'; script-src https://www.networkadspace.com https://networkadspace.com 'unsafe-inline'; img-src https: http: data:; style-src 'unsafe-inline'; frame-src https: http:; frame-ancestors *; base-uri 'none'", 'Referrer-Policy': 'no-referrer' }); return res.end(html); } - if (p === '/api/zone/seen' && (req.method === 'GET' || req.method === 'POST')) { await zones.seen(u.searchParams.get('i'), req); res.writeHead(204, { 'Access-Control-Allow-Origin': '*' }); return res.end(); } + if (p === '/api/zone/seen' && (req.method === 'GET' || req.method === 'POST')) { await zones.seen(u.searchParams.get('i'), req); res.writeHead(204, corsCreds(req)); return res.end(); } { const zm = /^\/api\/zone\/click\/([a-f0-9]{12})$/.exec(p); if (zm && req.method === 'GET') { const target = await zones.click(zm[1]); res.writeHead(302, { Location: target || '/', 'Cache-Control': 'no-store', 'Referrer-Policy': 'no-referrer-when-downgrade' }); return res.end(); } } { const wm = /^\/welcome\/([a-f0-9]{48})$/.exec(p); if (wm && (req.method === 'GET' || req.method === 'POST')) { // one-time tester sign-in link const t = inviteTokens.get(wm[1]); @@ -936,7 +952,7 @@ const server = http.createServer(async (req, res) => { const hdr = { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store', 'X-Content-Type-Options': 'nosniff', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'Content-Security-Policy': "default-src 'none'; script-src 'self'; style-src 'unsafe-inline'; img-src https: data:; form-action https: http:; base-uri 'none'; frame-ancestors *; connect-src 'self'" }; if (/^[a-z0-9]{6,20}$/i.test(lsid)) hdr['Set-Cookie'] = 'ls.click=' + lsid + '; Path=/; SameSite=Lax; Max-Age=2592000' + (IS_PROD ? '; Secure' : ''); - res.writeHead(200, hdr); return res.end(pages.html(pg, { leadUrl: '/p/' + pg.slug + '/lead', trackSrc: '/assets/pt.js', footerLink: 'https://' + SITE_HOST + '/', footerText: 'Made with LinkSpin' })); + res.writeHead(200, hdr); return res.end(pages.html(pg, { leadUrl: '/p/' + pg.slug + '/lead', trackSrc: '/assets/pt.js', footerLink: 'https://' + SITE_HOST + '/', footerText: 'Made with LinkSpin', pixel: 'https://' + SITE_HOST + '/p.gif?a=' + audiences.defaultFor(pg.owner) + '&e=page' })); } pm = /^\/p\/([a-z0-9-]{3,60})\/lead$/i.exec(p); if (pm && req.method === 'POST') { @@ -2103,7 +2119,7 @@ const server = http.createServer(async (req, res) => { if (status.views >= status.target || status.claimed) return json(res, 200, { ad: null, status }); const type = String(u.searchParams.get('type') || 'banner'); // members never see (or earn from) their own campaigns in the viewer - const ad = await ads.serve(type === 'text' ? 'text' : 'banner', Object.assign({ excludeEmail: s.email }, viewerGeo(req))); + const ad = await ads.serve(type === 'text' ? 'text' : 'banner', Object.assign({ excludeEmail: s.email }, viewerGeo(req), audiences.matcher(req))); if (!ad) return json(res, 200, { ad: null, status }); const token = crypto.randomBytes(16).toString('hex'); // the viewer tab frames the advertiser's REAL url (no click counted for a paid view) @@ -2710,7 +2726,7 @@ const server = http.createServer(async (req, res) => { // -- ad engine (spec §8b v1: banners, text, login ads) if (p === '/api/ads/slot' && req.method === 'GET') { const t = String(u.searchParams.get('type') || 'banner'); - const ad = await ads.serve(t, Object.assign({ width: Number(u.searchParams.get('w')) || 0, height: Number(u.searchParams.get('h')) || 0 }, viewerGeo(req))); + const ad = await ads.serve(t, Object.assign({ width: Number(u.searchParams.get('w')) || 0, height: Number(u.searchParams.get('h')) || 0 }, viewerGeo(req), audiences.matcher(req))); // login ads: the member clicks "Open Ad" (a real, counted click into a // new tab) while the countdown runs on our interstitial page if (ad && t === 'login') ad.dwell = ads.rates().loginDwellSeconds || 10; @@ -2724,6 +2740,16 @@ const server = http.createServer(async (req, res) => { res.writeHead(302, baseHeaders({ Location: target })); return res.end(); } + if (p === '/api/my/audiences' && 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, { audiences: audiences.list(s.email), host: SITE_HOST }); + } + if (p === '/api/my/audiences' && req.method === 'POST') { + const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' }); + const b = await readBody(req); + const r = b.remove ? audiences.remove(s.email, b.id) : b.id ? audiences.rename(s.email, b.id, b.name) : audiences.create(s.email, b.name); + return json(res, r.error ? 400 : 200, r); + } if (p === '/api/my/campaigns' && req.method === 'GET') { const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' }); @@ -2731,7 +2757,7 @@ const server = http.createServer(async (req, res) => { // welcome credits used to unlock only through the classic dashboard; the Control Room Ads screen grants them the same way (2026-09-29) let gauntletPending = false; if (!(await ads.welcomeGranted(s.email))) { const tour = (await uplineSlides(s.email)).filter(a => a.lineTargetUrl); if (!tour.length) await ads.grantWelcome(s.email); else gauntletPending = true; } - const out = { campaigns: await ads.listCampaigns(s.email), rates: ads.rates(), bannerSizes: ads.bannerSizes(), gauntletPending }; + const out = { campaigns: await ads.listCampaigns(s.email), rates: ads.rates(), bannerSizes: ads.bannerSizes(), gauntletPending, audiences: audiences.list(s.email) }; out.clickSources = await coach.clickSources(out.campaigns.map(c => c.id)); out.hours = await ads.hoursFor(out.campaigns.map(c => c.id)); // on-site views per UTC hour, last 7 days out.geo = await ads.geoFor(out.campaigns.map(c => c.id)); // on-site serves per viewer country @@ -2752,7 +2778,8 @@ const server = http.createServer(async (req, res) => { if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' }); const memberId = await auth.refreshMemberId(s); // 0 is fine: earned credits fund banner/text const b = await readBody(req); - if (!MEMBER_AD_TYPES.includes(String(b.type || ''))) return json(res, 400, { error: 'LinkSpin runs banner, text and login ads.' }); // Marty 2026-09-29: the three formats members buy + if (!MEMBER_AD_TYPES.includes(String(b.type || ''))) return json(res, 400, { error: 'LinkSpin runs banner, text and login ads.' }); + if (b.audience && !audiences.owns(s.email, b.audience)) return json(res, 400, { error: 'That audience is not one of yours.' }); // Marty 2026-09-29: the three formats members buy if (!['login', 'solo', 'video', 'featured'].includes(String(b.type || ''))) { // banner/text surf views frame the target; login/video/solo/featured open in a new tab or play in our own player const fc = await frameCheck(b.targetUrl); if (!fc.ok) return json(res, 400, { error: fc.reason }); diff --git a/zones.js b/zones.js index 3d4b992..9f45df1 100644 --- a/zones.js +++ b/zones.js @@ -7,6 +7,7 @@ const fs = require('fs'); const path = require('path'); const crypto = require('crypto'); +const audiences = require('./audiences'); let DATA_DIR = null, ads = null, siteHost = 'linkspin.app'; const SIZES = { '728x90': [728, 90], '468x60': [468, 60], '300x250': [300, 250], '336x280': [336, 280], '250x250': [250, 250], '125x125': [125, 125], '160x600': [160, 600], '120x600': [120, 600], '320x50': [320, 50] }; // + 336x280 / 250x250 / 125x125 / 120x600 (Marty 2026-10-07) // neutral file names on purpose: EasyList blocks any URL with an IAB size token like '-728x90.' (Marty's own blocker hid @@ -72,6 +73,8 @@ async function serve(zoneId, req, geoOpts) { // origin lock: paid inventory (campaigns, network ads) only on the declared site; anywhere else, or with no referrer, // the tag shows the house banner and nothing is earned. An admin pause does the same. const off = !onDeclaredSite(z, siteHostOf(req)); const paidOk = !vis.bot && !off && !z.adminPaused; + // retargeting: a real view on the declared site puts the visitor in the zone owner's automatic audience (30 days) + if (!off && !vis.bot && geoOpts && (geoOpts.vid || geoOpts.soft)) { try { audiences.hit(audiences.defaultFor(z.owner), geoOpts.vid, geoOpts.soft); } catch (e) {} } // waterfall: 1) a LinkSpin member campaign 2) a Network Ad Space ad (NAS serves 728x90 and 468x60) 3) the LinkSpin house banner let ad = null; if (paidOk) { try { ad = await ads.serve('banner', Object.assign({ width: w, height: h, excludeEmail: z.owner }, geoOpts || {})); } catch (e) { ad = null; } } const nas = !ad && paidOk && s.nasOn && NAS_SIZES.has(z.size);