Network rate 4:1 (Marty approved 2026-10-27): syndicated delivery costs 1/synRateDivisor of the on-site rate, going forward
rates.synRateDivisor (default 4, Admin > Rates; 1 = the old rule). Network Ad Space impressions charge 1 credit per impressionsPerCredit x N views (banner 20, text 40 at N=4), through the same chargeCredits path (earned pool first, then on-chain burn), with their own credit-log line "Network views (1/4 rate)". Fractions are exact: the cumulative served count carries the remainder. The budget is the limit: NAS bookings, resume, top-up and daily allowances are sized at the network rate, and a live ad booked at the old rate is topped up once to what its budget now buys. PassiveDrip: N partner visits use up 1 pack visit (floor on the cumulative count), every partner visit counted in the new syn_imps column, PD offered visits left x N. Nothing already charged changes. Member Campaigns: network views and partner visits marked "at 1/4", a note under the table, a Network rate chip. Chatbot canned answer + live AI fact. Cache tags bumped. QA: qa/run.sh nas (served 8, restart 9, ratio 15), chatbot-sync, run.sh member all passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
// 2. GET <bridge>?a=ptc_served -> [{iapId, received}] (cumulative visits PD delivered per campaign). Delivery is READ
|
||||
// from PD, never derived: the delta since our last read is applied through ads.applyExternalVisits, which bumps
|
||||
// imps and closes the pack when the ordered count is reached. Our last-read counters live in DATA_DIR/pdsync.json.
|
||||
// SYNDICATED RATE (Marty 2026-10-27, 4:1): N = ads.synRateDivisor() partner visits use up ONE visit of the pack
|
||||
// (floor(now/N) - floor(prev/N) on the cumulative count, so fractions carry exactly); every partner visit is still
|
||||
// counted in the campaign's syn_imps for the member's stats, and PD is offered (visits left) x N.
|
||||
//
|
||||
// FEATURE-FLAGGED: inert unless PD_BRIDGE_URL and PD_BRIDGE_SECRET are set. Geo-restricted campaigns are not sent
|
||||
// (PassiveDrip's audience is worldwide).
|
||||
@@ -16,6 +19,7 @@ const fs = require('fs'), path = require('path'), http = require('http'), https
|
||||
|
||||
let X = null, FILE = null, S = { served: {}, last: null }, running = false;
|
||||
function enabled() { return !!(process.env.PD_BRIDGE_URL && process.env.PD_BRIDGE_SECRET); }
|
||||
const synN = () => { try { return (X && X.ads && X.ads.synRateDivisor) ? X.ads.synRateDivisor() : 1; } catch (e) { return 1; } };
|
||||
function init(opts) { X = opts; FILE = path.join(opts.dataDir, 'pdsync.json'); try { S = Object.assign(S, JSON.parse(fs.readFileSync(FILE, 'utf8'))); } catch (e) {} }
|
||||
function save() { try { fs.writeFileSync(FILE, JSON.stringify(S)); } catch (e) {} }
|
||||
|
||||
@@ -37,7 +41,7 @@ function bridge(action, method, body) {
|
||||
async function listing() {
|
||||
const all = await X.ads.adminList(2000);
|
||||
return all.filter(c => c.type === 'visits' && c.status === 'active' && !c.doorOnly && !c.geo && !(c.starts && c.starts > Date.now()) && /^https?:\/\//.test(c.targetUrl || ''))
|
||||
.map(c => ({ id: c.id, title: String(c.name || c.title || 'Sponsor').slice(0, 64), desc: String((c.title && String(c.title).toLowerCase() !== String(c.name || '').toLowerCase()) ? c.title : '').slice(0, 128), url: c.targetUrl, visitsLeft: Math.max(0, Number(c.body || 0) - Number(c.imps || 0)) }))
|
||||
.map(c => ({ id: c.id, title: String(c.name || c.title || 'Sponsor').slice(0, 64), desc: String((c.title && String(c.title).toLowerCase() !== String(c.name || '').toLowerCase()) ? c.title : '').slice(0, 128), url: c.targetUrl, visitsLeft: Math.max(0, Number(c.body || 0) - Number(c.imps || 0)) * synN() }))
|
||||
.filter(c => c.visitsLeft > 0);
|
||||
}
|
||||
|
||||
@@ -54,7 +58,8 @@ async function sync() {
|
||||
const id = String(row.iapId); const now = Number(row.received) || 0; const prev = Number(S.served[id] || 0);
|
||||
if (now <= prev) { if (now < prev) S.served[id] = now; continue; } // PD's counter reset (row recreated): re-baseline, never charge backwards
|
||||
if (process.env.PD_SYNC_APPLY === '0') { S.served[id] = now; t.ignored = (t.ignored || 0) + (now - prev); continue; } // staging bridge: test views are read and baselined, never counted as delivery
|
||||
try { const res = await X.ads.applyExternalVisits(Number(id), now - prev, 'PassiveDrip'); S.served[id] = now; t.applied += res.applied || 0; if (res.closed) t.closed++; }
|
||||
const N = synN(); const units = Math.floor(now / N) - Math.floor(prev / N); // pack visits these partner visits use up
|
||||
try { const res = await X.ads.applyExternalVisits(Number(id), units, 'PassiveDrip', now - prev); S.served[id] = now; t.applied += res.applied || 0; if (res.closed) t.closed++; }
|
||||
catch (e) { console.error('pdsync apply', id, e.message); } // one bad row never stops the others; its delta is retried next sync
|
||||
}
|
||||
save();
|
||||
|
||||
Reference in New Issue
Block a user