Add interest field to mailing list subscribe (telecom/trucking/formation)
- Footer subscribe modal: new "I'm interested in" dropdown with 3 options - Hoisted JS: reads interest field, validates selection, passes to API - Subscribe API: routes to different Listmonk lists by interest (telecom→list 3, trucking→list 8, formation→list 9) - Interest stored as subscriber attribute for campaign segmentation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
33da00fd89
commit
f1027694a3
3 changed files with 16 additions and 7 deletions
|
|
@ -7,7 +7,16 @@ const LISTMONK_URL = process.env.LISTMONK_URL || "http://listmonk:9000";
|
|||
const LISTMONK_USER = process.env.LISTMONK_USER || "api";
|
||||
const LISTMONK_PASS = process.env.LISTMONK_PASSWORD || "";
|
||||
|
||||
async function addToListmonk(email: string, name: string, company?: string) {
|
||||
// Listmonk list IDs by interest area
|
||||
const LISTMONK_LISTS: Record<string, number[]> = {
|
||||
telecommunications: [3], // FCC Carriers - Direct Contacts
|
||||
trucking: [8], // FMCSA / DOT Carriers
|
||||
formation: [9], // Business Formation Leads
|
||||
};
|
||||
const DEFAULT_LISTS = [3]; // fallback to telecom list
|
||||
|
||||
async function addToListmonk(email: string, name: string, company?: string, interest?: string) {
|
||||
const lists = (interest && LISTMONK_LISTS[interest]) || DEFAULT_LISTS;
|
||||
const resp = await fetch(`${LISTMONK_URL}/api/subscribers`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
|
@ -18,9 +27,9 @@ async function addToListmonk(email: string, name: string, company?: string) {
|
|||
email,
|
||||
name: name || email.split("@")[0],
|
||||
status: "enabled",
|
||||
lists: [3], // FCC Carriers - Direct Contacts
|
||||
lists,
|
||||
preconfirm_subscriptions: true,
|
||||
attribs: { company: company || "", source: "website" },
|
||||
attribs: { company: company || "", source: "website", interest: interest || "" },
|
||||
}),
|
||||
});
|
||||
if (!resp.ok && resp.status !== 409) {
|
||||
|
|
@ -44,7 +53,7 @@ const CONSENT_TEXT =
|
|||
// POST /api/v1/subscribe
|
||||
router.post("/api/v1/subscribe", submitLimiter, async (req, res) => {
|
||||
try {
|
||||
const { email, name, company, consent, _hp, _ts } = req.body ?? {};
|
||||
const { email, name, company, interest, consent, _hp, _ts } = req.body ?? {};
|
||||
|
||||
// Honeypot — bots fill hidden fields
|
||||
if (_hp) {
|
||||
|
|
@ -106,7 +115,7 @@ router.post("/api/v1/subscribe", submitLimiter, async (req, res) => {
|
|||
}
|
||||
|
||||
try {
|
||||
await addToListmonk(cleanEmail, name || cleanEmail, company || undefined);
|
||||
await addToListmonk(cleanEmail, name || cleanEmail, company || undefined, interest || undefined);
|
||||
} catch (listmonkErr) {
|
||||
console.error("[subscribe] Listmonk addToListmonk failed (non-fatal):", listmonkErr);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue