Login ad in the games: the sponsor interstitial after a fresh in-game sign-in, counted per surface

- Game sign-in kit (game-signin.js): after a fresh email sign-in (never a remembered
  pass) the kit shows the login ad before the hand-off to /auth?t=, same as the
  dashboard: sponsor card, Open Ad (a counted click through /api/ads/click), sponsor
  framed in a full-screen overlay when frameable else a new tab, 10 s countdown
  (loginDwellSeconds), then Continue to the game. No ad, an error, a non-200 or a
  7 s stall all go straight to the game. A game page whose CSP blocks the frame gets a
  new-tab link instead. mount option loginAd: false switches it off.
- GET /api/game/ads/login?game=<slug>: CORS only for that game's GAME_AUTH origins
  (dev: localhost); the dashboard /api/ads/slot route keeps no CORS. Both share
  loginAdFor() (ads.serve: impression + lastShownDay as before). Drip Runner and
  PolyBreak are marked frames: false (their CSP is default-src 'self'), so their ad
  opens in a new tab; frame checks for games ignore an instantadpay.com-only
  frame-ancestors allowance.
- loginshows.js: every login-ad request tallied per Central day, surface (dashboard or
  game slug) and kind (member slot, house, none); MySQL table login_shows (created on
  first use) or DATA_DIR/login-shows.json. GET /api/admin/login-shows + a Login-ad
  showings card on the admin Traffic pane (dashboard vs games, house, no-ad, by game).
