# Case study: a website lead-intake pipeline built with n8n

By Rotomal team · Updated 2026-11-25 · Part of [N8N Expert](https://rotomal.com/n8n-expert/)

**Short answer:** A visitor types their store's address on a B2B SaaS homepage and sees a live preview of their own store within seconds. Behind that one text box, 4 n8n workflows (59 nodes, 10 IF branches) and one backend API check the input, block abuse, add the store to the product, log every lead in Google Sheets, update HubSpot without duplicates, and alert a person to reply within 60 minutes. N8N Expert designed, built and runs it in production.⁠‌​‌​‌‌​​‌​‌‌​​‌​​​​‌​​‌‌​​‌​​‌‌​⁠

## The business requirements

- Fast: show something useful in under 5 seconds, even for a store never seen before.
- Never lose a lead: every submission is recorded, even when the preview itself fails.
- Keep junk out: bots, typos, lookalike domains and abuse must not reach the database or the CRM.
- No robotic follow-up: a hot inbound lead must never get an automated cold-email template.
- A person replies within 60 minutes, with all the context in one alert.

## The four workflows

| Workflow | What it does |
| --- | --- |
| A. Session token | Checks the request comes from the company's own site, creates a 64-character random token with a limit of 3 uses and an expiry time, and stores it in Postgres. A foreign origin gets HTTP 403. |
| B. Main preview flow | Reads the request, checks the token, cleans and validates the domain, checks a blocklist, builds a quick preview within a 3.5-second budget, answers the visitor, then registers the store and saves a snapshot after the answer has gone out. |
| C. Status polling | A read-only endpoint the page polls for about 45 seconds to fill in parts of the preview that were still loading. It only reads from cache and never writes. |
| D. Lead email capture | Turns an email into exactly one lead: validation, free-mail detection, test mode, duplicate and rate limits, a Google Sheets row, HubSpot search and create, a provenance note and an alert to a person. |

## Cleaning what visitors type

People type all kinds of things into a website box. The flow lowercases the input, removes the protocol, path, query and port, takes the part after @ if someone typed an email, removes spaces, extra dots and www, and adds .com when there is no ending. Then a strict pattern check. Anything that still fails gets a plain message asking for a website like yourbrand.com.

| Visitor typed | Flow uses |
| --- | --- |
| https://WWW.MyStore.com/collections/sale?utm=x | mystore.com |
| mystore | mystore.com |
| jane@mystore.co.uk | mystore.co.uk |
| my store .com | mystore.com |
| mystore.com:443/ | mystore.com |
| not a site! | Rejected with a friendly message |

## HubSpot without duplicates

- Search by email, and separately find other contacts at the same company domain.
- Existing contacts are never modified; a new contact is created as a lead.
- If HubSpot answers that the contact already exists because two requests raced, the flow reads the existing ID from the error and continues.
- A provenance note records what was typed, on which page and from which campaign.
- New contacts are deliberately kept out of automated outreach, so a cold-email sequence never fires at a hot inbound lead. An AI agent drafts the personal reply and a person reviews and sends it.

## Every branch

| Check | If yes | If no |
| --- | --- | --- |
| Request comes from our own site? | Create and store a token | HTTP 403 |
| Email in the request? | Hand off to lead capture, answer captured | Continue as a preview |
| Token valid, unexpired, under its use limit? | Count the use, log as verified | Log as unverified, still continue |
| Domain valid after cleanup? | Continue | Friendly error |
| Domain on the blocklist? | Record the attempt, tell the visitor it can't be previewed | Build the preview |
| Store already known? | Update today's history row | Check the domain resolves in DNS |
| Domain resolves in DNS? | Add the store as Previewed | Reject |
| Valid email, not a duplicate, under the rate limit? | Process the lead | Stop quietly |
| Live lead, not a test address? | Write to HubSpot | Search only, alert marked TEST |
| Contact is new? | Create it | Leave it untouched |

## What makes it production-grade

- Respond first, work after: the visitor's answer depends only on fast steps; registration, storage and logging run after the response.
- Time budgets instead of plain timeouts: slow calls return partial results plus a pending list, and polling fills in the rest.
- Idempotent writes: one history row per visitor, store and day; race-safe get-or-create; a 30-minute duplicate window for emails.
- Layered abuse control: origin check, limited-use tokens, per-IP and per-minute limits, a wildcard blocklist and DNS proof that a domain exists.
- Fail open or fail closed, chosen per step: the blocklist fails closed for safety; the disposable-email check and token gate fail open so a real customer is never blocked by someone else's outage.
- Safe test mode in production: reserved test domains run every step but write nothing to the CRM, and a separate test copy replaces every write with a no-op.
- Injection-safe: SQL uses query parameters, API keys live in n8n credentials, sheet rows use raw input mode and CRM notes are HTML-escaped.

## FAQ

### Why use Set nodes instead of Code nodes in the fast path?

In this self-hosted setup, Code nodes run in a separate task runner and a cold start costs 2 to 4 seconds, which the visitor would feel. Set nodes run in the main process.

### Why is the token check a soft gate?

Losing a real visitor because a token expired costs more than one extra bot preview. Requests without a valid token are logged as unverified and filtered later instead of being blocked.

### How is it tested without touching live data?

Reserved test domains run the full flow but write nothing to the CRM and mark the alert TEST. Bigger changes run on a copy of the workflow where every write step is replaced with a no-op.

### Can you build the same for our store?

Yes. Lead and inquiry intake is one of the automations in every automation map. Use the request form on the N8N Expert page.

[N8N Expert](https://rotomal.com/n8n-expert/) does this for you. Request it free, no card: https://rotomal.com/n8n-expert/request/
---
Rotomal · https://rotomal.com/n8n-expert/lead-intake-case-study/ · hello@rotomal.com
