First-party retargeting: audiences (automatic 'My visitors' fed by pages + zones, custom pixel audiences via /p.js + /p.gif, ls.vid cookie + 24 h soft key), include/exclude audience targeting on banner/text/login campaigns, zone tag sends credentials with CORS echo, audience-targeted campaigns never syndicate, Audiences panel on Zones and selector on Ads

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-08 16:42:02 -05:00
parent b379f4adda
commit 92c5b777da
11 changed files with 180 additions and 16 deletions
+3 -1
View File
@@ -33,6 +33,8 @@
<label class="lbl">Budget, credits<input class="field mono" id="fBudget" type="number" min="10" step="1" value="50"></label>
<label class="lbl">Daily cap, credits (optional)<input class="field mono" id="fCap" type="number" min="10" step="1" placeholder="none"></label>
<label class="lbl">Show to<select class="field" id="fGeo"><option value="">Everyone</option><option value="1">Tier 1 countries</option><option value="1,2">Tier 1 and 2</option></select></label>
<label class="lbl">Audience<select class="field" id="fAud"><option value="">Everyone</option></select></label>
<label class="lbl" id="fAudModeRow" hidden>Audience rule<select class="field" id="fAudMode"><option value="include">Show only to them</option><option value="exclude">Never show to them</option></select></label>
</div>
<div style="display:grid;grid-template-columns:minmax(0,2fr) minmax(0,1fr);gap:12px;margin-top:12px" class="tgt">
<label class="lbl">Where the click goes<input class="field mono" id="fTarget" placeholder="https://"></label>
@@ -60,6 +62,6 @@
</div>
</div>
<script src="/assets/cr-shell.js?v=20261008c"></script>
<script src="/assets/ads-screen.js?v=20261008a"></script>
<script src="/assets/ads-screen.js?v=20261008b"></script>
</body>
</html>
+3 -1
View File
@@ -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 = '<option value="">Everyone</option>' + (D.audiences || []).map(a => '<option value="' + a.id + '">' + esc(a.name) + ' (' + fmt(a.size30) + ')</option>').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 ? '<span class="tag">Scheduled</span>' : c.status === 'active' ? '<span class="tag ok">Live</span>' : c.status === 'paused' ? '<span class="tag warn">Paused</span>' : c.status === 'out' ? '<span class="tag warn">Out of credits</span>' : c.status === 'done' ? '<span class="tag">Ended</span>' : '<span class="tag">' + esc(c.status) + '</span>';
const cr = c => c.type === 'banner' ? (c.imageUrl ? '<img class="thumb" src="' + esc(c.imageUrl) + '" alt="">' : '') + '<span class="mono muted" style="font-size:11px">' + c.width + 'x' + c.height + '</span>' : c.type === 'text' ? '<b>' + esc(c.title) + '</b><br><span class="muted" style="font-size:12px">' + esc(c.body || '') + '</span>' : '<span class="muted">full page</span>';
$('rows').innerHTML = cs.length ? cs.map(c => '<div class="rw"><div><b>' + esc(c.name) + '</b> <span class="tag t">' + esc(c.type) + '</span><br><span class="mono muted" style="font-size:11px">#' + c.id + ' · ' + esc(host(c.targetUrl)) + (c.geo ? ' · tiers ' + esc(c.geo) : '') + (c.dailyCap ? ' · cap ' + c.dailyCap + '/day' : '') + '</span></div><div>' + cr(c) + '</div><div><span class="num">' + fmt(c.spent) + '</span><span class="muted"> / ' + fmt(c.budget) + '</span><div class="bar"><i style="width:' + Math.min(100, Math.round(100 * c.spent / Math.max(1, c.budget))) + '%"></i></div></div><span class="r num">' + fmt(c.imps) + (c.impsNas ? '<br><span class="muted" style="font-size:11px">+' + fmt(c.impsNas) + ' network</span>' : '') + '</span><span class="r num">' + fmt(c.clicks) + '</span><span>' + st(c) + '</span><span style="display:flex;gap:6px;justify-content:flex-end;flex-wrap:wrap">'
$('rows').innerHTML = cs.length ? cs.map(c => '<div class="rw"><div><b>' + esc(c.name) + '</b> <span class="tag t">' + esc(c.type) + '</span>' + (c.audience ? ' <span class="tag plain" title="audience">' + esc((((D && D.audiences) || []).find(a => a.id === c.audience) || {}).name || 'audience') + (c.audienceMode === 'exclude' ? ' · excluded' : '') + '</span>' : '') + '<br><span class="mono muted" style="font-size:11px">#' + c.id + ' · ' + esc(host(c.targetUrl)) + (c.geo ? ' · tiers ' + esc(c.geo) : '') + (c.dailyCap ? ' · cap ' + c.dailyCap + '/day' : '') + '</span></div><div>' + cr(c) + '</div><div><span class="num">' + fmt(c.spent) + '</span><span class="muted"> / ' + fmt(c.budget) + '</span><div class="bar"><i style="width:' + Math.min(100, Math.round(100 * c.spent / Math.max(1, c.budget))) + '%"></i></div></div><span class="r num">' + fmt(c.imps) + (c.impsNas ? '<br><span class="muted" style="font-size:11px">+' + fmt(c.impsNas) + ' network</span>' : '') + '</span><span class="r num">' + fmt(c.clicks) + '</span><span>' + st(c) + '</span><span style="display:flex;gap:6px;justify-content:flex-end;flex-wrap:wrap">'
+ (c.status === 'active' ? '<button class="btn sm" type="button" data-pause="' + c.id + '">Pause</button>' : c.status === 'paused' ? '<button class="btn sm" type="button" data-resume="' + c.id + '">Resume</button>' : '')
+ (['active', 'paused', 'out'].includes(c.status) ? '<button class="btn sm" type="button" data-top="' + c.id + '">Top up</button>' : '') + '</span></div>').join('')
: '<div class="rw"><span class="muted">No ads yet. Launch one: a banner, a text ad or the login spot.</span></div>';
@@ -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;
+17 -1
View File
@@ -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 => '<script async src="https://' + HOST + '/p.js" data-aud="' + a.id + '"></script>';
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 => '<div style="padding:8px 0;border-top:1px solid var(--line)"><div style="display:flex;justify-content:space-between;gap:8px;align-items:center"><b>' + esc(a.name) + '</b>'
+ '<span class="mono muted" style="font-size:11px">' + fmt(a.size30) + ' in 30 d · ' + fmt(a.size7) + ' in 7 d' + (a.soft ? ' · ' + fmt(a.soft) + ' without cookie (24 h)' : '') + '</span></div>'
+ (a.auto ? '<div class="muted" style="font-size:11.5px">Automatic: your pages and your zones feed it. You can also paste its pixel elsewhere.</div>' : '')
+ '<div class="code" style="display:block;font-size:10.5px;line-height:1.5;word-break:break-all;margin:6px 0">' + esc(ptag(a)) + '</div>'
+ '<div style="display:flex;gap:6px;flex-wrap:wrap"><button class="btn sm" type="button" data-copy="' + a.id + '">Copy pixel</button>'
+ (a.auto ? '' : '<button class="btn sm ghost" type="button" data-ren="' + a.id + '">Rename</button><button class="btn sm ghost danger" type="button" data-del="' + a.id + '">Remove</button>') + '</div></div>').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(); });
})();
+13
View File
@@ -0,0 +1,13 @@
/* LinkSpin audience pixel. One line on any page you control:
<script async src="https://linkspin.app/p.js" data-aud="la-xxxxxx"></script>
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;
})();
+1 -1
View File
@@ -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;
+2 -1
View File
@@ -25,12 +25,13 @@
<div class="tbl zl"><div class="hd"><span>Zone</span><span>Size</span><span class="r">Views</span><span class="r">Viewable</span><span class="r">Credits</span><span>Quality</span><span></span></div><div id="rows"></div><div class="ft" id="foot"></div></div>
<div style="display:grid;gap:16px;align-content:start">
<div class="panel" id="tagPanel" hidden><h2 id="tagTitle">Embed tag</h2><div class="code" id="tagCode" style="display:block;font-size:11px;line-height:1.6;word-break:break-all"></div><div style="display:flex;gap:8px;flex-wrap:wrap"><button class="btn sm" type="button" id="tagCopy">Copy tag</button><button class="btn sm" type="button" id="tagCheck">Check it is live</button></div><div class="muted" id="tagNote">Paste it where the banner should appear. It sizes itself.</div></div>
<div class="panel" id="audPanel"><h2>Audiences</h2><div class="ink2">Your own retargeting. Every visitor to your LinkSpin pages and your zones lands in <b>My visitors</b> 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.</div><div id="audList" class="ink2">loading</div><div style="display:flex;gap:8px;flex-wrap:wrap"><button class="btn sm" type="button" id="audNew">+ New audience</button></div><div class="muted" style="font-size:11.5px">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.</div></div>
<div class="panel"><h2>What runs here</h2><div class="ink2">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.</div><div class="muted" id="rateNote"></div></div>
</div>
</div>
</div>
</div>
<script src="/assets/cr-shell.js?v=20261008c"></script>
<script src="/assets/zones-screen.js?v=20261008a"></script>
<script src="/assets/zones-screen.js?v=20261008b"></script>
</body>
</html>