- The kit is served no-cache so games pick it up without a tag bump; admin.js tag bumped.
- Chatbot fact updated (slot rules + games), KNOWLEDGE_DATE 2026-10-18.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-18 06:17:41 -05:00
parent d520eb67af
commit 017017ad63
6 changed files with 211 additions and 24 deletions
+2 -2
View File
@@ -20,7 +20,7 @@ function key() {
function enabled() { return !!key(); }
// ---- canned answers: instant, free, always in voice ----
const KNOWLEDGE_DATE = '2026-10-16'; // bump whenever the canned answers / prompt are brought up to date
const KNOWLEDGE_DATE = '2026-10-18'; // bump whenever the canned answers / prompt are brought up to date
const SUPPORT_RE = /(contact|reach|email|e-mail|message|talk to|speak (to|with)|get hold of) (the )?(support|admin|administrator|owner|marty|staff|team at instantadpay|someone|a (human|person|real person))|support (email|address|ticket|team|desk)|help ?desk|(open|send|file|submit|raise) (a )?(support )?ticket|\b(human|real person|live (agent|person|chat|support))\b|customer (service|support)|support@|how (do|can) i get (help|support)/i;
const CANNED = [
{ re: SUPPORT_RE, handoff: true,
@@ -172,7 +172,7 @@ FACTS:
- CREDIT ACTIVITY LEDGER (2026-09-16): Members > Campaigns has a 'Credit activity' list (last 40 lines, newest first; also linked from the Earn credits pane) showing every real credit movement with a reason: welcome credits, sign-in bonus with streak, daily claim, inbox reads, video watches, verified visits, milestone and leaderboard bonuses, partner codes, admin/team grants, AI Copy Engine charges and refunds, flat buys (featured runs, extensions, visit packs, more visits), login-ad days, and metered delivery rolled up as one line per campaign per day ('Ad views: NAME', 'Inbox deliveries: NAME', 'Video views: NAME'); lines marked '(purchased credits)' spent on-chain purchased credits rather than the earned pool. Reservations (credits set aside for a live campaign) are NOT ledger lines; they show as 'in live campaigns'. Earned credits are spent before purchased ones, so an earn followed by a buy appears as two lines. The ledger starts 2026-09-16; nothing earlier is listed.
- PAYMENT + MISSED-PAYMENT NOTICES (2026-09-15): every payout that lands (who bought, level, share in POL and dollars, transaction link) and every missed payout is delivered BOTH by email and as an on-site inbox message from the company account, shown in the login pop-up and the Messages card, so it is waiting when the member signs in. MISSED-PAYOUT detail: when a level-2 or level-3 share passes a member by because that level is not open on their account, the member gets an email the same minute: who bought, the POL and dollar amount they missed, how many qualifying buyers they have versus the 2 or 5 needed, and the two ways to close the gap (bring buyers, or Qualified Start). Qualified members whose wallet rejected a transfer get a different email telling them to link a regular wallet. MISSED PAYOUTS ARE ALSO PUBLIC (2026-09-16): the team's Telegram payments feed posts, by username, who was passed over on a purchase, why (not qualified yet with N of 2 buyers, or payouts not switched on), the amount, and who received it instead; the same for a sale that routed past an unactivated sponsor. Nothing about the contract changed; it is visibility.
- LAUNCH WEEK SWIPES (2026-09-15): the founding-week checklist page (/launch) ends with four promoter emails members send to their OWN lists, one a day toward Monday's opening, with the member's invite link and the FOUNDER code (500 credits for anyone who joins before Mon 2026-09-21 9 AM Central) filled in, each with a Copy button. These are swipes for members, not emails the site sends.
- LOGIN ADS ARE A SLOT (2026-09-19): 1,000 purchased credits buys 30 days on the sign-in screen, paid up front, never metered. At most 3 member slots run at once because every slot shares the same sign-ins; when all 3 are taken the buy is refused until one ends. House login ads only show when no member slot is running. Featured links count views (one per viewer per hour) as well as clicks.
- LOGIN ADS ARE A SLOT (2026-09-19, updated 2026-10-18): 1,000 purchased credits buys 30 days on the sign-in screen, paid up front, never metered. Purchased credits only: credited purchased credits first, the rest from the position's on-chain package credits; earned (viewing) credits never pay for a login slot. At most 3 member slots run at once because every slot shares the same sign-ins; when all 3 are taken the buy is refused until one ends, and a paused slot can only be resumed while a slot is open. A slot cannot be topped up (it is a flat 30-day buy with unlimited sign-in impressions). Since 2026-10-18 the login ad shows after a fresh sign-in on the dashboard AND after a fresh email sign-in inside the connected games (Drip Runner, Gem Kingdom, ClutterHunt, PolyBreak, SpellWheel, PolyWarriors), before the player continues to the game; a remembered game session does not show it. House login ads only show when no member slot is running. Featured links count views (one per viewer per hour) as well as clicks.
- AD VIEWER OPEN-IN-TAB (2026-09-19): the earn viewer shows the advertiser's page inside a frame; a link in its bar opens the same site in a new tab for sites that refuse to load framed or where signing up is easier in a full tab. The view still credits from the frame's countdown and check.
- (2026-09-14 hold rule REPLACED on 2026-09-16 by the walk-up rule above: a purchase is never held for an unactivated sponsor; only a transient chain read error pauses a buy.)
- NO-PAYOUT POSITIONS (2026-09-14): admin can list member ids (Settings > No-payout positions) whose wallets must never be paid again (e.g. a compromised key). Those positions stay linked for history and counting only: the buy-from picker disables them, a purchase from them is refused, and invite links that would place a new member under them (or under their upline chain) route to the fallback sponsor instead. The contract itself cannot change a member's wallet.
+61
View File
@@ -0,0 +1,61 @@
// Login-ad showings per day per surface (Marty, 2026-10-18). The sign-in interstitial now runs on
// the dashboard AND inside the games' sign-in kit; before raising the 3-slot cap he wants a week of
// combined numbers. One row per Central day, surface ('dashboard' or a game slug) and kind:
// 'member' (a member's slot was shown), 'house' (the house login ad), 'none' (a sign-in with no
// login ad to show). MySQL table login_shows when the DB is on, else DATA_DIR/login-shows.json.
'use strict';
const fs = require('fs');
const path = require('path');
const db = require('./db');
let DATA_DIR = null, J = null, ready = null;
const ctDay = t => new Date(t === undefined ? Date.now() : t).toLocaleDateString('en-CA', { timeZone: 'America/Chicago' });
const FILE = () => path.join(DATA_DIR, 'login-shows.json');
function init(opts) { DATA_DIR = opts.dataDir; }
function ensure() {
if (!ready) ready = db.q(`CREATE TABLE IF NOT EXISTS login_shows (
day VARCHAR(10) NOT NULL, surface VARCHAR(40) NOT NULL, kind VARCHAR(10) NOT NULL, n INT NOT NULL DEFAULT 0,
PRIMARY KEY (day, surface, kind)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`).catch(e => { ready = null; throw e; });
return ready;
}
function load() { if (J) return J; try { J = JSON.parse(fs.readFileSync(FILE(), 'utf8')); } catch (e) { J = {}; } return J; }
// surface: 'dashboard' | game slug; ad: what ads.serve returned (null = nothing to show)
async function record(surface, ad) {
const s = String(surface || 'dashboard').toLowerCase().replace(/[^a-z0-9_-]/g, '').slice(0, 40) || 'dashboard';
const kind = !ad ? 'none' : ad.house ? 'house' : 'member';
const d = ctDay();
try {
if (db.enabled()) {
await ensure();
await db.q('INSERT INTO login_shows (day,surface,kind,n) VALUES (?,?,?,1) ON DUPLICATE KEY UPDATE n=n+1', [d, s, kind]);
} else {
const k = d + '|' + s + '|' + kind, st = load();
st[k] = (st[k] || 0) + 1;
fs.writeFileSync(FILE(), JSON.stringify(st));
}
} catch (e) { console.error('login shows', e.message); }
}
// last `days` Central days, newest first: { day, dashboard: {member,house,none}, games: {member,house,none}, byGame: {slug: shown} }
async function report(days) {
days = Math.max(1, Math.min(90, Number(days) || 14));
const since = ctDay(Date.now() - (days - 1) * 86400000);
let rows = [];
if (db.enabled()) {
await ensure();
rows = (await db.q('SELECT day, surface, kind, n FROM login_shows WHERE day>=?', [since])).map(r => ({ day: String(r.day), surface: r.surface, kind: r.kind, n: Number(r.n) }));
} else {
for (const [k, n] of Object.entries(load())) { const [day, surface, kind] = k.split('|'); if (day >= since) rows.push({ day, surface, kind, n }); }
}
const out = {};
const blank = () => ({ member: 0, house: 0, none: 0 });
for (let i = 0; i < days; i++) { const d = ctDay(Date.now() - i * 86400000); out[d] = { day: d, dashboard: blank(), games: blank(), byGame: {} }; }
for (const r of rows) {
const o = out[r.day]; if (!o || !['member', 'house', 'none'].includes(r.kind)) continue;
if (r.surface === 'dashboard') o.dashboard[r.kind] += r.n;
else { o.games[r.kind] += r.n; if (r.kind !== 'none') o.byGame[r.surface] = (o.byGame[r.surface] || 0) + r.n; }
}
return Object.values(out).sort((a, b) => (a.day < b.day ? 1 : -1));
}
module.exports = { init, record, report };
+2 -1
View File
@@ -314,6 +314,7 @@
<div class="pane" id="pane-traffic" hidden>
<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>Login-ad showings</h3><span class="sub" id="lsSub">sign-in interstitials per day, dashboard vs games</span></div><div class="tablewrap"><table class="adm-table" id="trfLogin"></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>
@@ -565,6 +566,6 @@
</div>
<script src="/assets/common.js?v=20261016n"></script><script src="/assets/welcome.js?v=20260923b"></script>
<script src="/assets/admin.js?v=20261016tr"></script>
<script src="/assets/admin.js?v=20261018ls"></script>
</body>
</html>
+14
View File
@@ -601,6 +601,7 @@
});
async function loadTraffic() {
loadPromos().catch(e => IAP.status(e.message, 'bad'));
loadLoginShows().catch(e => IAP.status(e.message, 'bad'));
const d = await (await fetch('/api/admin/traffic?days=' + trfDays)).json();
if (d.error) throw new Error(d.error);
const esc = s => String(s == null ? '' : s).replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
@@ -619,6 +620,19 @@
$('trfAngles').innerHTML = '<tr><th>Angle</th><th>Join-page<br>views</th><th>Signups</th><th>View &rarr;<br>signup</th></tr>' + (d.angles.length ? d.angles.map(a => '<tr><td>' + esc(a.angle) + '</td><td>' + n(a.views) + '</td><td>' + n(a.signups) + '</td><td>' + pct(a.signups, a.views) + '</td></tr>').join('') : '<tr><td colspan="4" class="muted">No angle data yet.</td></tr>');
$('trfDaily').innerHTML = '<tr><th>Day</th><th>Page views</th><th>Signups</th></tr>' + (d.daily.length ? d.daily.slice().reverse().map(x => '<tr><td>' + esc(x.day) + '</td><td>' + n(x.hits) + '</td><td>' + n(x.signups) + '</td></tr>').join('') : '<tr><td colspan="3" class="muted">Nothing yet.</td></tr>');
}
// login-ad showings per Central day (2026-10-18): the dashboard gate vs the games' sign-in kit, member slot vs house ad,
// and sign-ins that had no login ad to show. A week of these decides whether the 3-slot cap goes up.
async function loadLoginShows() {
const d = await (await fetch('/api/admin/login-shows?days=14')).json();
if (d.error) throw new Error(d.error);
const esc = s => String(s == null ? '' : s).replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
const n = v => Number(v || 0).toLocaleString(), shown = x => x.member + x.house;
const week = d.days.slice(0, 7).reduce((a, x) => { a.dash += shown(x.dashboard); a.games += shown(x.games); return a; }, { dash: 0, games: 0 });
$('lsSub').textContent = 'last 7 days: ' + n(week.dash + week.games) + ' shown (' + n(week.dash) + ' dashboard, ' + n(week.games) + ' games) · slots ' + d.slots.used + ' of ' + d.slots.max + ' taken';
$('trfLogin').innerHTML = '<tr><th>Day (CT)</th><th>Dashboard<br>shown</th><th>Games<br>shown</th><th>Total<br>shown</th><th>Of which<br>house ad</th><th>Sign-ins with<br>no login ad</th><th>By game</th></tr>'
+ d.days.map(x => '<tr><td>' + esc(x.day) + '</td><td>' + n(shown(x.dashboard)) + '</td><td>' + n(shown(x.games)) + '</td><td><b>' + n(shown(x.dashboard) + shown(x.games)) + '</b></td><td>' + n(x.dashboard.house + x.games.house) + '</td><td>' + n(x.dashboard.none + x.games.none) + '</td><td class="small">'
+ (Object.keys(x.byGame).length ? Object.entries(x.byGame).map(([g, v]) => esc(g) + ' ' + n(v)).join(', ') : '<span class="muted">-</span>') + '</td></tr>').join('');
}
// ── blog: coaching articles, public at /blog (Marty, 2026-09-12) ──
let blCur = null; // slug being edited, or null for a new one
function blCount() {
+84 -3
View File
@@ -3,7 +3,10 @@
from the player's browser; the game only ever receives its normal hand-off token, which it opens at /auth.
Host page sets theme through CSS variables on .iapsi (--si-*). Usage:
IAPSignin.mount(el, { game: 'driprunner', ref: 'skycash', oneTap: 'https://instantadpay.com/api/my/driprunner' });
IAPSignin.enter('wallet'); // nudge: opens InstantAdPay in a new tab, already signed in */
IAPSignin.enter('wallet'); // nudge: opens InstantAdPay in a new tab, already signed in
After a fresh sign-in (never on a remembered pass) the kit shows the InstantAdPay login ad before the hand-off,
same as the dashboard: sponsor card, Open Ad (a counted click), 10 s countdown, then Continue. Any ad error,
or no ad to show, goes straight to the game. mount option loginAd: false switches it off (2026-10-18). */
(function () {
var IAP = 'https://instantadpay.com';
try { var me = document.currentScript && document.currentScript.src; if (me) IAP = new URL(me).origin; } catch (e) {}
@@ -27,9 +30,83 @@
+ '.iapsi .lk{background:none;border:0;padding:0;font:inherit;font-size:13.5px;color:var(--mu);text-decoration:underline;cursor:pointer}.iapsi .lk[disabled]{opacity:.5;cursor:default;text-decoration:none}'
+ '.iapsi form{display:grid;gap:12px;margin:0}.iapsi .row{display:flex;gap:14px;flex-wrap:wrap;justify-content:space-between}.iapsi label.ck{display:flex!important;gap:10px;align-items:flex-start;font-size:13px;color:var(--mu);margin:0}.iapsi .ck input{margin:3px 0 0;width:auto!important;flex:0 0 auto;height:auto;padding:0}.iapsi .ck span{flex:1}.iapsi .err:empty{display:none}'
+ '.iapsi .err{color:var(--si-bad,#ff8a8a);font-size:14px;min-height:1px}.iapsi .fine{font-size:12px;color:var(--mu)}.iapsi .fine a{color:var(--mu)}'
+ '.iapsi .hp{position:absolute;left:-9999px;width:1px;height:1px;opacity:0}.iapsi .chal{display:flex;gap:8px;flex-wrap:wrap}.iapsi .chal button{font-size:26px;width:52px;height:52px;border-radius:12px;border:1px solid var(--ln);background:var(--fl);cursor:pointer}';
+ '.iapsi .hp{position:absolute;left:-9999px;width:1px;height:1px;opacity:0}.iapsi .chal{display:flex;gap:8px;flex-wrap:wrap}.iapsi .chal button{font-size:26px;width:52px;height:52px;border-radius:12px;border:1px solid var(--ln);background:var(--fl);cursor:pointer}'
// login-ad gate (full screen, above the game page)
+ '.iapla{position:fixed;inset:0;z-index:2147483000;display:flex;flex-direction:column;background:var(--si-ground,#0d0b1a);color:var(--si-ink,#f2efff);font-family:var(--si-font,system-ui,sans-serif)}'
+ '.iapla-bar{display:flex;align-items:center;gap:10px 14px;flex-wrap:wrap;padding:10px 16px;background:var(--si-panel,#17142b);border-bottom:1px solid var(--si-line,rgba(255,255,255,.18))}'
+ '.iapla-brand{font-weight:800;font-size:15px;white-space:nowrap}.iapla-brand em{color:var(--si-accent,#7c5cff);font-style:normal}.iapla-note{flex:1;min-width:140px;font-size:13px;color:var(--si-muted,#b7b0d6)}'
+ '.iapla-timer{font-weight:700;font-size:14px;border:1px solid var(--si-line,rgba(255,255,255,.3));border-radius:999px;padding:4px 12px;white-space:nowrap}.iapla-timer.done{color:var(--si-accent,#7c5cff);border-color:var(--si-accent,#7c5cff)}'
+ '.iapla-btn{font:inherit;font-weight:700;font-size:14px;padding:9px 14px;border:0;border-radius:10px;background:var(--si-accent,#7c5cff);color:var(--si-accent-ink,#fff);cursor:pointer;text-decoration:none;white-space:nowrap}'
+ '.iapla-btn.sec{background:transparent;color:var(--si-ink,#f2efff);border:1px solid var(--si-line,rgba(255,255,255,.3))}.iapla-btn[disabled]{opacity:.55;cursor:default}.iapla-btn.big{font-size:17px;padding:13px 22px}'
+ '.iapla-frame{flex:1;border:0;width:100%;background:#fff;min-height:0}.iapla-body{flex:1;display:grid;place-items:center;padding:24px 16px;overflow:auto}'
+ '.iapla-card{max-width:560px;text-align:center;display:grid;gap:16px;justify-items:center}.iapla-card p{margin:0;font-size:14px;line-height:1.5;color:var(--si-muted,#b7b0d6)}'
+ '.iapla-eye{font-size:12px;letter-spacing:.12em;text-transform:uppercase}.iapla-card img{max-width:100%;max-height:50vh;border-radius:12px;border:1px solid var(--si-line,rgba(255,255,255,.18))}'
+ '.iapla-link{display:inline-block;font-size:20px;font-weight:700;color:var(--si-ink,#f2efff);background:var(--si-field,rgba(255,255,255,.06));border:1px solid var(--si-line,rgba(255,255,255,.18));border-radius:14px;padding:18px 22px}'
+ '.iapla [hidden]{display:none!important}';
function styleOnce() { if (document.getElementById('iapsiCss')) return; var s = document.createElement('style'); s.id = 'iapsiCss'; s.textContent = CSS; document.head.appendChild(s); }
// the login ad after a fresh sign-in. `then` (the hand-off) always runs exactly once: when the gate is done,
// when there is no ad, or on any error or a slow answer, so an ad can never hold a player out of the game.
function loginAd(game, then) {
var over = false; function go() { if (over) return; over = true; try { then(); } catch (e) {} }
var ctl = null; try { ctl = new AbortController(); } catch (e) {}
var slow = setTimeout(function () { if (ctl) try { ctl.abort(); } catch (e) {} go(); }, 7000);
fetch(IAP + '/api/game/ads/login?game=' + encodeURIComponent(game || ''), { credentials: 'omit', signal: ctl ? ctl.signal : undefined })
.then(function (r) { return r.ok ? r.json() : {}; })
.then(function (j) { clearTimeout(slow); if (over) return; var ad = j && j.ad; if (!ad || !ad.targetUrl) return go(); gate(ad, go); })
.catch(function () { clearTimeout(slow); go(); });
}
function gate(ad, go) {
var abs = function (u) { return /^https?:/i.test(u) ? u : IAP + u; };
var click = abs(ad.targetUrl), site = ad.siteUrl || click, framed = !!ad.frameable, started = false, t = null;
var g = document.createElement('div'); g.className = 'iapla'; g.setAttribute('role', 'dialog'); g.setAttribute('aria-label', 'Login sponsor');
g.innerHTML = '<div class="iapla-bar"><span class="iapla-brand">Instant<em>AdPay</em></span>'
+ '<span class="iapla-note" data-st>Login ad sponsor. Tap "Open Ad" to begin.</span>'
+ '<span class="iapla-timer" data-tm hidden></span>'
+ '<a class="iapla-btn sec" data-tab target="_blank" rel="noopener" hidden>Open site in a new tab \u2197</a>'
+ '<button class="iapla-btn" type="button" data-go hidden>Continue to the game</button></div>'
+ '<iframe class="iapla-frame" data-fr hidden sandbox="allow-scripts allow-same-origin allow-forms allow-popups" referrerpolicy="no-referrer" title="Sponsor site"></iframe>'
+ '<div class="iapla-body" data-bd><div class="iapla-card"><p class="iapla-eye">Today\'s login sponsor</p>'
+ (ad.imageUrl ? '<img src="' + esc(ad.imageUrl) + '" alt="sponsor ad">' : '<span class="iapla-link">' + esc(ad.title || 'Visit today\'s sponsor') + '</span>')
+ '<button class="iapla-btn big" type="button" data-open>Open Ad</button>'
+ '<p>' + (framed ? 'The sponsor\'s page opens right here under this bar. When the timer hits zero, your Continue button appears beside it.'
: 'This sponsor\'s site opens in a new tab. The timer counts down here; come back when it hits zero to continue to the game.') + '</p></div></div>';
var q = function (k) { return g.querySelector('[data-' + k + ']'); };
var st = q('st'), tm = q('tm'), tab = q('tab'), btn = q('go'), fr = q('fr'), bd = q('bd'), open = q('open');
function finish() { clearInterval(t); document.removeEventListener('securitypolicyviolation', csp); try { g.remove(); } catch (e) {} go(); }
// a game page whose CSP refuses the frame: offer the sponsor in a new tab instead (the timer keeps running)
function csp(ev) {
if (!started || !framed || !/frame|child|default/.test(String(ev.violatedDirective || ev.effectiveDirective || ''))) return;
var b = String(ev.blockedURI || '');
fr.hidden = true; bd.hidden = true; tab.hidden = false;
tab.href = (!b || b.indexOf(IAP) === 0) ? click : site; // blocked before our click relay ran: the tab is the counted click
st.textContent = 'This game cannot show the sponsor here. Open it in a new tab; the timer runs here.';
}
document.addEventListener('securitypolicyviolation', csp);
open.addEventListener('click', function () {
if (started) return; started = true; open.disabled = true;
if (framed) {
fr.src = click; // the click relay counts it, then redirects inside the frame
fr.hidden = false; bd.hidden = true; tab.href = site; tab.hidden = false;
st.textContent = 'Today\'s sponsor. Have a look; your Continue button appears when the timer ends.';
} else {
try { window.open(click, '_blank'); } catch (e) {} // the click relay counts it
st.textContent = 'The sponsor opened in a new tab. View it and come back; the timer runs here.';
}
var left = Math.max(1, Number(ad.dwell) || 10);
tm.hidden = false; tm.textContent = 'Time remaining: ' + left + 's';
t = setInterval(function () {
left -= 1;
if (left > 0) { tm.textContent = 'Time remaining: ' + left + 's'; return; }
clearInterval(t); tm.textContent = 'Time is up'; tm.className = 'iapla-timer done';
st.textContent = 'Thanks for the look. Your game is ready.'; btn.hidden = false;
try { btn.focus(); } catch (e) {}
}, 1000);
});
btn.addEventListener('click', finish);
document.body.appendChild(g);
}
function mount(el, opt) {
styleOnce(); opt = opt || {};
var game = opt.game, ref = String(opt.ref || '').toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 40), src = String(opt.src || '').toLowerCase().replace(/[^a-z0-9_.-]/g, '').slice(0, 30);
@@ -41,7 +118,11 @@
function done(r) {
if (r.pass) ls(PASS_KEY, JSON.stringify({ p: r.pass, exp: Date.now() + 29 * 86400000, email: email }));
if (r.needUsername) return stepName(r);
if (r.token) return onToken(r.token);
if (r.token) { // a fresh sign-in: the login ad first (fails open to the hand-off)
if (opt.loginAd === false) return onToken(r.token);
el.innerHTML = '<h2>You are in</h2><p>One moment\u2026</p>';
try { return loginAd(game, function () { onToken(r.token); }); } catch (e) { return onToken(r.token); }
}
err('Something went wrong. Try again.');
}
function stepEmail(msg) {
+48 -18
View File
@@ -31,6 +31,7 @@ const walletnudge = require('./walletnudge');
const milestone = require('./milestone'); // players with POL waiting in the games and no wallet (2026-10-07) // holding tank: unsponsored free members, adoptions, pay-it-forward
const legacy = require('./legacy'); // Faucet Wave / Tier One Ads bridge: welcome-back credits for listed emails
const traffic = require('./traffic'); // public page views by referring domain (admin Traffic tab)
const loginShows = require('./loginshows'); // login-ad showings per day, dashboard vs games (2026-10-18)
const promos = require('./promos');
const missedNotice = require('./missed'); // the whole-chain missed-payout notice // partner promo codes -> free ad credits (link ?promo=CODE or the dashboard box)
const blog = require('./blog');
@@ -477,14 +478,14 @@ function headUrl(url) {
// login-ad gate: can this sponsor's page load inside our frame? Cached 6 h per campaign + url; an answer that
// takes longer than 4 s counts as "no" for this sign-in (new-tab fallback) while the check finishes for the cache.
const loginFrameCache = new Map();
async function loginFrameable(id, url) {
const key = id + '|' + url, hit = loginFrameCache.get(key);
async function loginFrameable(id, url, inGame) { // inGame: the frame sits on a game's page, so an allowance for instantadpay.com alone is not enough
const key = (inGame ? 'g|' : '') + id + '|' + url, hit = loginFrameCache.get(key);
if (hit && Date.now() - hit.ts < 6 * 3600 * 1000) return hit.ok;
if (!url) return false;
const check = frameCheck(url).then(r => { loginFrameCache.set(key, { ok: !!r.ok, ts: Date.now() }); return !!r.ok; }).catch(() => false);
const check = frameCheck(url, inGame).then(r => { loginFrameCache.set(key, { ok: !!r.ok, ts: Date.now() }); return !!r.ok; }).catch(() => false);
return Promise.race([check, new Promise(r => setTimeout(() => r(false), 4000))]);
}
async function frameCheck(url) {
async function frameCheck(url, inGame) {
const h = await frameFetch(url, 0);
if (h.error) return { ok: false, reason: 'We checked your URL and ' + h.error + '. Fix the URL and try again.' };
if (h.status >= 400) return { ok: false, reason: 'Your URL answers with HTTP ' + h.status + '. Point the campaign at a working page.' };
@@ -493,7 +494,7 @@ async function frameCheck(url) {
const fa = /frame-ancestors\s+([^;]+)/i.exec(String(h.csp));
if (fa && !fa[1].split(/\s+/).some(x => {
const v = x.replace(/['"]/g, '').toLowerCase();
return v === '*' || v === 'https:' || v.includes('instantadpay.com');
return v === '*' || v === 'https:' || (!inGame && v.includes('instantadpay.com'));
}))
return { ok: false, reason: 'That site blocks framing (CSP frame-ancestors), so it would show members a blank page in the ad viewer. Use a landing page that allows framing.' };
return { ok: true };
@@ -589,6 +590,7 @@ async function boot() {
}
legacy.init({ dataDir: DATA_DIR });
traffic.init({ dataDir: DATA_DIR });
loginShows.init({ dataDir: DATA_DIR });
promos.init({ dataDir: DATA_DIR });
blog.init({ dataDir: DATA_DIR });
adminMember.init({ accounts, ads, chain, tank, legacy, promos, messages, dataDir: DATA_DIR });
@@ -744,7 +746,8 @@ function sendFile(res, file) {
// HTML is never stored (so a fresh load always gets the current asset
// versions — aggressive in-app wallet browsers were serving stale pages
// that pointed at old, since-fixed JS); versioned assets cache for an hour.
'Cache-Control': ext === '.html' ? 'no-store, must-revalidate' : 'public, max-age=3600' }));
// the games load the sign-in kit from here with no version tag, so it revalidates every load (2026-10-18)
'Cache-Control': ext === '.html' ? 'no-store, must-revalidate' : path.basename(file) === 'game-signin.js' ? 'no-cache' : 'public, max-age=3600' }));
res.end(data);
});
}
@@ -1788,13 +1791,14 @@ async function sdProgress(memberId) {
// here, kept by the game in localStorage, 30 days) that lets the game's "open InstantAdPay" nudges arrive signed in
// (POST /api/game/enter). The IAP device cookie cannot ride a cross-site request, so the game sends its own
// browser id (req.gameDev) for the device checks.
// frames: false = that game's page CSP (default-src 'self', no frame-src) refuses iframes, so its login ad opens in a new tab
const GAME_AUTH = {
driprunner: { name: 'Drip Runner', origins: () => [DR_URL()], host: () => DR_URL().replace(/^https?:\/\//, ''),
driprunner: { name: 'Drip Runner', frames: false, origins: () => [DR_URL()], host: () => DR_URL().replace(/^https?:\/\//, ''),
mint: (a, memberId) => drMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), wallet: a.address || null, username: a.username || null,
sponsorRef: a.sponsorRef || null, joinedRef: a.joinedRef || null, joinedAt: a.created || null }) },
seek: { name: 'ClutterHunt', origins: () => [SEEK_URL()].concat(SEEK_ALT()), host: () => SEEK_URL().replace(/^https?:\/\//, ''),
mint: (a, memberId) => seekMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
polybreak: { name: 'PolyBreak', origins: () => [PB_URL()].concat(PB_ALT()), host: () => PB_URL().replace(/^https?:\/\//, ''),
polybreak: { name: 'PolyBreak', frames: false, origins: () => [PB_URL()].concat(PB_ALT()), host: () => PB_URL().replace(/^https?:\/\//, ''),
mint: (a, memberId) => pbMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null, sponsorRef: a.sponsorRef || null }) },
spellwheel: { name: 'SpellWheel', origins: () => [SW_URL()].concat(SW_ALT()), host: () => SW_URL().replace(/^https?:\/\//, ''),
mint: (a, memberId) => swMint({ memberId: Number(memberId) || 0, email: String(a.email).toLowerCase(), username: a.username || null, wallet: a.address || null }) },
@@ -1807,6 +1811,25 @@ const GAME_AUTH = {
// Spooky Doors passed it before; signed-out visitors from the other games lost their sponsor)
const refQ = u => { const r = String(u.searchParams.get('ref') || '').trim().toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 20); return r ? '?ref=' + encodeURIComponent(r) : ''; };
const devOrigin = o => !IS_PROD && /^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(o);
// the sign-in login ad, shared by the dashboard (GET /api/ads/slot?type=login) and the games' sign-in kit
// (GET /api/game/ads/login). ads.serve counts the impression and marks lastShownDay, exactly as before; the
// member clicks "Open Ad" (a real, counted click through /api/ads/click) while the countdown runs. Every call
// is tallied per Central day and surface (loginshows.js) so the admin can compare dashboard and game sign-ins.
async function loginAdFor(req, surface) {
const ad = await ads.serve('login', viewerGeo(req));
let house = false;
if (ad) {
ad.dwell = ads.rates().loginDwellSeconds || 10;
// 2026-10-09: the gate frames the sponsor's page under our bar (timer + way out visible on the ad itself).
// Login campaigns were never frame-checked, so check here, once per campaign, and fall back to a new tab.
const site = await ads.targetOf(ad.id);
ad.siteUrl = site;
ad.frameable = await loginFrameable(ad.id, site, surface !== 'dashboard');
try { const c = await ads.campaignById(ad.id); house = !!(c && (c.house || c.owner === ads.HOUSE_OWNER)); } catch (e) {}
}
loginShows.record(surface, ad ? { house } : null).catch(() => {});
return ad;
}
function gameOf(req, slug) {
const g = Object.prototype.hasOwnProperty.call(GAME_AUTH, String(slug || '')) ? GAME_AUTH[slug] : null; if (!g) return null;
const o = String(req.headers.origin || '');
@@ -2294,6 +2317,17 @@ const server = http.createServer(async (req, res) => {
// -- in-game sign-in (2026-10-03): see GAME_AUTH. Mirrors /api/auth/email/start + verify, minus cookies.
if (p.startsWith('/api/game/auth/') && req.method === 'OPTIONS') { res.writeHead(204, gameCors(req)); return res.end(); }
// the login ad inside a game's sign-in kit, after a fresh sign-in (2026-10-18). CORS only for the GAME_AUTH
// origins of the named game (dev mode: localhost); the dashboard route stays same-origin.
if (p === '/api/game/ads/login' && (req.method === 'GET' || req.method === 'OPTIONS')) {
const g = gameOf(req, u.searchParams.get('game'));
const cors = g ? Object.assign(gameCors(req), { 'Access-Control-Allow-Methods': 'GET, OPTIONS' }) : { Vary: 'Origin' };
if (req.method === 'OPTIONS') { res.writeHead(204, cors); return res.end(); }
if (!g) return json(res, 403, { error: 'This game is not connected to InstantAdPay.' }, cors);
const ad = await loginAdFor(req, String(u.searchParams.get('game')));
if (ad && g.frames === false) ad.frameable = false;
return json(res, 200, { ad }, cors);
}
if (p === '/api/game/auth/start' && req.method === 'POST') {
const cors = gameCors(req); const b = await readBody(req); const g = gameOf(req, b.game);
if (!g) return json(res, 403, { error: 'This game is not connected to InstantAdPay.' }, cors);
@@ -3033,6 +3067,11 @@ const server = http.createServer(async (req, res) => {
}
// -- admin Traffic tab: page views + join-page views + signups + $20 buyers, by referring
// domain / first-touch source, by landing page, by angle and by day (Marty, 2026-09-12)
// login-ad showings per Central day, dashboard vs games (2026-10-18: a week of combined sign-ins before the cap decision)
if (p === '/api/admin/login-shows' && req.method === 'GET') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
return json(res, 200, { days: await loginShows.report(Number(u.searchParams.get('days')) || 14), slots: await ads.loginSlots() });
}
if (p === '/api/admin/traffic' && req.method === 'GET') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const days = Math.min(365, Math.max(1, Number(u.searchParams.get('days')) || 30));
@@ -4424,17 +4463,8 @@ const server = http.createServer(async (req, res) => {
// -- ad engine (spec §8b v1: banners, text, login ads)
if (p === '/api/ads/slot' && req.method === 'GET') {
const t = String(u.searchParams.get('type') || 'banner');
if (t === 'login') return json(res, 200, { ad: await loginAdFor(req, 'dashboard') });
const ad = await ads.serve(t, Object.assign({ width: Number(u.searchParams.get('w')) || 0, height: Number(u.searchParams.get('h')) || 0 }, viewerGeo(req)));
// login ads: the member clicks "Open Ad" (a real, counted click into a
// new tab) while the countdown runs on our interstitial page
if (ad && t === 'login') {
ad.dwell = ads.rates().loginDwellSeconds || 10;
// 2026-10-09: the gate frames the sponsor's page under our bar (timer + way out visible on the ad itself).
// Login campaigns were never frame-checked, so check here, once per campaign, and fall back to a new tab.
const site = await ads.targetOf(ad.id);
ad.siteUrl = site;
ad.frameable = await loginFrameable(ad.id, site);
}
return json(res, 200, { ad });
}
m = /^\/api\/ads\/click\/(\d+)$/.exec(p);