Skip to content
// Score the lead against your ideal customer profile (ICP) with transparent points.
const icp = $('Settings (edit me)').first().json.icp;
const lead = $input.first().json;
const sg = lead.signals;
const reasons = [];
let score = 0;
const add = (pts, why) => { score += pts; reasons.push(`+${pts} ${why}`); };

// Industry: first keyword match in title/description/headline/page text
const hay = sg ? `${sg.title} ${sg.description} ${sg.headline} ${lead.page_text}`.toLowerCase() : '';
const industry = Object.entries(icp.industries).find(([, words]) => words.some((w) => hay.includes(w)))?.[0] ?? null;

if (industry && icp.target_industries.includes(industry)) add(25, `target industry (${industry})`);
if (!lead.free_email && lead.email) add(15, 'business email');
if (lead.site_ok) add(10, 'website reachable');
if (sg?.has_booking) add(10, 'uses online booking');
if (sg?.hiring) add(10, 'hiring (growing)');
const goodTech = (sg?.tech ?? []).filter((t) => icp.good_tech.includes(t));
if (goodTech.length) add(10, `tech fit (${goodTech.join(', ')})`);
if (sg && (sg.emails.length || sg.phones.length)) add(10, 'contact details on site');
if (sg?.socials.length) add(10, 'social presence');

return [{ json: { ...lead, industry, rule_score: Math.min(score, 100), rule_reasons: reasons } }];