Dmitry Troshenkov

What I checked on a lead form before the ads went live

· 5 min read

A remodeling company in the Bay Area was getting ready to run Google and Meta ads. All the ad traffic goes to one page with a quote form. If the form stops working, the ads keep spending money and nobody sees the problem until the leads stop coming.

The site is a Next.js app. It runs on a small Linux server and goes out through a Cloudflare Tunnel, so the server has no open ports. Everything below is on the Cloudflare free plan and free monitoring.

Bots and spam

The form already had a hidden honeypot field, Cloudflare Turnstile, and a limit in the app of 5 submissions per minute per IP. The app takes the visitor IP from the header Cloudflare adds. Without that, every visitor would look like the tunnel.

I wanted one more limit at Cloudflare, so bots are stopped before they reach the server. The rule: POST requests to /api/*, more than 10 in 10 seconds from one IP, block for 10 seconds. On the free plan you can’t choose a longer window.

I made the rule in the dashboard first. Later I checked the zone through the API, and the rule was not there. So I created it again through the API and tested it with 30 POST requests in a row:

RequestsResult
1 to 12204, passed to the app
13 to 30429, blocked by Cloudflare (error code: 1015)
10 seconds later204 again

The block started at request 13, a little after the limit of 10. Normal page views (GET) were not affected.

Redirects that keep the ad parameters

Ad clicks come with parameters like utm_source, gclid and fbclid. If a redirect loses them, you can’t tell which ad brought the lead.

I found two problems. The http:// version of the site opened the page and the form without encryption, so I turned on Always Use HTTPS. And www had no redirect at all, so I added a 301 from www to the main domain.

Then I checked that the path and the query string survive both redirects:

http://<domain>/?utm_source=t           301  https://<domain>/?utm_source=t
www.<domain>/privacy?utm_source=fb      301  https://<domain>/privacy?utm_source=fb

Email

Every lead sends an email to the team and an auto-reply to the customer. SPF, DKIM and DMARC were already set up. But DMARC was in p=none with no report address. In p=none DMARC only watches, and without a report address nobody gets to see what it watched. I added a rua address. The reports go to a mailbox on another domain, and that only works when the other domain publishes a small DNS record that allows it. That record is still on the list, so the reports haven’t started yet. When they come in clean for a week, I’ll switch to p=quarantine.

I also turned on DNSSEC in Cloudflare. It starts to work only when the domain registry publishes the DS record. Cloudflare is also the registrar here, so that should happen by itself within a day. It didn’t. Two days later the registry still had no DS record and the dashboard still said pending. I turned DNSSEC off and on again, and the record showed up at the registry about 40 minutes later. You can check yours with dig +short DS <domain>. Empty output means DNSSEC isn’t active, whatever the dashboard says.

Monitoring the form, not only the homepage

An uptime check on the homepage won’t notice a broken form. The page can load fine while the CRM key is expired or the captcha secret has changed.

The app has a health endpoint just for the lead path. It checks the CRM ingest key, the email provider, the Turnstile secret and a local spool folder, and returns a keyword. A monitor checks it every 3 minutes. There is also a normal uptime check and a heartbeat from the server.

If the CRM is down, the lead goes to the team by email. If email is down too, the lead is saved to a file on disk, the visitor sees an error, and the heartbeat stays red until someone clears the file. A lead can’t disappear without somebody getting an alert.

Content Security Policy

The site sends a Content Security Policy in enforce mode. Scripts can load only from a list of hosts: analytics, the ad pixels, Turnstile, and the Yelp and Google Maps widgets. Before I turned it on, I opened the production site in a browser with every tag running and checked that nothing was blocked. Violations are reported back to the site, so a broken tag shows up in the logs.

Speed

Lighthouse, mobile, on production, three runs. Performance 90, 94 and 94. Accessibility 100, Best Practices 100. LCP was 2.8 s on simulated slow 4G. The largest element is the photo at the top of the page. The real server response is about 175 ms.

Cost

Nothing new to pay for. The Cloudflare free plan, the free tier of a monitoring service, and a server that was already there. The free plans have limits (a fixed 10 second window for the rate limit, alerts only by email), and for a site with one form that is fine.

Checklist

If you are about to run ads to a form, this is what I would check:

If you want me to look at yours, message me on LinkedIn.