// LinkSpin Zones screen: list, create, embed tag, live check, quality grade. (function () { const $ = id => document.getElementById(id); const esc = CR.esc, fmt = CR.fmt, api = CR.api, toast = CR.toast, dialog = CR.dialog; let Z = [], SEL = null, HOST = location.host, SIZES = [], RATE = {}; CR.mount({ active: 'zones', title: 'Zones', sub: 'loading', actions: '' }); const ago = t => { if (!t) return 'never'; const d = Date.now() - t; if (d < 3600e3) return Math.max(1, Math.round(d / 60e3)) + ' min ago'; if (d < 86400e3) return Math.round(d / 3600e3) + ' h ago'; return Math.floor(d / 86400e3) + ' d ago'; }; const tag = z => ''; async function load() { let r; try { r = await CR.get('/api/my/zones'); } catch (e) { CR.sub('could not load'); return; } Z = r.zones || []; HOST = r.host || HOST; SIZES = r.sizes || []; RATE = r.rates || {}; RATE.warmup = r.warmup || 100; const t = Z.reduce((a, z) => { a.v += z.views30; a.ok += z.viewable30; a.k += z.clicks30; a.c += z.credits; return a; }, { v: 0, ok: 0, k: 0, c: 0 }); CR.sub(Z.length + ' zone' + (Z.length === 1 ? '' : 's') + ' · ' + fmt(t.v) + ' views in 30 days'); $('tiles').innerHTML = [['Views served, 30 d', fmt(t.v)], ['Viewable', t.v ? Math.round(t.ok / t.v * 100) + '%' : '0%'], ['Clicks out', fmt(t.k)], ['Credits earned', fmt(t.c)]].map(([k, v], i) => '
' + k + '' + v + '
').join(''); $('rateNote').textContent = 'You earn 1 credit per ' + (RATE.viewsPerCredit || 5) + ' viewable views of a LinkSpin campaign and 1 per ' + (RATE.nasViewsPerCredit || 10) + ' viewable views of a network ad (1 per ' + (RATE.nasViewsPerCreditVerified || 8) + ' on a Verified zone), capped at ' + (RATE.capPerVisitorDay || 50) + ' credited views per visitor per zone per day. House banners are not paid. Bots never count. Every zone starts Standard; a reviewed site can be marked Verified by the admin.'; firstRun(); const q = g => '' + [1, 2, 3, 4, 5].map(i => '').join('') + '' + (g || ''); $('rows').innerHTML = Z.length ? Z.map(z => '
' + esc(z.name) + '' + (z.site ? ' · ' + esc(z.site) + '' : '') + (z.tier === 'verified' ? ' Verified' : '') + '
' + z.id + ' · ' + (z.lastSeen ? 'last view ' + ago(z.lastSeen) : 'no views yet') + (z.views30 ? ' · mix: ' + fmt(z.campaign30 || 0) + ' LinkSpin / ' + fmt(z.nas30 || 0) + ' network / ' + fmt(z.house30 || 0) + ' house' : '') + '
' + z.size + '' + fmt(z.views30) + '' + (z.viewablePct == null ? '·' : z.viewablePct + '%') + '' + fmt(z.credits) + '' + (z.grade ? q(z.grade) : 'no data') + ' ' + esc(z.statusLabel || '') + '' + '
').join('') : '
No zones yet. Add one, paste the tag on your site, and the banner is live.
'; $('foot').textContent = 'viewable = at least half the banner on screen for one second, reported by the tag · quality: A 60%+ viewable, B 40%+, C below · paid ads serve only on the declared site; a zone earns after its first 100 on-site views with 40%+ viewable and goes on hold below that'; $('rows').querySelectorAll('[data-tag]').forEach(b => b.addEventListener('click', () => showTag(b.dataset.tag))); $('rows').querySelectorAll('[data-tog]').forEach(b => b.addEventListener('click', async () => { const z = Z.find(x => x.id === b.dataset.tog); try { await api('/api/my/zones/' + z.id, { active: !z.active }); load(); } catch (e) { toast(e.message, true); } })); $('rows').querySelectorAll('[data-del]').forEach(b => b.addEventListener('click', async () => { if (!await dialog({ title: 'Remove this zone?', text: 'The tag on your site stops showing ads. Credits already earned stay.', ok: 'Remove', danger: true })) return; try { await api('/api/my/zones/' + b.dataset.del, { remove: true }); SEL = null; $('tagPanel').hidden = true; load(); } catch (e) { toast(e.message, true); } })); if (SEL && Z.find(z => z.id === SEL)) showTag(SEL); } function showTag(id) { const z = Z.find(x => x.id === id); if (!z) return; SEL = id; $('tagPanel').hidden = false; $('tagTitle').textContent = 'Embed tag · ' + z.name; $('tagCode').textContent = tag(z); $('tagNote').textContent = 'Paste it where the banner should appear (' + z.size + '). It sizes itself and never loads more than one ad. Tip: do not wrap it in an element whose class or id contains "ad", "banner" or "sponsor" (ad blockers hide those), and if you test with an ad blocker on, pause it for your own site first.'; $('tagCopy').onclick = () => { CR.copy(tag(z)); COPIED = true; LS.set('ls.zoneTagCopied', '1'); firstRun(); }; $('tagCheck').onclick = async () => { await load(); const zz = Z.find(x => x.id === id); toast(zz && zz.lastSeen && Date.now() - zz.lastSeen < 3600e3 ? 'Live: last view ' + ago(zz.lastSeen) : 'No view in the last hour. Is the tag on a page people open?', !(zz && zz.lastSeen && Date.now() - zz.lastSeen < 3600e3)); }; } async function addZone() { 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); } } $('newBtn').addEventListener('click', addZone); // ---- first-run card (publisher onboarding, 2026-10-10): site, size, copy the tag, check it is live. Shows while the // account has no zone with a view, or when /zones?start=1 (the /publishers Start button) asks for it; Hide remembers. const START = /[?&]start=1\b/.test(location.search); const LS = { get: k => { try { return localStorage.getItem(k); } catch (e) { return null; } }, set: (k, v) => { try { localStorage.setItem(k, v); } catch (e) {} } }; let COPIED = LS.get('ls.zoneTagCopied') === '1'; function firstRun() { const fr = $('firstRun'); if (!fr) return; const live = Z.some(z => z.lastSeen); const hidden = LS.get('ls.zonesFirstRunHidden') === '1'; if ((hidden || live) && !START) { fr.hidden = true; return; } fr.hidden = false; const step = !Z.length ? 1 : (!COPIED && !live) ? 3 : !live ? 4 : 5; // 1-2 site+size, 3 copy, 4 check, 5 done const steps = [['Your site', 'The domain the tag will live on, exactly as the address bar shows it. Paid ads serve only there.'], ['Size', 'The banner size of the spot. 728x90 and 468x60 also get network ads.'], ['Copy the tag', 'Paste it where the banner should appear: a widget, a template, an HTML block.'], ['Check it is live', 'Open your page once, then press the button. The warm-up counter starts with that first view.']]; $('frSteps').innerHTML = steps.map(([t, d], i) => { const n = i + 1; const done = n < step || (n <= 2 && step > 2) || step === 5; const now = !done && (n === step || (step === 1 && n === 2)); return '
  • ' + (done ? '✓' : n) + '' + t + '' + d + '
  • '; }).join(''); $('frTitle').textContent = step === 5 ? 'Your site is live' : 'Add your site'; $('frIntro').textContent = step === 5 ? 'The tag is serving. The zone earns after its first ' + (RATE.warmup || 100) + ' on-site views with 40% or more viewable; the status column tells you where it stands. Add another spot any time.' : step >= 3 ? 'Zone created. Copy the tag, paste it on ' + esc(Z[0].site) + ', then check it is live.' : 'Four steps and your site is carrying the network. Paid ads serve only on the site you name, and every viewable impression pays you ad credits.'; const go = $('frGo'); go.textContent = step === 1 ? 'Add your site' : step === 3 ? 'Show the tag' : step === 4 ? 'Check it is live' : 'Add another zone'; go.onclick = () => { if (step === 1 || step === 5) return addZone(); showTag(Z[0].id); if (step === 4) $('tagCheck').click(); }; $('frHide').onclick = () => { LS.set('ls.zonesFirstRunHidden', '1'); fr.hidden = true; }; } // ---- 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(); }); })();