Member welcome offer from the games: starter.js (+100 purchased-grade credits on a first $5+ package after a game visit within 14 days, once per account; setting starterBonusCredits), /api/starter + /api/starter/public, /my?from=<game>#buy banner with the way back to the game perk, Members get <perk> on game cards, admin Traffic 'Games to members' table
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+3
-2
@@ -289,7 +289,8 @@
|
||||
</div>
|
||||
|
||||
<div class="pane" id="pane-traffic" hidden>
|
||||
<div class="card">
|
||||
<div class="card"><div class="card-head"><h3>Games to members</h3><span class="sub" id="stSub">the $5 welcome offer after a game win</span></div><div class="tablewrap"><table class="adm-table" id="trfStarter"></table></div></div>
|
||||
<div class="card">
|
||||
<div class="card-head"><h3>Where visitors come from</h3><span class="sub" id="trfSub"></span></div>
|
||||
<div class="chips" id="trfRange" style="margin:0 0 10px"><button type="button" class="chip-t" data-days="7">7 days</button><button type="button" class="chip-t on" data-days="30">30 days</button><button type="button" class="chip-t" data-days="90">90 days</button><button type="button" class="chip-t" data-days="365">Year</button></div>
|
||||
<p class="muted small" style="margin:0 0 10px">Page views are public-page loads by referring domain (crawlers skipped; our own pages and no referrer count as direct). Join-page views are invite-link opens. Signups, registered and $20+ buyers are accounts whose first-touch source was that domain; legacy arrivals show as legacy:brand:domain.</p>
|
||||
@@ -520,6 +521,6 @@
|
||||
</div>
|
||||
|
||||
<script src="/assets/common.js?v=20261003fr2"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/admin.js?v=20261004tax"></script>
|
||||
<script src="/assets/admin.js?v=20261005st"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1050
-1046
File diff suppressed because it is too large
Load Diff
+3224
-3205
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1131,7 +1131,7 @@
|
||||
<script src="/assets/common.js?v=20261003fr2"></script><script src="/assets/welcome.js?v=20260923b"></script>
|
||||
<script src="/assets/wallet.js?v=20260911a"></script>
|
||||
<script src="/assets/promo.js?v=20261002ref"></script>
|
||||
<script src="/assets/my.js?v=20261004soon2"></script>
|
||||
<script src="/assets/my.js?v=20261005st"></script>
|
||||
<script src="/assets/chat.js?v=20260907l"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -45,6 +45,7 @@ const leaderboard = require('./leaderboard');
|
||||
const toolkit = require('./toolkit');
|
||||
const badge = require('./badge'); // achievement badge image drawn on the server with ffmpeg (2026-09-16)
|
||||
const friday = require('./friday');
|
||||
const starter = require('./starter'); // member welcome offer from the games (2026-10-05)
|
||||
const wednesday = require('./wednesday'); // Wired Wednesday: +25% on $10+ packs, wired into a visits campaign (2026-09-29)
|
||||
const fridaybank = require('./fridaybank'); // Friday Bonus Hunts: days banked Sat-Thu by solo + video (2026-09-26)
|
||||
const refill = require('./refill');
|
||||
@@ -477,6 +478,7 @@ async function boot() {
|
||||
emailOnEvent(ev).catch(() => {});
|
||||
telegramOnEvent(ev).catch(() => {});
|
||||
friday.onEvent(ev).catch(e => console.error('friday bonus', e.message));
|
||||
starter.onEvent(ev).catch(e => console.error('starter bonus', e.message));
|
||||
wednesday.onEvent(ev).catch(e => console.error('wednesday bonus', e.message));
|
||||
sponsorSyncOnEvent(ev).catch(e => console.error('sponsor sync', e.message));
|
||||
}).catch(e => console.error('marks claim', e.message));
|
||||
@@ -500,6 +502,7 @@ async function boot() {
|
||||
send: async (c, t, th) => { await telegramSend(c, t, th); return true; },
|
||||
sendPhoto: (c, jpeg, cap, th) => telegramSendPhoto(c, jpeg, cap, th) });
|
||||
fridaybank.init({ db });
|
||||
starter.init({ dataDir: DATA_DIR, siteConfig, chain, ads, accounts });
|
||||
friday.init({ dataDir: DATA_DIR, siteConfig, chain, ads, accounts, mailer, drip, marks,
|
||||
telegram: async text => { const sc = siteConfig(); if (!sc.telegramBotToken || !sc.telegramEchoChatId) return false; return telegramSend(sc.telegramEchoChatId, '\u{1F7E0} <b>InstantAdPay</b> \u00b7 ' + text, sc.telegramEchoTopicId); },
|
||||
notify: async (memberId, subject, text, kind) => { const a = await accounts.byMemberId(memberId); if (!a || !a.email) return; const html = '<p>' + String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/(https:\/\/[^\s]+)/g, '<a href="$1" target="_blank" rel="noopener">$1</a>').split('\n\n').join('</p><p>').replace(/\n/g, '<br>') + '</p>'; await messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [a.email], subject, html, kind || 'notice'); } });
|
||||
@@ -1419,7 +1422,7 @@ function seasonState(season, day, admin) {
|
||||
}
|
||||
// -- the games registry (2026-10-01). Add a game here; launch it by adding its slug to site config gamesLive.
|
||||
function GAMES() {
|
||||
return [
|
||||
return withPerks([
|
||||
{ slug: 'spookydoors', name: 'Spooky Doors', tag: 'Halloween \u00b7 Oct 4 to 31', blurb: 'Trick or treat! Walk the street, knock on doors and fill your candy bucket. Every door is a short visit to a member\u2019s page or ad, and candy climbs a ladder with POL at set levels. Gone after Halloween night.',
|
||||
art: SD_URL() + '/og-spookydoors.jpg', play: '/api/my/spookydoors', pays: 'POL at set candy levels', season: { start: SD_SEASON.start, end: SD_SEASON.end }, progress: sdProgress },
|
||||
{ slug: 'driprunner', name: 'Drip Runner', tag: 'Arcade runner', blurb: 'Hop the network, dodge the bots, clear chapters. Each first clear drips POL into your game balance, and a refuel on a member\u2019s page keeps your run alive.',
|
||||
@@ -1434,8 +1437,10 @@ function GAMES() {
|
||||
// the card with its date and no Play button until `soon.opens` (Central); from then it is an ordinary card, live via gamesLive
|
||||
{ slug: 'spellwheel', name: 'SpellWheel', tag: 'Word game', blurb: 'Swipe the letter wheel to fill the crossword, travel through six cozy places, and solve a new daily puzzle with everyone. Clear levels and chapters to earn POL.',
|
||||
art: '/assets/games/spellwheel-soon.jpg?v=1', play: '/api/my/spellwheel', pays: 'POL for levels, chapters and daily puzzles', soon: { opens: '2026-10-10', label: 'Opens Saturday, Oct 10' } },
|
||||
];
|
||||
]);
|
||||
}
|
||||
// each game's member perk (the $5 welcome offer, 2026-10-05) shown on its card
|
||||
const withPerks = list => { const st = starter.cfg(); return list.map(g => starter.GAMES[g.slug] && st.on ? Object.assign({}, g, { perk: starter.GAMES[g.slug].perk }) : g); };
|
||||
// -- cross-promo strip (2026-10-03): one short line per game and where a signed-out player lands (the game's own page)
|
||||
const STRIP = () => ({
|
||||
spookydoors: { line: 'Halloween only. Run the graveyard, knock on doors, climb the candy ladder to POL.', open: SD_URL() + '/play', host: SD_URL().replace(/^https?:\/\//, '') },
|
||||
@@ -1650,6 +1655,14 @@ const server = http.createServer(async (req, res) => {
|
||||
|
||||
// -- public API
|
||||
if (p === '/api/friday' && req.method === 'GET') return json(res, 200, friday.view(), { 'Cache-Control': 'public, max-age=60' });
|
||||
// member welcome offer from the games: public numbers for the game cards, the member's own view, and the 'came from' mark
|
||||
if (p === '/api/starter/public' && req.method === 'GET') return json(res, 200, starter.publicView(), { 'Cache-Control': 'public, max-age=300', 'Access-Control-Allow-Origin': '*' });
|
||||
if (p === '/api/starter' && (req.method === 'GET' || req.method === 'POST')) {
|
||||
const s = await auth.fromRequest(req); if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
|
||||
if (req.method === 'POST') { const b = await readBody(req); starter.setFrom(s.email, String(b.game || '')); }
|
||||
const acct = await accounts.byEmail(s.email);
|
||||
return json(res, 200, await starter.view(s.email, Number((acct && acct.memberId) || s.memberId || 0)));
|
||||
}
|
||||
if (p === '/api/wednesday' && req.method === 'GET') return json(res, 200, wednesday.view(), { 'Cache-Control': 'public, max-age=60' });
|
||||
if (p === '/api/admin/pdsync' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, pdsync.status()); }
|
||||
if (p === '/api/admin/pdsync/run' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, await pdsync.sync()); }
|
||||
@@ -2628,7 +2641,7 @@ const server = http.createServer(async (req, res) => {
|
||||
const k = a.joinedVia || 'plain'; angles[k] = angles[k] || { angle: k, views: 0, signups: 0 }; angles[k].signups += 1;
|
||||
}
|
||||
const sources = Object.values(hosts).sort((x, y) => (y.hits + y.joinViews + y.signups * 10) - (x.hits + x.joinViews + x.signups * 10));
|
||||
return json(res, 200, { days, sources, paths: Object.entries(paths).map(([path, hits]) => ({ path, hits })).sort((x, y) => y.hits - x.hits),
|
||||
return json(res, 200, { starter: starter.adminView(), days, sources, paths: Object.entries(paths).map(([path, hits]) => ({ path, hits })).sort((x, y) => y.hits - x.hits),
|
||||
angles: Object.values(angles).sort((x, y) => y.views - x.views), daily: Object.values(daily).sort((x, y) => x.day < y.day ? -1 : 1),
|
||||
totals: { hits: sources.reduce((n, s) => n + s.hits, 0), joinViews: sources.reduce((n, s) => n + s.joinViews, 0), signups: sources.reduce((n, s) => n + s.signups, 0), buyers: sources.reduce((n, s) => n + s.buyers, 0) } });
|
||||
}
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
// Member welcome offer from the games (Marty, 2026-10-05). After a win in a network game, a signed-in player who is not a
|
||||
// member yet sees one card a day: "Become an InstantAdPay member for $5". The card links to /my?from=<game>#buy; this module
|
||||
// remembers which game sent them, and when that account's FIRST package ($5 or more) lands on chain it grants the welcome
|
||||
// bonus credits (purchased-grade, once per account) and counts the conversion for that game. The game perk itself is handed
|
||||
// out by each game the next time the player signs in there as a member (the sign-in token carries memberId).
|
||||
//
|
||||
// Settings (siteConfig): starterOffer '1'|'0' (on), starterBonusCredits (100), starterWindowDays (14: the game visit must be
|
||||
// this recent). Every number comes from the chain index, never a marketing counter. Games are a marketing cost
|
||||
// (Marty 2026-10-05); this is how we see what each one converts.
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
let X = {}, FILE = null, S = null;
|
||||
const GAMES = {
|
||||
driprunner: { name: 'Drip Runner', perk: 'a free hangar upgrade', back: '/api/my/driprunner' },
|
||||
clutterhunt: { name: 'ClutterHunt', perk: '5 bonus hints', back: '/api/my/clutterhunt' },
|
||||
spellwheel: { name: 'SpellWheel', perk: '5 bonus hints', back: '/api/my/spellwheel' },
|
||||
gemkingdom: { name: 'Gem Kingdom', perk: '50 Crowns', back: '/api/my/gemkingdom' },
|
||||
spookydoors: { name: 'Spooky Doors', perk: 'a lucky caramel apple', back: '/api/my/spookydoors' },
|
||||
polywarriors: { name: 'PolyWarriors', perk: 'a free warrior recruit', back: '/api/my/polywarriors' },
|
||||
};
|
||||
|
||||
function init(opts) { X = opts; FILE = path.join(opts.dataDir, 'starter.json'); S = load(); }
|
||||
function load() { try { return Object.assign({ from: {}, granted: {}, conv: {}, visits: {} }, JSON.parse(fs.readFileSync(FILE, 'utf8'))); } catch (e) { return { from: {}, granted: {}, conv: {}, visits: {} }; } }
|
||||
function save() { try { fs.writeFileSync(FILE + '.tmp', JSON.stringify(S)); fs.renameSync(FILE + '.tmp', FILE); } catch (e) {} }
|
||||
function cfg() {
|
||||
const c = (X.siteConfig && X.siteConfig()) || {};
|
||||
return { on: String(c.starterOffer == null ? '1' : c.starterOffer) === '1', bonus: Math.max(0, Math.round(Number(c.starterBonusCredits == null ? 100 : c.starterBonusCredits) || 0)), windowDays: Math.max(1, Number(c.starterWindowDays) || 14) };
|
||||
}
|
||||
const known = g => Object.prototype.hasOwnProperty.call(GAMES, String(g || ''));
|
||||
|
||||
// a member who has bought before cannot get the welcome bonus; the chain index decides
|
||||
function hasPurchased(memberId) { if (!memberId) return false; try { return X.chain.recentEvents(1e9).some(e => e.type === 'Purchase' && e.buyerId === memberId); } catch (e) { return false; } }
|
||||
|
||||
// the card in a game was tapped and the player reached InstantAdPay (signed in): remember the game
|
||||
function setFrom(email, game) {
|
||||
if (!email || !known(game)) return null; const e = String(email).toLowerCase();
|
||||
S.from[e] = { game, at: Date.now() }; const day = new Date().toLocaleDateString('en-CA', { timeZone: 'America/Chicago' });
|
||||
S.visits[game] = S.visits[game] || {}; S.visits[game][day] = (S.visits[game][day] || 0) + 1; save();
|
||||
return S.from[e];
|
||||
}
|
||||
// what the Buy page shows this member
|
||||
async function view(email, memberId) {
|
||||
const c = cfg(), e = String(email || '').toLowerCase(), f = S.from[e];
|
||||
const fresh = f && Date.now() - f.at < c.windowDays * 86400000 ? f : null, bought = hasPurchased(memberId);
|
||||
const g = fresh ? GAMES[fresh.game] : null;
|
||||
return { on: c.on, bonus: c.bonus, from: fresh ? fresh.game : null, game: g ? g.name : null, perk: g ? g.perk : null, back: g ? g.back : null,
|
||||
eligible: c.on && !!fresh && !bought, granted: !!Object.values(S.granted).find(x => x.email === e) };
|
||||
}
|
||||
// public numbers for the game cards (no account needed)
|
||||
function publicView() { const c = cfg(); return { on: c.on, bonus: c.bonus, games: Object.fromEntries(Object.entries(GAMES).map(([k, v]) => [k, { name: v.name, perk: v.perk }])) }; }
|
||||
|
||||
// a Purchase on chain: the buyer's first package, $5 or more, with a recent game visit -> welcome bonus, once per account
|
||||
async function onEvent(ev) {
|
||||
if (!ev || ev.type !== 'Purchase' || (ev.priceCents || 0) < 500) return null;
|
||||
const c = cfg(); if (!c.on || S.granted[ev.tx]) return null;
|
||||
let earlier = false; try { earlier = X.chain.recentEvents(1e9).some(e => e.type === 'Purchase' && e.buyerId === ev.buyerId && e.tx !== ev.tx && (e.block < ev.block || (e.block === ev.block && e.li < ev.li))); } catch (e) {}
|
||||
if (earlier) return null;
|
||||
const a = await X.accounts.byMemberId(ev.buyerId); if (!a || !a.email) return null;
|
||||
const e = String(a.email).toLowerCase(), f = S.from[e];
|
||||
if (!f || ev.ts - f.at > c.windowDays * 86400000 || ev.ts < f.at - 60000) return null; // the game visit came first, recently
|
||||
if (Object.values(S.granted).some(x => x.email === e)) return null; // once per account
|
||||
const g = GAMES[f.game] || { name: f.game };
|
||||
S.granted[ev.tx] = { email: e, memberId: ev.buyerId, game: f.game, bonus: c.bonus, cents: ev.priceCents, at: Date.now() };
|
||||
S.conv[f.game] = S.conv[f.game] || { buyers: 0, cents: 0 }; S.conv[f.game].buyers++; S.conv[f.game].cents += ev.priceCents; save();
|
||||
if (c.bonus > 0) await X.ads.addEarned(e, c.bonus, { purchased: true, log: { kind: 'bonus', note: 'Member welcome bonus: +' + c.bonus + ' credits (you came from ' + g.name + ')', ref: 'starter:' + String(ev.tx).slice(0, 30) } });
|
||||
return S.granted[ev.tx];
|
||||
}
|
||||
// admin: what each game converted (card taps that reached InstantAdPay, first packages, dollars)
|
||||
function adminView() {
|
||||
const out = {}; for (const k of Object.keys(GAMES)) { const v = S.visits[k] || {}; out[k] = { name: GAMES[k].name, visits: Object.values(v).reduce((n, x) => n + x, 0), buyers: (S.conv[k] || {}).buyers || 0, usd: ((S.conv[k] || {}).cents || 0) / 100 }; }
|
||||
return { settings: cfg(), games: out, granted: Object.values(S.granted).length };
|
||||
}
|
||||
|
||||
module.exports = { init, GAMES, setFrom, view, publicView, onEvent, adminView, cfg };
|
||||
Reference in New Issue
Block a user