Invite friends card in the lobby + ?ref attribution on every entry page

Marty: members could not find their referral link. A signed-in player now sees an
"Invite friends" card right under Play: their /r/<username> link (previews with their
own card), Copy (clipboard API, select+copy fallback, prompt last) with a Copied!
confirmation, and Share where the phone has a share sheet. Link stats and the how-it-works
line moved into the card. No username yet: the card says how to get one.

Attribution: ?ref=<name> on /, /play and /signin (and ?r= on the landing, where framed
/r/<name> lands) now sets the same dr.ref sponsor cookie as /r/<name>, last touch wins.
/r/<name> for a name the game does not know keeps it as /?ref=<name> instead of
dropping it. signin.js also reads ?ref straight from the URL. Tests cover each path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-05 07:25:22 -05:00
parent 09692de8c6
commit 11d6f46950
6 changed files with 71 additions and 11 deletions
+26 -2
View File
@@ -88,6 +88,17 @@ canvas#game{position:absolute;inset:0;width:100%;height:100%;display:block;touch
.tip{margin:12px 0 0;padding:10px 12px;border-radius:10px;background:rgba(34,211,238,.07);border:1px solid rgba(34,211,238,.25);font-size:12px;line-height:1.45;color:var(--ink2);text-align:left}.tip b{display:block;font:700 9px var(--body);letter-spacing:.16em;text-transform:uppercase;color:var(--cyan);margin-bottom:3px}
.shrHow{margin:6px 0 8px;font-size:11px;line-height:1.45;color:var(--ink2)}.shrHow a{color:inherit}
.shr{margin-top:10px;padding:10px 12px;border-radius:10px;border:1px solid var(--line);background:rgba(14,23,45,.6);font-size:11px;color:var(--muted);text-align:center}.shr b{color:var(--gold)}.shr .btn{margin-top:8px}
/* invite friends card (2026-10-05) */
.inv{margin-top:14px;padding:14px 14px 12px;border-radius:14px;border:1px solid rgba(34,211,238,.5);background:linear-gradient(180deg,rgba(14,40,58,.92),rgba(14,23,45,.96));box-shadow:0 0 34px -14px rgba(34,211,238,.6);text-align:left}
.inv .eyebrow{font:800 13px var(--display);letter-spacing:.14em;text-transform:uppercase;color:var(--cyan2)}
.invLead{margin:6px 0 10px;font-size:13px;line-height:1.45;color:var(--ink)}
.invLbl{display:block;font:700 9px var(--body);letter-spacing:.16em;text-transform:uppercase;color:var(--muted);margin-bottom:4px}
.invLink{display:block;width:100%;padding:10px 11px;border-radius:10px;border:1px solid var(--line);background:rgba(5,9,18,.75);color:var(--gold2);font:700 13px var(--mono);user-select:all;-webkit-user-select:all}
.invLink:focus{outline:2px solid var(--cyan);outline-offset:1px}
.invBtns{display:flex;gap:10px}.invBtns .btn{flex:1 1 0;min-width:0;font-size:13px;padding:12px 8px}
.invBtns .btn.done{background:linear-gradient(180deg,#A7F3D0,var(--ok) 55%,#059669)}
.invNote{margin:8px 0 0;font-size:11px;line-height:1.45;color:var(--muted)}.invNote a{color:var(--cyan2)}
.invStat{margin-top:10px;padding-top:8px;border-top:1px solid var(--line);font-size:11px;color:var(--muted)}.invStat b{color:var(--gold)}
.toast{position:absolute;left:50%;bottom:calc(70px + env(safe-area-inset-bottom,0px));transform:translateX(-50%);z-index:20;background:var(--panel2);border:1px solid var(--line);color:var(--ink);font-size:12px;padding:8px 12px;border-radius:10px;opacity:0;transition:opacity .2s;pointer-events:none;max-width:92%;text-align:center}
.toast.on{opacity:1}
/* member welcome offer (2026-10-05): an extra card under the chapter-clear result, never during a run, never blocking */
@@ -130,9 +141,22 @@ canvas#game{position:absolute;inset:0;width:100%;height:100%;display:block;touch
<div class="tip" id="lTip" hidden></div>
<button class="btn" id="bPlay" type="button">Play</button>
<div class="row2"><button class="btn ghost" id="bHangar" type="button">Hangar</button><button class="btn ghost" id="bBalance" type="button">Balance</button></div>
<!-- invite friends (2026-10-05, Marty: members could not find their link): a signed-in player's own /r/<username> link, right under Play -->
<section class="inv" id="lShare" hidden aria-labelledby="invTitle">
<div class="eyebrow" id="invTitle">Invite friends</div>
<p class="invLead">Invite friends to Drip Runner. When they join InstantAdPay from your link, you are their sponsor.</p>
<div id="invHas">
<label class="invLbl" for="invLink">Your invite link</label>
<input class="invLink" id="invLink" type="text" readonly value="" aria-label="Your invite link">
<div class="invBtns"><button class="btn" id="bCopy" type="button">Copy link</button><button class="btn ghost" id="bShare" type="button">Share</button></div>
<p class="invNote">It shows your own card when you post it on Telegram, Facebook or X.</p>
<div class="invStat" id="lShareStat"></div>
<p class="shrHow" id="lShareHow"></p>
</div>
<p class="invNote" id="invNone" hidden>Your invite link uses your InstantAdPay username. <a id="invNoneGo" href="https://instantadpay.com/my">Set your username on InstantAdPay</a>, then come back here.</p>
</section>
<a class="btn gold" id="bLevel" href="https://instantadpay.com/my#buy" style="text-decoration:none;text-align:center;font-size:13px;padding:11px">Level up on InstantAdPay</a>
<a class="btn" id="bSignin" href="#" hidden style="text-decoration:none;text-align:center">Sign in to keep progress</a>
<div class="shr" id="lShare" hidden><div id="lShareStat"></div><p class="shrHow" id="lShareHow"></p><button class="btn ghost" id="bShare" type="button">Share your link</button></div>
<div class="member" id="lMember"><i></i>connecting…</div>
<div id="moreGames" class="moreGames" hidden></div>
<div class="member" style="margin-top:6px"><a id="lIap" href="https://instantadpay.com/my" style="color:var(--muted)">InstantAdPay dashboard</a> · <a href="/" style="color:var(--muted)">tester briefing</a></div>
@@ -181,6 +205,6 @@ canvas#game{position:absolute;inset:0;width:100%;height:100%;display:block;touch
<script src="https://instantadpay.com/assets/game-signin.js?v=20261003a" async></script>
<script src="https://instantadpay.com/assets/game-strip.js?v=20261003a"></script>
<script src="/spawn.js"></script>
<script src="/play.js?v=20261005a"></script>
<script src="/play.js?v=20261005b"></script>
</body>
</html>
+20 -3
View File
@@ -71,9 +71,11 @@ function lobby() {
$('lMember').innerHTML = '<i class="' + (ME.wallet ? '' : 'no') + '"></i>InstantAdPay · ' + (ME.username ? '@' + ME.username : '#' + ME.memberId) + ' · ' + (ME.wallet ? ME.wallet.slice(0, 6) + '…' + ME.wallet.slice(-4) : 'no wallet on file');
$('bSignin').hidden = true;
var rf = ME_EXTRA.referrals || {};
$('lShare').hidden = !ME_EXTRA.share;
// the invite card shows for every signed-in player; without a username there is no link yet, so it says how to get one
$('lShare').hidden = false; $('invHas').hidden = !ME_EXTRA.share; $('invNone').hidden = !!ME_EXTRA.share; $('invNoneGo').href = IAP + '/my';
$('invLink').value = ME_EXTRA.share || ''; $('bShare').hidden = !navigator.share;
$('lShareHow').innerHTML = 'Players whose InstantAdPay sponsor is you are your team. Each time one of them refuels, ' + (rf.pct || 10) + '% of what that refuel adds to the pool is credited to your balance, and it is sent to your wallet with your drips at ' + Number((BAL && BAL.threshold) || 0.25).toFixed(2) + ' POL. <a href="/#team" target="_blank" rel="noopener">How it works</a>';
$('lShareStat').innerHTML = 'Your link: <b>' + (rf.clicks || 0) + '</b> visits · <b>' + (rf.count || 0) + '</b> players on your team · <b>' + f3(rf.earned) + '</b> POL earned from their refuels (' + (rf.pct || 0) + '% of each)';
$('lShareStat').innerHTML = 'Your link: <b>' + (rf.clicks || 0) + '</b> visit' + (rf.clicks === 1 ? '' : 's') + ' · <b>' + (rf.count || 0) + '</b> player' + (rf.count === 1 ? '' : 's') + ' on your team · <b>' + f3(rf.earned) + '</b> POL earned from their refuels (' + (rf.pct || 0) + '% of each)';
}
show('ovLobby');
}
@@ -167,7 +169,22 @@ function starterOffer(o) {
$('cOfferNo').addEventListener('click', function () { $('cOffer').hidden = true; });
$('bNext').addEventListener('click', function () { if (!R) return; R.paused = false; R.inv = 1.5; hideAll(); });
$('bShareClear').addEventListener('click', function () { share(this.dataset.text || 'Play Drip Runner with me:'); });
$('bShare').addEventListener('click', function () { share('I am playing Drip Runner, a game that pays in POL. Hop the network, dodge the bots:'); });
$('bShare').addEventListener('click', function () { share('Come play Drip Runner with me. Hop the network, dodge the bots:'); });
// Copy: the clipboard API where the page may use it, else select the field and copy, else a prompt to copy by hand
var copyT = null;
function copied(ok) {
var b = $('bCopy'); clearTimeout(copyT);
if (!ok) { window.prompt('Copy your invite link', ME_EXTRA.share); return; }
b.textContent = 'Copied!'; b.classList.add('done'); toast('Invite link copied. Paste it anywhere.');
copyT = setTimeout(function () { b.textContent = 'Copy link'; b.classList.remove('done'); }, 2200);
}
function copyFallback() { var f = $('invLink'), ok = false; try { f.focus(); f.select(); f.setSelectionRange(0, f.value.length); ok = document.execCommand('copy'); } catch (e) { ok = false; } f.blur(); copied(ok); }
$('bCopy').addEventListener('click', function () {
var url = ME_EXTRA.share; if (!url) return;
if (navigator.clipboard && navigator.clipboard.writeText && window.isSecureContext !== false) navigator.clipboard.writeText(url).then(function () { copied(true); }, copyFallback);
else copyFallback();
});
$('invLink').addEventListener('focus', function () { this.select(); });
$('bRestart').addEventListener('click', function () { endRun().then(newRun); });
function endRun() { var id = R && R.id; R = null; hideAll(); return id ? api('/api/run/end', { runId: id }).catch(function () {}) : Promise.resolve(); }
['bLobby1', 'bLobby2'].forEach(function (id) { $(id).addEventListener('click', function () { endRun().then(loadMe).then(lobby); }); });
+1 -1
View File
@@ -23,6 +23,6 @@ html{background:#050912}
<p class="back"><a href="/play">Keep playing as a guest</a></p>
</main>
<script src="https://instantadpay.com/assets/game-signin.js?v=20261003b"></script>
<script src="/signin.js"></script>
<script src="/signin.js?v=20261005b"></script>
</body>
</html>
+2 -1
View File
@@ -5,5 +5,6 @@
if (!window.IAPSignin) { box.innerHTML = '<p>Sign-in could not load. <a href="https://instantadpay.com/api/my/driprunner" style="color:var(--cyan)">Sign in on InstantAdPay instead</a>.</p>'; return; }
var m = /(?:^|;\s*)dr\.ref=([^;]+)/.exec(document.cookie || ''); // the share link a guest arrived on: their sponsor
var s = /(?:^|;\s*)dr\.src=([^;]+)/.exec(document.cookie || ''); // paid-traffic source, if any (2026-10-03)
IAPSignin.mount(box, { game: 'driprunner', src: s ? decodeURIComponent(s[1]).split('|')[0] : '', ref: m ? decodeURIComponent(m[1]) : '', title: 'Sign in to run', oneTap: IAPSignin.origin + '/api/my/driprunner' });
var q = String(new URLSearchParams(location.search).get('ref') || '').replace(/[^A-Za-z0-9_.-]/g, '').slice(0, 40); // /signin?ref=<name> works even where the cookie was refused (2026-10-05)
IAPSignin.mount(box, { game: 'driprunner', src: s ? decodeURIComponent(s[1]).split('|')[0] : '', ref: q || (m ? decodeURIComponent(m[1]) : ''), title: 'Sign in to run', oneTap: IAPSignin.origin + '/api/my/driprunner' });
})();
+14 -3
View File
@@ -229,8 +229,10 @@ const server = http.createServer(async (req, res) => {
}
{ const mr = /^\/r\/([A-Za-z0-9_.-]{1,40})$/.exec(p); if (mr) {
const sharer = game.byUsername(mr[1]);
if (!sharer) { res.writeHead(302, { Location: '/', 'Cache-Control': 'no-store' }); return res.end(); }
const ck = ['dr.ref=' + encodeURIComponent(sharer.username.toLowerCase()) + '; Path=/; Max-Age=' + 30 * 86400 + '; SameSite=Lax' + (IS_PROD ? '; Secure' : '')];
// not a Drip Runner player (yet), but maybe an InstantAdPay member: the landing keeps the name as ?ref (2026-10-05), and
// InstantAdPay decides whether it is a real sponsor when the visitor signs up
if (!sharer) { res.writeHead(302, { Location: '/?ref=' + encodeURIComponent(mr[1].toLowerCase()), 'Cache-Control': 'no-store' }); return res.end(); }
const ck = [refCookieHeader(sharer.username.toLowerCase())];
if (CURTAIN) ck.push('dr.pass=' + encodeURIComponent(CURTAIN) + '; Path=/; Max-Age=2592000; HttpOnly; SameSite=Lax' + (IS_PROD ? '; Secure' : '')); // a player's link is a pass during the trial
store.update('share-hits', {}, h => { const k = sharer.username.toLowerCase(); h[k] = (h[k] || 0) + 1; return h; });
res.writeHead(302, { Location: '/play', 'Set-Cookie': ck, 'Cache-Control': 'no-store' }); return res.end();
@@ -250,7 +252,13 @@ const server = http.createServer(async (req, res) => {
// ---- static + pages ----
// a paid-traffic landing (?src=adsterra&cid=<click id>): remember it (dr.src) and count the visit (2026-10-03)
let srcHdr = null; if (req.method === 'GET' && ['/', '/index.html', '/play', '/signin'].includes(p)) { const t = srctrack.fromQuery(u); if (t) { srcHdr = { 'Set-Cookie': srctrack.cookieHeader(t, IS_PROD) }; srctrack.bump(t.src, 'visits'); } }
let srcHdr = null; if (req.method === 'GET' && ['/', '/index.html', '/play', '/signin'].includes(p)) {
const ck = []; const t = srctrack.fromQuery(u); if (t) { ck.push(srctrack.cookieHeader(t, IS_PROD)); srctrack.bump(t.src, 'visits'); }
// ?ref=<username> on the landing, the game or sign-in (2026-10-05, the IAP viral-link pattern): the same sponsor cookie as /r/<name>,
// last touch wins. ?r= too on the landing only (the framed /r/<name> lands on /?r=<name>); on /play, r is the refuel receipt.
const rq = queryRef(u, p === '/' || p === '/index.html'); if (rq) ck.push(refCookieHeader(rq));
if (ck.length) srcHdr = { 'Set-Cookie': ck };
}
if (p === '/' || p === '/index.html') { if (curtained(req, res, u)) return; return sendFile(res, path.join(PUBLIC_DIR, 'index.html'), srcHdr); }
if (p === '/testers') { if (curtained(req, res, u)) return; return sendFile(res, path.join(PUBLIC_DIR, 'testers.html')); } // the pre-launch briefing
if (p === '/play') return sendFile(res, path.join(PUBLIC_DIR, 'play.html'), srcHdr);
@@ -335,6 +343,9 @@ const server = http.createServer(async (req, res) => {
if (!res.headersSent) json(res, 500, { error: 'Something broke on our side. Try again.' });
}
});
// the sponsor cookie (read by signin.js and handed to the InstantAdPay sign-in kit as ref; not HttpOnly on purpose)
function refCookieHeader(ref) { return 'dr.ref=' + encodeURIComponent(ref) + '; Path=/; Max-Age=' + 30 * 86400 + '; SameSite=Lax' + (IS_PROD ? '; Secure' : ''); }
function queryRef(u, allowR) { const r = String(u.searchParams.get('ref') || (allowR ? u.searchParams.get('r') : '') || '').trim().replace(/^@/, ''); return /^[A-Za-z0-9_.-]{1,40}$/.test(r) ? r.toLowerCase() : null; }
function refCookie(req) { const m = /(?:^|;\s*)dr\.ref=([^;]+)/.exec(req.headers.cookie || ''); const r = m ? decodeURIComponent(m[1]) : ''; return /^[a-z0-9_.-]{1,40}$/.test(r) ? r : null; }
// where a guest signs in: through the sharer's InstantAdPay join link when they came from one (new people land under the sharer), else the plain hand-off
function signinUrl(req) { return '/signin'; } // in-game sign-in (2026-10-03); the kit carries the dr.ref sponsor itself
+8 -1
View File
@@ -99,7 +99,14 @@ const spawnLib = require('../lib/spawn');
const hit = async (p, opt = {}, ck = '') => { const r = await fetch(B + p, Object.assign({ redirect: 'manual' }, opt, { headers: Object.assign({ Cookie: ck, 'Content-Type': 'application/json' }, opt.headers || {}) })); const set = r.headers.getSetCookie ? r.headers.getSetCookie() : []; let body = null; try { body = await r.json(); } catch (e) {} return { status: r.status, body, set, loc: r.headers.get('location') }; };
const jarAdd = (ck, set) => { const parts = ck ? ck.split('; ') : []; for (const c of set) { const m = /^([^=]+)=([^;]*)/.exec(c); if (!m) continue; const i = parts.findIndex(x => x.startsWith(m[1] + '=')); if (i >= 0) parts.splice(i, 1); if (m[2]) parts.push(m[1] + '=' + m[2]); } return parts.join('; '); };
await admin('/api/admin/settings', { signups: 'open', thresholdPol: 5, refSharePct: 10 });
eq((await hit('/r/nobody')).loc, '/', 'a share link for an unknown player goes to the landing page');
eq((await hit('/r/nobody')).loc, '/?ref=nobody', 'a share link for a name the game does not know goes to the landing page with the name kept as ?ref');
// ?ref=<name> (2026-10-05): the landing, the game and sign-in all set the same sponsor cookie; ?r= only on the landing (on /play it is the refuel receipt)
for (const [path, want] of [['/?ref=Alice', 'alice'], ['/?r=alice', 'alice'], ['/play?ref=alice', 'alice'], ['/signin?ref=@alice', 'alice'], ['/play?r=receipt', null], ['/?ref=bad%20name', null]]) {
const x = await hit(path); const c = x.set.find(s => /^dr\.ref=/.test(s)) || null;
eq([x.status, c ? /^dr\.ref=([^;]*)/.exec(c)[1] : null], [200, want], path + (want ? ' sets dr.ref=' + want : ' sets no sponsor cookie'));
}
{ const x = await hit('/?ref=alice&src=adsterra&cid=c1'); eq([x.set.some(s => /^dr\.ref=alice/.test(s)), x.set.some(s => /^dr\.src=/.test(s))], [true, true], 'a paid-traffic landing with ?ref keeps both cookies'); }
{ const x = await hit('/r/runner42', { headers: { 'Sec-Fetch-Dest': 'iframe' } }); eq(x.loc, '/?r=runner42', 'a framed share link lands on the landing with ?r'); }
const sh = await hit('/r/runner42'); eq([sh.status, sh.loc, sh.set.some(c => /^dr\.ref=runner42/.test(c))], [302, '/play', true], 'a player share link sets the referrer and opens the game');
let g = jarAdd('', sh.set);
const me401 = await hit('/api/me', {}, g); eq([me401.status, me401.body.guestOk, me401.body.signin === '/signin'], [401, true, true], 'a newcomer is offered guest play, sign-in stays in the game (/signin; the kit carries the dr.ref sponsor)');