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