Conversion tracking fixes (Marty approved 2026-10-26): own clicks are tests on every click type, Banner Spin straight-to-page clicks carry lsclk
1. Own clicks: a goal owner's own click on ANY click type (LinkSpin/InstantAdPay ads, spin links, Banner Spins) is kept as a test, never counted, never fires a goal postback. Own = ad click flagged self for that owner, a spin-link / Banner Spin click marked at click time (signed in as the owner, or from an owner soft key: markOwnClick in server.js), or the clicking or converting browser's soft key is one the owner signs in from. auth.onSeen notes LinkSpin session soft keys (throttled, kept 31 days in convtrack.json S.own); /api/partner/clicks takes owners [{owner, sk, ts}] from InstantAdPay before the clicks, so IAP members' own browsers are known too. Linked positions share the owner's email. X-LS-Result adds ;self. partnerSummary returns selfTests for the IAP card. Conversions screen copy: test with Send a test conversion and the &test=1 page check, own clicks never count (conversions.js ?v=20261026a).
3. Banner Spin: a click whose target is a direct page (not a /r/ spin link) gets ?lsclk=<k click id> when the owner tracks goals (string insert like lsconv.withClickId: params kept, before #hash, an existing lsclk never replaced). convtrack.lookup resolves k ids through bannerspin.clickById; conversions record k:'bspin' with the Banner Spin, banner, page and source; report By Banner Spin, CSV site 'Banner Spin', postback ctx with its sub ids.
Guides: /conversion-tracking (Banner Spin straight to a page now counted, own clicks on every type are tests, By Banner Spin), /refuel tile. Chatbot CANNED + FACTS, KNOWLEDGE_DATE 2026-10-26.
QA: convpixel 77/77 (new: owner soft keys, own ad/spin/Banner Spin/IAP clicks as tests, stranger still counts, own-browser conversion, withClickId, Banner Spin lsclk + By Banner Spin + spin-link banner untouched, selfTests in the IAP summary, no postback for own clicks); lsid 31/31; fuel all pass (engine.js / engine-room.js / kit.js untouched, byte-identical with InstantAdPay); bannerspin 75/75; member walk 0 bugs; public 0 bugs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+72
-18
@@ -12,7 +12,9 @@
|
||||
// The method that matched is kept on the conversion so Reports can say how solid each count is.
|
||||
// - Rules: each goal counts once per click (per ROOT click: an ad click and the spin-link click it led to are one
|
||||
// click), only within 30 days of a real click, only for clicks the pixel's owner owns (the ad's owner or the spin
|
||||
// link's owner), per-pixel and per-IP rate limits. A test conversion is recorded apart and never counted.
|
||||
// link's owner), per-pixel and per-IP rate limits. A test conversion is recorded apart and never counted. The goal
|
||||
// owner's own click (any type: ad, spin link, Banner Spin) is kept as a test, never counted (2026-10-26).
|
||||
// - Banner Spin clicks ('k' + 11 hex) that go straight to a page carry lsclk too since 2026-10-26 (bannerspin.js).
|
||||
// Storage: DATA_DIR/convtrack.json (JSON in both modes, like rotator.json / postbacks.json), debounced writes.
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
@@ -21,19 +23,20 @@ const crypto = require('crypto');
|
||||
|
||||
const DAY = 86400000, WINDOW_MS = 30 * DAY, SOFT_MS = 24 * 3600000, MAX_GOALS = 20;
|
||||
const MAX_CLICKS = 300000, MAX_CONV = 100000;
|
||||
let FILE = null, S = null, dirty = false, rotator = null, campaignOf = async () => null;
|
||||
let FILE = null, S = null, dirty = false, rotator = null, bannerspin = null, campaignOf = async () => null;
|
||||
|
||||
function load() {
|
||||
if (S) return S;
|
||||
try { S = JSON.parse(fs.readFileSync(FILE, 'utf8')); } catch (e) { S = null; }
|
||||
if (!S || typeof S !== 'object') S = {};
|
||||
S.v = 1; S.goals = S.goals || {}; S.clicks = S.clicks || {}; S.soft = S.soft || {}; S.conv = Array.isArray(S.conv) ? S.conv : []; S.camps = S.camps || {}; S.tests = S.tests || {};
|
||||
S.own = S.own || {}; S.selfIds = S.selfIds || {}; // own-click tests (2026-10-26): soft key -> { owner email: last seen }, click id -> marked at
|
||||
return S;
|
||||
}
|
||||
function save() { dirty = true; }
|
||||
function flush() { if (!dirty || !S || !FILE) return; dirty = false; try { fs.writeFileSync(FILE + '.tmp', JSON.stringify(S)); fs.renameSync(FILE + '.tmp', FILE); } catch (e) { console.error('convtrack save', e.message); } }
|
||||
function init(opts) {
|
||||
FILE = path.join(opts.dataDir, 'convtrack.json'); rotator = opts.rotator || null; if (opts.campaignOf) campaignOf = opts.campaignOf;
|
||||
FILE = path.join(opts.dataDir, 'convtrack.json'); rotator = opts.rotator || null; bannerspin = opts.bannerspin || null; if (opts.campaignOf) campaignOf = opts.campaignOf;
|
||||
S = null; load();
|
||||
if (!opts.noTimers) { setInterval(flush, 3000).unref(); setInterval(prune, 3600000).unref(); }
|
||||
}
|
||||
@@ -50,6 +53,34 @@ function ipOf(req) { return String(req.headers['x-forwarded-for'] || (req.socket
|
||||
// the soft key: InstantAdPay computes exactly the same thing for its ad clicks (contract 2026-10-23)
|
||||
function softKey(req) { return 's:' + crypto.createHash('sha256').update(ipOf(req) + '|' + String(req.headers['user-agent'] || '')).digest('hex').slice(0, 20); }
|
||||
|
||||
// ── own clicks are tests, on every click type (Marty approved 2026-10-26) ───────────────────────────────────────
|
||||
// A member clicking their OWN ad, spin link or Banner Spin and converting is a test, never a count. Known by: the click
|
||||
// was made while signed in as the owner (ads), or the clicking / converting browser's soft key is one the owner has been
|
||||
// seen signed in from (LinkSpin sessions, noted by auth.js; InstantAdPay sessions, pushed with its clicks). Linked
|
||||
// positions sit on the owner's own email, so they are the owner here too. Soft keys kept 31 days (the click window).
|
||||
const OWN_MS = WINDOW_MS + DAY, ownNoted = new Map();
|
||||
const isSk = sk => /^s:[a-f0-9]{20}$/.test(String(sk || ''));
|
||||
function noteOwner(email, sk, ts) {
|
||||
const e = norm(email); if (!e || e.length > 190 || !isSk(sk)) return false;
|
||||
const at = Math.min(Number(ts) || Date.now(), Date.now()); const k = e + '|' + sk;
|
||||
if ((ownNoted.get(k) || 0) > at - 600000) return false; ownNoted.set(k, at); if (ownNoted.size > 20000) ownNoted.clear();
|
||||
const st = load(); const m = st.own[sk] = st.own[sk] || {};
|
||||
if (!(m[e] >= at)) m[e] = at;
|
||||
const keys = Object.keys(m); if (keys.length > 8) { keys.sort((a, b) => m[a] - m[b]); for (const x of keys.slice(0, keys.length - 8)) delete m[x]; }
|
||||
save(); return true;
|
||||
}
|
||||
function noteSession(email, req) { try { return noteOwner(email, softKey(req)); } catch (e) { return false; } }
|
||||
// InstantAdPay's pushed rows: [{ owner, sk, ts }] (its members' own sessions)
|
||||
function importOwners(rows) { let n = 0; for (const r of (Array.isArray(rows) ? rows.slice(0, 2000) : [])) if (r && noteOwner(r.owner, r.sk, r.ts)) n++; return n; }
|
||||
function isOwnerSk(owner, sk) { const m = isSk(sk) && load().own[sk]; const t = m && m[norm(owner)]; return !!(t && Date.now() - t <= OWN_MS); }
|
||||
// spin-link and Banner Spin clicks: marked when the owner made them (signed in on this host, or from an owner soft key)
|
||||
function markSelfClick(id, owner, req, sessionEmail) {
|
||||
if (!isClickId(id) || !owner) return false;
|
||||
const mine = (sessionEmail && norm(sessionEmail) === norm(owner)) || isOwnerSk(owner, softKey(req));
|
||||
if (mine) { load().selfIds[id] = Date.now(); save(); }
|
||||
return !!mine;
|
||||
}
|
||||
|
||||
// ── goals ───────────────────────────────────────────────────────────────────────────────────────────────────────
|
||||
function pubGoal(g) { return { px: g.px, name: g.name, value: g.value || 0, created: g.created, lastTest: (load().tests[g.px] || 0) || null }; }
|
||||
function goalsOf(owner) { const o = norm(owner); return Object.values(load().goals).filter(g => g.owner === o).sort((a, b) => a.created - b.created); }
|
||||
@@ -85,7 +116,7 @@ function recordAdClick(camp, req, extra) {
|
||||
const sk = softKey(req);
|
||||
let pl = String((extra && extra.placement) || ''); if (!pl) { try { const r = new URL(String(req.headers.referer || '')); pl = (r.hostname.replace(/^www\./, '') + r.pathname).slice(0, 80); } catch (e) {} }
|
||||
st.clicks[id] = { id, k: 'ad', camp: Number(camp.id), cname: String(camp.name || camp.title || '').slice(0, 80), type: camp.type || '', owner: norm(camp.owner), ts: Date.now(), sk,
|
||||
c: (extra && extra.country) || '', dv: /mobile|android|iphone|ipad/i.test(ua) ? 'mobile' : 'desktop', pl, self: extra && extra.self ? 1 : undefined, target: String(camp.targetUrl || '').slice(0, 300) };
|
||||
c: (extra && extra.country) || '', dv: /mobile|android|iphone|ipad/i.test(ua) ? 'mobile' : 'desktop', pl, self: (extra && extra.self) || isOwnerSk(camp.owner, sk) ? 1 : undefined, target: String(camp.targetUrl || '').slice(0, 300) };
|
||||
noteSoft(sk, id, camp.owner); trimClicks(); save();
|
||||
return id;
|
||||
}
|
||||
@@ -99,7 +130,7 @@ function importClicks(rows) {
|
||||
const sk = /^s:[a-f0-9]{20}$/.test(String(r.sk || '')) ? String(r.sk) : '';
|
||||
const had = !!st.clicks[id];
|
||||
st.clicks[id] = { id, k: 'iap', camp: Number(r.camp) || 0, cname: String(r.cname || '').slice(0, 80), type: String(r.type || '').slice(0, 12), owner, ts, sk,
|
||||
c: String(r.c || '').toUpperCase().replace(/[^A-Z]/g, '').slice(0, 2), dv: r.dv === 'mobile' ? 'mobile' : 'desktop', pl: String(r.pl || '').slice(0, 80), self: r.self ? 1 : undefined, target: String(r.target || '').slice(0, 300) };
|
||||
c: String(r.c || '').toUpperCase().replace(/[^A-Z]/g, '').slice(0, 2), dv: r.dv === 'mobile' ? 'mobile' : 'desktop', pl: String(r.pl || '').slice(0, 80), self: r.self || isOwnerSk(owner, sk) ? 1 : undefined, target: String(r.target || '').slice(0, 300) };
|
||||
if (r.camp) { const key = 'iap:' + Number(r.camp); const cur = st.camps[key] || {}; if (!cur.ts || ts >= cur.ts) st.camps[key] = { owner, name: String(r.cname || '').slice(0, 80), spent: Math.max(0, Number(r.spent) || 0), ts }; }
|
||||
if (!had && sk) noteSoft(sk, id, owner, ts);
|
||||
n++;
|
||||
@@ -116,6 +147,8 @@ function prune() {
|
||||
for (const k in st.clicks) if (now - st.clicks[k].ts > WINDOW_MS + DAY) delete st.clicks[k];
|
||||
for (const k in st.soft) { const l = st.soft[k].filter(x => now - x[1] <= SOFT_MS); if (l.length) st.soft[k] = l; else delete st.soft[k]; }
|
||||
for (const k in st.camps) if (now - st.camps[k].ts > 400 * DAY) delete st.camps[k];
|
||||
for (const k in st.selfIds) if (now - st.selfIds[k] > OWN_MS) delete st.selfIds[k];
|
||||
for (const k in st.own) { const m = st.own[k]; for (const e in m) if (now - m[e] > OWN_MS) delete m[e]; if (!Object.keys(m).length) delete st.own[k]; }
|
||||
if (st.conv.length > MAX_CONV) st.conv = st.conv.slice(-Math.floor(MAX_CONV * 0.8));
|
||||
save(); flush();
|
||||
}
|
||||
@@ -126,11 +159,16 @@ function lookup(id) {
|
||||
const st = load();
|
||||
const ad = st.clicks[id];
|
||||
if (ad) return { id, root: id, ts: ad.ts, owners: [ad.owner], ad };
|
||||
if (rotator && rotator.hitById) {
|
||||
if (rotator && rotator.hitById && id[0] !== 'k') { // spin-link ids are 10 hex, never 'k' (that is Banner Spin's)
|
||||
const h = rotator.hitById(id); if (!h || !h.hit || h.hit.bot) return null;
|
||||
const via = h.hit.ac && st.clicks[h.hit.ac] ? st.clicks[h.hit.ac] : null;
|
||||
return { id, root: via ? via.id : id, ts: via ? Math.min(via.ts, h.hit.ts) : h.hit.ts, owners: [h.owner].concat(via ? [via.owner] : []), ad: via, spin: h };
|
||||
}
|
||||
// a Banner Spin click ('k' + 11 hex) that went straight to a page (2026-10-26: those now carry lsclk too)
|
||||
if (bannerspin && bannerspin.clickById && id[0] === 'k') {
|
||||
const b = bannerspin.clickById(id); if (!b || !b.click || b.click.bot) return null;
|
||||
return { id, root: id, ts: b.click.ts, owners: [b.owner], bspin: b };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -162,22 +200,26 @@ function record(q, req, cookies) {
|
||||
if (!hit) return { result: refused ? 'refused' : 'nomatch' };
|
||||
const st = load();
|
||||
if (st.conv.some(c => c.px === g.px && (c.root === hit.root || c.click === hit.id || c.root === hit.id))) return { result: 'dup', method: hit.method };
|
||||
const ad = hit.ad, sp = hit.spin;
|
||||
const ad = hit.ad, sp = hit.spin, bs = hit.bspin;
|
||||
const value = q.value != null && q.value !== '' ? cleanValue(q.value) : (g.value || 0);
|
||||
const self = ad && ad.self ? 1 : undefined; // the advertiser's own click: kept as a test, never in the counts
|
||||
// the goal owner's own click, on ANY click type (ad, spin link, Banner Spin): kept as a test, never in the counts.
|
||||
// Own = the ad click was flagged self for this owner, the spin / Banner Spin click was marked at click time, or the
|
||||
// clicking or converting browser is one the owner has been seen signed in from (2026-10-26).
|
||||
const self = (ad && ad.self && ad.owner === g.owner) || st.selfIds[hit.id] || st.selfIds[hit.root] || isOwnerSk(g.owner, sk) || (ad && ad.sk && isOwnerSk(g.owner, ad.sk)) ? 1 : undefined;
|
||||
const conv = { id: crypto.randomBytes(6).toString('hex'), ts: now, px: g.px, goal: g.name, owner: g.owner, click: hit.id, root: hit.root, method: hit.method, value,
|
||||
k: ad ? ad.k : 'spin', camp: ad ? ad.camp : undefined, cname: ad ? ad.cname : undefined, ctype: ad ? ad.type : undefined,
|
||||
k: ad ? ad.k : (bs ? 'bspin' : 'spin'), camp: ad ? ad.camp : undefined, cname: ad ? ad.cname : undefined, ctype: ad ? ad.type : undefined,
|
||||
rot: sp ? sp.rotation.id : undefined, rcode: sp ? sp.rotation.code : undefined, rname: sp ? sp.rotation.name : undefined,
|
||||
dest: sp ? sp.destUrl : (ad ? ad.target : undefined), sr: sp ? (sp.hit.sr || undefined) : undefined, src: sp ? sp.hit.s : (ad ? ad.pl : undefined),
|
||||
c: (sp ? sp.hit.c : ad && ad.c) || '', dv: (sp ? sp.hit.dv : ad && ad.dv) || '', self };
|
||||
bs: bs ? bs.spin.id : undefined, bcode: bs ? bs.spin.code : undefined, bname: bs ? bs.spin.name : undefined, bban: bs && bs.banner ? bs.banner.id : undefined,
|
||||
dest: sp ? sp.destUrl : (bs ? bs.destUrl : (ad ? ad.target : undefined)), sr: sp ? (sp.hit.sr || undefined) : (bs ? (bs.click.sr || undefined) : undefined), src: sp ? sp.hit.s : (bs ? (bs.click.h || 'direct') : (ad ? ad.pl : undefined)),
|
||||
c: (sp ? sp.hit.c : (bs ? bs.click.c : ad && ad.c)) || '', dv: (sp ? sp.hit.dv : (bs ? bs.click.dv : ad && ad.dv)) || '', self };
|
||||
for (const k of Object.keys(conv)) if (conv[k] === undefined) delete conv[k];
|
||||
st.conv.push(conv); save();
|
||||
return { result: 'counted', method: hit.method, conv, hit };
|
||||
}
|
||||
// the postback context for a counted conversion (postbacks.fire)
|
||||
function postbackCtx(r) {
|
||||
const c = r.conv, sp = r.hit && r.hit.spin;
|
||||
return { q: sp ? (sp.hit.q || {}) : {}, source: c.src || '', country: c.c || '', device: c.dv || '', lsid: c.click, code: c.rcode || '', sourceId: c.sr || '', payout: c.value || 0, currency: 'USD', label: c.goal };
|
||||
const c = r.conv, sp = r.hit && r.hit.spin, bs = r.hit && r.hit.bspin;
|
||||
return { q: sp ? (sp.hit.q || {}) : (bs ? (bs.click.q || {}) : {}), source: c.src || '', country: c.c || '', device: c.dv || '', lsid: c.click, code: c.rcode || c.bcode || '', sourceId: c.sr || '', payout: c.value || 0, currency: 'USD', label: c.goal };
|
||||
}
|
||||
// the landing tag's beacon: it saw a click id on the member's page. Returns the id when it is a real click of the pixel's owner.
|
||||
function landing(px, id, req) {
|
||||
@@ -197,11 +239,12 @@ async function report(owner, days, opts) {
|
||||
const selfTests = st.conv.filter(c => c.owner === o && c.ts >= since && c.self).length;
|
||||
const methods = { url: 0, stored: 0, cookie: 0, soft: 0 };
|
||||
const byGoal = {};
|
||||
const at = (gname) => (byGoal[gname] = byGoal[gname] || { goal: gname, n: 0, value: 0, methods: { url: 0, stored: 0, cookie: 0, soft: 0 }, campaigns: {}, links: {}, dests: {}, sources: {} });
|
||||
const at = (gname) => (byGoal[gname] = byGoal[gname] || { goal: gname, n: 0, value: 0, methods: { url: 0, stored: 0, cookie: 0, soft: 0 }, campaigns: {}, links: {}, banners: {}, dests: {}, sources: {} });
|
||||
for (const c of conv) {
|
||||
const G = at(c.goal); G.n++; G.value += c.value || 0; G.methods[c.method] = (G.methods[c.method] || 0) + 1; methods[c.method] = (methods[c.method] || 0) + 1;
|
||||
if (c.camp) { const key = (c.k === 'iap' ? 'iap:' : 'ls:') + c.camp; const x = G.campaigns[key] = G.campaigns[key] || { key, site: c.k === 'iap' ? 'InstantAdPay' : 'LinkSpin', id: c.camp, name: c.cname || '', n: 0, value: 0 }; x.n++; x.value += c.value || 0; }
|
||||
if (c.rot) { const x = G.links[c.rot] = G.links[c.rot] || { id: c.rot, code: c.rcode, name: c.rname || '', n: 0, value: 0 }; x.n++; x.value += c.value || 0; }
|
||||
if (c.bs) { const x = G.banners[c.bs] = G.banners[c.bs] || { id: c.bs, code: c.bcode, name: c.bname || '', n: 0, value: 0 }; x.n++; x.value += c.value || 0; }
|
||||
if (c.dest) { let d = c.dest; try { const u = new URL(c.dest); d = u.hostname.replace(/^www\./, '') + u.pathname.replace(/\/$/, ''); } catch (e) {} const x = G.dests[d] = G.dests[d] || { k: d, n: 0 }; x.n++; }
|
||||
{ const key = c.sr ? 'src:' + c.sr : (c.src || '(direct)'); const x = G.sources[key] = G.sources[key] || { k: key, sourceId: c.sr || '', n: 0 }; x.n++; }
|
||||
}
|
||||
@@ -222,7 +265,7 @@ async function report(owner, days, opts) {
|
||||
const sources = Object.values(G.sources).map(x => Object.assign(x, { name: x.sourceId ? ((meta[x.sourceId] || {}).name || 'Deleted source') : x.k })).sort((a, b) => b.n - a.n).slice(0, 15);
|
||||
const g = goals.find(y => y.name === gname);
|
||||
out.push({ goal: gname, px: g ? g.px : null, removed: !g, n: G.n, value: Math.round(G.value * 100) / 100, methods: G.methods, campaigns,
|
||||
links: Object.values(G.links).sort((a, b) => b.n - a.n).slice(0, 15), dests: Object.values(G.dests).sort((a, b) => b.n - a.n).slice(0, 15), sources });
|
||||
links: Object.values(G.links).sort((a, b) => b.n - a.n).slice(0, 15), banners: Object.values(G.banners).sort((a, b) => b.n - a.n).slice(0, 15), dests: Object.values(G.dests).sort((a, b) => b.n - a.n).slice(0, 15), sources });
|
||||
}
|
||||
return { days: Number(days) || 30, goals: goals.map(g => Object.assign(pubGoal(g), { conv: conv.filter(c => c.px === g.px).length, lastAt: (conv.filter(c => c.px === g.px).pop() || {}).ts || null })),
|
||||
byGoal: out, methods, total: conv.length, selfTests };
|
||||
@@ -238,17 +281,28 @@ function partnerSummary(owner, days) {
|
||||
for (const c of conv) if (c.k === 'iap' && c.camp) { const b = byCampaign[c.camp] = byCampaign[c.camp] || { clicks: 0, conv: {}, value: {} }; b.conv[c.px] = (b.conv[c.px] || 0) + 1; b.value[c.px] = Math.round(((b.value[c.px] || 0) + (c.value || 0)) * 100) / 100; }
|
||||
const methods = { url: 0, stored: 0, cookie: 0, soft: 0 }; for (const c of conv) methods[c.method] = (methods[c.method] || 0) + 1;
|
||||
const goals = goalsOf(o).map(g => { const mine = conv.filter(c => c.px === g.px); return Object.assign(pubGoal(g), { conv: mine.length, convDays: Number(days) || 30, lastAt: mine.length ? mine[mine.length - 1].ts : null }); });
|
||||
return { ok: true, goals, byCampaign, methods };
|
||||
const selfTests = st.conv.filter(c => c.owner === o && c.ts >= since && c.self).length; // own clicks, kept as tests (InstantAdPay shows "N from your own clicks")
|
||||
return { ok: true, goals, byCampaign, methods, selfTests };
|
||||
}
|
||||
function csv(owner, days) {
|
||||
const o = norm(owner); const since = Date.now() - (Math.max(1, Math.min(400, Number(days) || 30))) * DAY;
|
||||
const esc = v => { const s = v == null ? '' : String(v); return /[",\n]/.test(s) || /^[=+\-@]/.test(s) ? '"' + (/^[=+\-@]/.test(s) ? "'" : '') + s.replace(/"/g, '""') + '"' : s; };
|
||||
const ctFmt = new Intl.DateTimeFormat('en-CA', { timeZone: 'America/Chicago', year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hour12: false });
|
||||
const lines = ['time_central,goal,value,match_method,site,campaign_id,campaign,spin_link,destination,source,country,device,click_id'];
|
||||
for (const c of load().conv) if (c.owner === o && c.ts >= since && !c.self) lines.push([ctFmt.format(new Date(c.ts)).replace(',', ''), c.goal, c.value || 0, c.method, c.k === 'iap' ? 'InstantAdPay' : (c.k === 'ad' ? 'LinkSpin ad' : 'Spin link'), c.camp || '', c.cname || '', c.rcode || '', c.dest || '', c.src || '', c.c || '', c.dv || '', c.click].map(esc).join(','));
|
||||
for (const c of load().conv) if (c.owner === o && c.ts >= since && !c.self) lines.push([ctFmt.format(new Date(c.ts)).replace(',', ''), c.goal, c.value || 0, c.method, c.k === 'iap' ? 'InstantAdPay' : (c.k === 'ad' ? 'LinkSpin ad' : (c.k === 'bspin' ? 'Banner Spin' : 'Spin link')), c.camp || '', c.cname || '', c.rcode || (c.bcode ? 'c/' + c.bcode : ''), c.dest || '', c.src || '', c.c || '', c.dv || '', c.click].map(esc).join(','));
|
||||
return lines.join('\n') + '\n';
|
||||
}
|
||||
// "Send a test conversion" from a screen (InstantAdPay's partner call, or the Control Room when it cannot load the image)
|
||||
function testGoal(owner, px) { const g = goal(px); if (!g || g.owner !== norm(owner)) return { error: 'No such goal.' }; load().tests[g.px] = Date.now(); save(); flush(); return { ok: true, at: load().tests[g.px] }; }
|
||||
function adminCounts() { const st = load(); return { goals: Object.keys(st.goals).length, clicks: Object.keys(st.clicks).length, conversions: st.conv.length }; }
|
||||
module.exports = { countSince, init, flush, prune, softKey, isPx, isClickId, isAdId, cleanName, cleanValue, goalsOf, goal, createGoal, updateGoal, recordAdClick, importClicks, lookup, record, postbackCtx, landing, report, partnerSummary, csv, adminCounts, testGoal, LIMITS, WINDOW_MS, SOFT_MS };
|
||||
// append lsclk=<id> the way InstantAdPay's lsconv.withClickId does: string insert (every existing param keeps its exact
|
||||
// encoding), before any #hash, an lsclk already there never replaced, a URL that does not parse goes out unchanged
|
||||
function withClickId(target, id) {
|
||||
const t = String(target || '');
|
||||
let u; try { u = new URL(t); } catch (e) { return t; }
|
||||
if (!/^https?:$/.test(u.protocol) || u.searchParams.has('lsclk') || !isClickId(id)) return t;
|
||||
const hashAt = t.indexOf('#'); const base = hashAt >= 0 ? t.slice(0, hashAt) : t; const hash = hashAt >= 0 ? t.slice(hashAt) : '';
|
||||
const sep = base.includes('?') ? (/[?&]$/.test(base) ? '' : '&') : '?';
|
||||
return base + sep + 'lsclk=' + encodeURIComponent(id) + hash;
|
||||
}
|
||||
module.exports = { noteOwner, noteSession, importOwners, isOwnerSk, markSelfClick, withClickId, countSince, init, flush, prune, softKey, isPx, isClickId, isAdId, cleanName, cleanValue, goalsOf, goal, createGoal, updateGoal, recordAdClick, importClicks, lookup, record, postbackCtx, landing, report, partnerSummary, csv, adminCounts, testGoal, LIMITS, WINDOW_MS, SOFT_MS };
|
||||
|
||||
Reference in New Issue
Block a user