| 1 | const KEY = process.env.GTM_TOOLS_API_KEY!; |
| 2 | |
| 3 | const WEIGHTS: Record<string, number> = { |
| 4 | signal_hiring_sales_rep_repost: 5, |
| 5 | signal_trustpilot_negative_support_reviews: 4, |
| 6 | signal_hiring_support: 3, |
| 7 | signal_hiring_sales_leadership: 3, |
| 8 | signal_socials_spike: 2, |
| 9 | signal_technologies_identified: 2, |
| 10 | signal_hiring_sales_rep: 2, |
| 11 | signal_hiring_role: 1, |
| 12 | signal_trustpilot_negative_reviews: 1, |
| 13 | }; |
| 14 | |
| 15 | interface Detection { |
| 16 | name: string; |
| 17 | fired: boolean; |
| 18 | evidence?: unknown[]; |
| 19 | } |
| 20 | |
| 21 | interface DetectResponse { |
| 22 | domain: string; |
| 23 | signals: Detection[]; |
| 24 | } |
| 25 | |
| 26 | interface Scored { |
| 27 | domain: string; |
| 28 | score: number; |
| 29 | fired: string[]; |
| 30 | } |
| 31 | |
| 32 | async function detect(domain: string, techs: string[]): Promise<DetectResponse | null> { |
| 33 | const res = await fetch("https://api.gtm-tools.sh/api/v0/detect_signal", { |
| 34 | method: "POST", |
| 35 | headers: { |
| 36 | "Authorization": `Bearer ${KEY}`, |
| 37 | "Content-Type": "application/json", |
| 38 | }, |
| 39 | body: JSON.stringify({ domain, techs }), |
| 40 | }); |
| 41 | if (!res.ok) { |
| 42 | console.error(`detect_signal ${domain}: ${res.status}`); |
| 43 | return null; |
| 44 | } |
| 45 | return res.json(); |
| 46 | } |
| 47 | |
| 48 | function score(d: DetectResponse): Scored { |
| 49 | const fired = d.signals.filter((s) => s.fired).map((s) => s.name); |
| 50 | const total = fired.reduce((acc, name) => acc + (WEIGHTS[name] ?? 1), 0); |
| 51 | return { domain: d.domain, score: total, fired }; |
| 52 | } |
| 53 | |
| 54 | async function run(domains: string[], techs: string[]) { |
| 55 | const results: Scored[] = []; |
| 56 | for (let i = 0; i < domains.length; i += 5) { |
| 57 | const slice = domains.slice(i, i + 5); |
| 58 | const detected = await Promise.all(slice.map((d) => detect(d, techs))); |
| 59 | for (const d of detected) { |
| 60 | if (d) results.push(score(d)); |
| 61 | } |
| 62 | console.log(`scored ${results.length}/${domains.length}`); |
| 63 | } |
| 64 | return results.sort((a, b) => b.score - a.score); |
| 65 | } |
| 66 | |
| 67 | const TARGETS = [ |
| 68 | "gymshark.com", |
| 69 | "mammaly.de", |
| 70 | "kettleandfire.com", |
| 71 | "spanx.com", |
| 72 | "siena.cx", |
| 73 | ]; |
| 74 | |
| 75 | const ranked = await run(TARGETS, ["zendesk.com", "intercom.com"]); |
| 76 | |
| 77 | console.log("\n=== Top targets ==="); |
| 78 | for (const r of ranked.slice(0, 10)) { |
| 79 | if (r.score === 0) break; |
| 80 | console.log(`${r.score.toString().padStart(3)} ${r.domain} [${r.fired.join(", ")}]`); |
| 81 | } |