Files
linkspin/qa/bannerspin-attrib.test.cjs
T
martbost e545343fe0 Michael Camire fixes + hub shells in the tank (Marty 2026-11-14, LinkSpin Support)
1. Top-up across positions: an ad burns from ONE position, and topUpCampaign only looked at the ad's
   own position (or the main one when the list row had no memberId), so credits bought on a linked
   position could never top up the ad. Ported from InstantAdPay 2026-09-27 (Jim Watts): the ad's real
   member id is read from the campaign row; when it cannot cover, the refusal names where the free
   credits are and offers switchOptions; with the member's yes (switchTo, only a position on the
   account) moveFunding settles what the ad already ran up on the OLD position, moves the ad, then
   tops up. Ads screen asks in-page (own dialog) and retries. Create already had the largest-position guard.
2. Toasts: errors stay until closed (close button, role=alert), other notes 3.5 to 9 s by length.
3. Banner Spin per-banner clicks: his 3 clicks were all unmatched (no view on record for that browser),
   so they landed on the fallback row and every banner said 0. Click matching now also tries the same
   connection (daily-salted IP-only hash) when the browser key finds nothing (mail/exchange app view,
   click opened in the phone browser), view notes last 60 min instead of 15, and the stats split
   'Fallback shown' from 'Clicks not tied to a banner' so the rows add up to the total. History is not
   backfilled: views were never stored per visitor, so old clicks cannot be tied reliably.
4. Holding tank: hub-made waiting accounts with no sponsor are in the tank (waiting, rescue, readyTick
   read listAll with { shells: true }; 'hub-shell' no longer holds anyone back). Locked / sponsored /
   unknown, grace, 2-adoption cap unchanged; readyTick still never switches a shell on;
   accounts.listAll default unchanged (mailings skip shells).

Assets: cr.css, cr-shell.js, ads-screen.js ?v=20261114tu, banner-spin.js ?v=20261114bc.
QA: walk member 0 bugs (36 ok), netconv 57/57, networksso ALL PASSED, tank-hold all passed (new hub
shell part), profile policy 16/16, new topup-positions 8/8, new bannerspin-attrib 7/7, bannerspin e2e
75/75, hubsync 15 checks, tank-cap 15/15, sponsorfollow 30/30.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 11:59:38 -06:00

73 lines
5.5 KiB
JavaScript

