diff --git a/public/assets/my.js b/public/assets/my.js index fc2f1fa..2e16e24 100644 --- a/public/assets/my.js +++ b/public/assets/my.js @@ -1075,7 +1075,7 @@ function shareLink(ref) { return SHARE_DOMAIN && /^[A-Za-z0-9_]{1,40}$/.test(Str function convSnips(host, g) { const h = 'https://' + String(host || 'linkspin.app').replace(/^https?:\/\//, '').replace(/\/+$/, ''); const px = encodeURIComponent(g.px), goal = encodeURIComponent(g.name); - const val = g.value != null && g.value !== '' ? '&value=' + encodeURIComponent(g.value) : ''; + const val = Number(g.value) > 0 ? '&value=' + encodeURIComponent(g.value) : ''; // a goal with no default value (LinkSpin stores 0) adds nothing return { landing: ' - + diff --git a/qa/convpixel.test.mjs b/qa/convpixel.test.mjs index 121615d..bfabc4b 100644 --- a/qa/convpixel.test.mjs +++ b/qa/convpixel.test.mjs @@ -43,7 +43,7 @@ fs.writeFileSync(path.join(DATA, 'campaigns.json'), JSON.stringify({ v: 1, nextI // ---- mock LinkSpin ---- const PX1 = 'px0123456789', PX2 = 'pxabcdef0123'; -const mock = { clicks: new Map(), badSig: 0, calls: [], down: false, goals: { [A1]: [{ px: PX1, name: 'subscriber', value: null, created: now - 86400000, conv: 6, convDays: 6, lastAt: now - 3600000, lastTest: null }, { px: PX2, name: 'sale', value: 19.95, created: now - 86400000, conv: 1, convDays: 1, lastAt: now - 7200000, lastTest: null }] } }; +const mock = { clicks: new Map(), badSig: 0, calls: [], down: false, goals: { [A1]: [{ px: PX1, name: 'subscriber', value: null, created: now - 86400000, conv: 6, convDays: 30, lastAt: now - 3600000, lastTest: null }, { px: PX2, name: 'sale', value: 19.95, created: now - 86400000, conv: 1, convDays: 30, lastAt: now - 7200000, lastTest: null }] } }; const verify = (ts, sig, raw) => { if (!ts || !sig || Math.abs(Date.now() - Number(ts)) > 300000) return false; const want = crypto.createHmac('sha256', SECRET).update(ts + '\n' + raw).digest('hex'); return want.length === String(sig).length && crypto.timingSafeEqual(Buffer.from(want), Buffer.from(String(sig))); }; const send = (res, code, obj) => { res.writeHead(code, { 'Content-Type': 'application/json' }); res.end(JSON.stringify(obj)); }; function mockHandler(req, res) { @@ -57,7 +57,7 @@ function mockHandler(req, res) { mock.calls.push(b); const email = String(b.email || ''); const goals = mock.goals[email] || (mock.goals[email] = []); if (b.op === 'summary') return send(res, 200, { ok: true, goals, byCampaign: email === A1 ? { 1: { clicks: 9, conv: { [PX1]: 4, [PX2]: 1 }, value: { [PX2]: 19.95 } }, 2: { clicks: 3, conv: {} } } : {}, methods: { url: 2, stored: 2, cookie: 1, soft: 1 }, host: 'linkspin.app' }); - if (b.op === 'create') { const g = { px: 'px' + crypto.randomBytes(5).toString('hex'), name: b.name, value: b.value == null ? null : b.value, created: Date.now(), conv: 0, convDays: 0, lastAt: null, lastTest: null }; goals.push(g); return send(res, 200, { ok: true, goal: g }); } + if (b.op === 'create') { const g = { px: 'px' + crypto.randomBytes(5).toString('hex'), name: b.name, value: b.value == null ? null : b.value, created: Date.now(), conv: 0, convDays: 30, lastAt: null, lastTest: null }; goals.push(g); return send(res, 200, { ok: true, goal: g }); } if (b.op === 'remove') { const i = goals.findIndex(g => g.px === b.px); if (i < 0) return send(res, 404, { error: 'No such goal.' }); goals.splice(i, 1); return send(res, 200, { ok: true }); } if (b.op === 'test') { const g = goals.find(x => x.px === b.px); if (!g) return send(res, 404, { error: 'No such goal.' }); g.lastTest = Date.now(); return send(res, 200, { ok: true, at: g.lastTest }); } return send(res, 400, { error: 'unknown op' }); @@ -164,7 +164,7 @@ try { line1: (document.querySelector('[data-convcamp="1"]') || {}).textContent || '', line1Hidden: !!(document.querySelector('[data-convcamp="1"]') || {}).hidden, line5Hidden: (document.querySelector('[data-convcamp="5"]') || { hidden: true }).hidden, card: !document.getElementById('convCard').hidden, status: document.getElementById('convStatus').textContent, - goals: document.querySelectorAll('#convGoals tbody tr').length, landing: (document.getElementById('convLanding') || {}).value || '', img: (document.getElementById('convImg') || {}).value || '', + goals: document.querySelectorAll('#convGoals tbody tr').length, convCells: [...document.querySelectorAll('#convGoals td[data-l="Conversions (30 days)"]')].map(td => (td.firstChild && td.firstChild.textContent || '').trim()), landing: (document.getElementById('convLanding') || {}).value || '', img: (document.getElementById('convImg') || {}).value || '', js: (document.getElementById('convJs') || {}).value || '', tip: document.getElementById('convCard').textContent })); await page.screenshot({ path: path.join(OUT, shot), fullPage: true }).catch(() => {}); await ctx.close(); return { st, errs }; @@ -173,6 +173,7 @@ try { ok(p1.st.rows >= 4 && p1.st.card, 'Campaigns pane loads with the Conversion tracking card', JSON.stringify(p1.st).slice(0, 200)); ok(!p1.st.line1Hidden && /subscriber 4 \(75 credits each\)/.test(p1.st.line1) && /sale 1 \(300 credits each\)/.test(p1.st.line1), 'campaign row shows goals + cost per goal (300 / 4 = 75 credits)', p1.st.line1); ok(!/\$/.test(p1.st.line1), 'cost per goal is in credits, never dollars'); + ok(JSON.stringify(p1.st.convCells) === '["6","1"]', 'goal rows show the conversion count, not the 30-day window (convDays is the window length)', JSON.stringify(p1.st.convCells)); ok(p1.st.goals === 2 && p1.st.landing === '', 'goal list + landing tag snippet', p1.st.landing); ok(p1.st.img === '' && p1.st.js === '', 'goal pixel image + JS snippets match the contract', p1.st.img + ' | ' + p1.st.js); ok(/Thank You Page: custom page/.test(p1.st.tip) && /Thank-you page: custom URL/.test(p1.st.tip) && /24-hour match/.test(p1.st.tip), 'autoresponder advice + match legend present');