Campaigns: optional daily cap on banner/text paces spend on-site and hands Network Ad Space one day's allowance at a time

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-10 10:03:57 -05:00
parent abf7415c83
commit 6e187c4f41
5 changed files with 12 additions and 4 deletions
+2 -1
View File
@@ -58,7 +58,8 @@ async function pushCampaign(c, opts = {}) {
const kind = nasKind(c.type);
if (!kind) return { skipped: 'type' };
const budgetLeft = c.budget - (c.spent || 0);
const assigned = Math.max(1, Math.floor(budgetLeft * impressionsPerCredit(c.type)));
const window = c.dailyCap ? Math.min(c.dailyCap, budgetLeft) : budgetLeft; // capped campaigns start with one day's allowance
const assigned = Math.max(1, Math.floor(window * impressionsPerCredit(c.type)));
const token = 'iap_' + crypto.randomBytes(8).toString('hex'); // manage token = Username
const now = new Date();
const days = Number(opts.days || 30);