Viral links: any public page + ?ref=<username|code|id> sets the same last-touch sponsor cookie as /join, counts under a 'page' hook in link stats, then redirects to the clean URL; Promo tools > Viral links builder (pages list + paste any address, copy + share); blog posts show a signed-in member's own link; chatbot answer; QA walk proves redirect + cookie

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-21 05:54:55 -05:00
parent 337d5dd556
commit e2f88dad42
8 changed files with 113 additions and 5 deletions
+33
View File
@@ -198,6 +198,39 @@ window.IAPPromo = (function () {
vw.appendChild(card);
}
}
// viral link builder: any page on the site + ?ref=<you> (same cookie as the invite link)
const vp = $('viralPage');
if (vp && token && vp.dataset.filled !== token) {
vp.dataset.filled = token;
const origin = 'https://instantadpay.com', enc = encodeURIComponent;
const build = raw => {
let s = String(raw || '').trim(); if (!s) return '';
if (!/^https?:\/\//i.test(s)) s = origin + (s.charAt(0) === '/' ? '' : '/') + s;
let x; try { x = new URL(s); } catch (e) { return ''; }
if (!/(^|\.)instantadpay\.com$/i.test(x.hostname) || /^\/(join|from|api|admin)(\/|$)/.test(x.pathname)) return '';
x.searchParams.delete('ref'); x.searchParams.set('ref', token);
return origin + x.pathname + x.search;
};
const render = () => {
const typed = $('viralUrl').value.trim();
const l = build(typed || vp.value);
$('viralLink').textContent = l || (typed ? 'That is not a page on instantadpay.com.' : '…');
const sh = $('viralShare'); sh.innerHTML = '';
if (!l) return;
const title = (!typed && vp.selectedOptions[0]) ? vp.selectedOptions[0].textContent.replace(/^Article: /, '') : 'InstantAdPay';
[linkBtn('https://x.com/intent/tweet?url=' + enc(l) + '&text=' + enc(title), 'X'),
linkBtn('https://www.facebook.com/sharer/sharer.php?u=' + enc(l), 'Facebook'),
linkBtn('https://t.me/share/url?url=' + enc(l) + '&text=' + enc(title), 'Telegram'),
linkBtn('https://wa.me/?text=' + enc(title + ' ' + l), 'WhatsApp'),
linkBtn('https://www.linkedin.com/sharing/share-offsite/?url=' + enc(l), 'LinkedIn'),
linkBtn('mailto:?subject=' + enc(title) + '&body=' + enc(l), 'Email')].forEach(b => sh.appendChild(b));
if (navigator.share) { const b = document.createElement('button'); b.className = 'btn small sec'; b.type = 'button'; b.textContent = 'Share'; b.onclick = async () => { try { await navigator.share({ title, url: l }); } catch (e) {} }; sh.appendChild(b); }
};
fetch('/api/pages').then(r => r.json()).then(r => { vp.innerHTML = (r.pages || []).map(pg => '<option value="' + esc(pg.path) + '">' + esc(pg.title) + '</option>').join(''); render(); }).catch(() => { vp.innerHTML = '<option value="/">Home page</option>'; render(); });
vp.onchange = () => { $('viralUrl').value = ''; render(); };
$('viralUrl').oninput = render;
$('viralCopy').onclick = async () => { const l = $('viralLink').textContent; if (!/^https:/.test(l)) return; try { await navigator.clipboard.writeText(l); status('Link copied.', 'ok'); } catch (e) { status('Copy failed.', 'bad'); } };
}
// objections
const ob = $('promoObjections');
if (ob && ob.dataset.filled !== link) {