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:
+8
-1
@@ -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)');
|
||||
|
||||
Reference in New Issue
Block a user