// Banner Spin click attribution (Michael Camire 2026-11-14: his "Login Ad Explosion" showed Clicks 3 overall while every
// banner's own Clicks said 0. All three clicks came in with no view on record for that visitor, so they were counted on
// the fallback and no banner got them). Checks, on bannerspin.js directly (throwaway DATA_DIR, fake rotator, no server):
// impression -> click from the same browser credits that banner (note), the script embed's ?x= credits exactly,
// a click from the same connection in ANOTHER browser (mail app / exchange app view, click opens in the phone browser)
// credits the banner it was shown (ip), a click with no view anywhere stays "not tied to a banner",
// and banner rows + fallback shown + not tied add up to the Banner Spin totals.
// node qa/bannerspin-attrib.test.cjs
'use strict';
const assert = require('assert');
const fs = require('fs');
const os = require('os');
const path = require('path');
const SITE = path.join(__dirname, '..');
const DATA = fs.mkdtempSync(path.join(os.tmpdir(), 'bs-attrib-'));
const bs = require(path.join(SITE, 'bannerspin.js'));
const rotator = { cellAt: () => 0, zoneFor: () => 'UTC', isOn: () => true, rawRotations: () => [], cleanHours: () => ({}), cleanTz: () => ({ tz: 'visitor' }) };
const OWNER = 'owner@bs.test';
let passed = 0, failed = 0; const results = [];
async function t(name, fn) { try { await fn(); passed++; results.push('ok ' + name); } catch (e) { failed++; results.push('FAIL ' + name + '\n ' + String(e && e.stack || e).split('\n').slice(0, 4).join('\n ')); } }
const req = (url, ip, ua, referer) => ({ url, headers: Object.assign({ 'x-forwarded-for': ip, 'user-agent': ua }, referer ? { referer } : {}), socket: {} });
const TG = n => 'https://offer.example/b' + n;
(async () => {
bs.init({ dataDir: DATA, rotator, adminEmail: OWNER, schedule: false });
let S, code;
await t('a Banner Spin with 3 banners (one target each) and a fallback', async () => {
const c = await bs.create(OWNER, { name: 'Attrib', size: '468x60', fallback: 'https://fallback.example/' }); assert.ok(!c.error, c.error);
S = c.spin; code = S.code;
for (const n of [1, 2, 3]) { const r = await bs.addBanner(OWNER, S.id, { image: 'https://img.example/' + n + '.png', target: TG(n), weight: 10 }); assert.ok(!r.error, r.error); }
});
const shown = async (ip, ua, ref) => { const im = await bs.image(code, req('/i/' + code + '.gif', ip, ua, ref), null); const n = Number(/\/(\d)\.png$/.exec(im.url)[1]); return n; };
const clickAs = (ip, ua, ref, q) => bs.click(code, req('/c/' + code + (q || ''), ip, ua, ref), 'linkspin.app');
const want = { 1: 0, 2: 0, 3: 0 };
await t('impression -> click, same browser, with a referrer: that banner, matched by note', async () => {
for (let i = 0; i < 6; i++) {
const ip = '10.9.0.' + i, ua = 'Mozilla/5.0 Desktop' + i; const n = await shown(ip, ua, 'https://exchange-a.example/surf');
const c = await clickAs(ip, ua, 'https://exchange-a.example/surf');
assert.strictEqual(c.url, TG(n)); assert.strictEqual(c.matched, 'note'); assert.strictEqual(c.banner.id, n); want[n]++;
}
});
await t('impression -> click, same browser, no referrer on either (mailer, privacy settings): that banner', async () => {
const n = await shown('10.9.1.1', 'Mozilla/5.0 Quiet', ''); const c = await clickAs('10.9.1.1', 'Mozilla/5.0 Quiet', '');
assert.strictEqual(c.banner && c.banner.id, n); assert.strictEqual(c.matched, 'note'); want[n]++;
});
await t('viewed in a mail or exchange app, clicked in the phone browser (same IP, other UA): that banner, matched by ip', async () => {
const n = await shown('10.9.2.2', 'MailApp/3.1 (Android) WebView', ''); const c = await clickAs('10.9.2.2', 'Mozilla/5.0 (Linux; Android 14) Chrome/130 Mobile', '');
assert.strictEqual(c.banner && c.banner.id, n); assert.strictEqual(c.matched, 'ip'); assert.strictEqual(c.url, TG(n)); want[n]++;
});
await t('script embed click (?x=2) credits banner 2 exactly', async () => {
const c = await clickAs('10.9.3.3', 'Mozilla/5.0 Script', 'https://blog.example/', '?x=2'); assert.strictEqual(c.banner.id, 2); assert.strictEqual(c.matched, 'exact'); want[2]++;
});
await t('a click with no view anywhere: fallback link, not tied to a banner', async () => {
const c = await clickAs('10.9.4.4', 'Mozilla/5.0 NeverSaw', ''); assert.strictEqual(c.banner, null); assert.strictEqual(c.matched, 'none'); assert.strictEqual(c.url, 'https://fallback.example/');
});
await t('stats: per-banner clicks match what was shown, and banners + fallback shown + not tied = the total', async () => {
bs.flush();
const st = await bs.stats(OWNER, S.id);
for (const b of st.banners) assert.strictEqual(b.clicks, want[b.id], 'banner ' + b.id + ' clicks ' + b.clicks + ' want ' + want[b.id]);
assert.strictEqual(st.unmatched.clicks, 1); assert.strictEqual(st.fallback.clicks, 0);
const sum = st.banners.reduce((n, b) => n + b.clicks, 0) + st.fallback.clicks + st.unmatched.clicks;
assert.strictEqual(sum, st.totals.clicks); assert.strictEqual(st.totals.clicks, 10);
assert.strictEqual(st.totals.matched, 9); assert.strictEqual(st.totals.unmatched, 1);
const views = st.banners.reduce((n, b) => n + b.imps, 0) + st.fallback.imps; assert.strictEqual(views, st.totals.imps); assert.strictEqual(st.totals.imps, 8);
});
console.log(results.join('\n'));
console.log('\nbannerspin-attrib: ' + passed + ' passed, ' + failed + ' failed');
try { fs.rmSync(DATA, { recursive: true, force: true }); } catch (e) {}
process.exit(failed ? 1 : 0);
})();