Your main landing page lives on launch.example.com, but the company site is example.com or a Webflow page. You still want one waitlist backend, one Prisma table, and the same referral math. An embed waitlist form iframe Next.js route serves a chrome-free join UI at /embed that marketing drops into an <iframe> while POST /api/waitlist/signup stays the single write path.
This guide builds that route in the App Router: pass ?ref= into the embed URL, reuse honeypot and rate limiting on the API, and set headers so only your marketing origins can frame the page.
Embed vs full landing
Approach When to use Full landing (/) Pre-launch hero, FAQ, status links, SEO /embed iframe Blog, docs, partner site, footer CTA Widget JS (later) Shadow DOM on third parties; more moving parts
Iframe is the fastest path: no SDK, works on static CMS pages, and the signup API is identical to the main form.
Prerequisites
Working
POST /api/waitlist/signupfrom referral waitlist series.Optional double opt-in.
Known parent origins (e.g.
https://example.com,https://www.example.com).
Step 1: Create the embed route
Use a dedicated segment with a minimal layout (no global nav/footer).
app/embed/layout.tsx:
export default function EmbedLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body className="min-h-screen bg-transparent p-4">{children}</body>
</html>
);
}
app/embed/page.tsx:
import { EmbedWaitlistForm } from "./embed-waitlist-form";
type Props = {
searchParams: Promise<{ ref?: string }>;
};
export default async function EmbedPage({ searchParams }: Props) {
const params = await searchParams;
const defaultRef = params.ref ?? "";
return (
<main className="mx-auto max-w-md">
<EmbedWaitlistForm defaultRef={defaultRef} />
</main>
);
}
Marketing links:
<iframe
src="https://waitlist.example.com/embed?ref=PARENT_CAMPAIGN"
title="Join the waitlist"
width="100%"
height="220"
style="border:0;overflow:hidden;"
loading="lazy"
></iframe>
Pass the user’s referral code via query on the parent page, not only inside the iframe:
<!-- Parent already has ?ref=CODE from viral loop -->
<script>
const ref = new URLSearchParams(location.search).get("ref") || "";
const iframe = document.querySelector("iframe[data-waitlist]");
iframe.src = `https://waitlist.example.com/embed?ref=${encodeURIComponent(ref)}`;
</script>
Step 2: Embed form component
Reuse the same fields as the landing form: email, consent, hidden ref, honeypot website.
"use client";
export function EmbedWaitlistForm({ defaultRef }: { defaultRef: string }) {
async function onSubmit(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();
const form = new FormData(e.currentTarget);
const res = await fetch("/api/waitlist/signup", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
email: form.get("email"),
consent: form.get("consent") === "on",
ref: form.get("ref") || undefined,
website: form.get("website") ?? "",
}),
});
const data = await res.json().catch(() => ({}));
if (res.ok) {
if (data.redirectUrl) {
window.top.location.href = data.redirectUrl;
return;
}
if (data.referralCode) {
window.top.location.href = `/waitlist/status/${data.referralCode}`;
}
}
}
return (
<form onSubmit={onSubmit} className="space-y-3">
<input type="hidden" name="ref" defaultValue={defaultRef} />
<input
type="email"
name="email"
required
autoComplete="email"
placeholder="you@company.com"
className="w-full rounded border px-3 py-2"
/>
<label className="flex gap-2 text-sm">
<input type="checkbox" name="consent" required />
I agree to receive product updates.
</label>
<div
aria-hidden="true"
className="absolute left-[-9999px] h-0 w-0 overflow-hidden"
>
<input name="website" type="text" tabIndex={-1} autoComplete="off" />
</div>
<button type="submit" className="w-full rounded bg-black px-4 py-2 text-white">
Join waitlist
</button>
</form>
);
}
Redirect behavior: window.top.location sends the user to your status page on the waitlist domain (best for referral sharing). Alternatively return JSON only and show an inline success message inside the iframe if you must stay on the parent domain.
Step 3: Allow framing from marketing origins
Default Next.js does not always set X-Frame-Options: DENY, but you should be explicit. Use Content-Security-Policy frame-ancestors (modern) instead of X-Frame-Options: ALLOW-FROM (deprecated).
next.config.ts:
import type { NextConfig } from "next";
const embedAncestors = [
"'self'",
"https://example.com",
"https://www.example.com",
];
const nextConfig: NextConfig = {
async headers() {
return [
{
source: "/embed",
headers: [
{
key: "Content-Security-Policy",
value: `frame-ancestors ${embedAncestors.join(" ")};`,
},
],
},
{
source: "/embed/:path*",
headers: [
{
key: "Content-Security-Policy",
value: `frame-ancestors ${embedAncestors.join(" ")};`,
},
],
},
];
},
};
export default nextConfig;
Add staging origins while testing. Wildcard * is tempting on /embed; avoid it unless you accept any site embedding your signup and burning your rate limits.
Step 4: Cross-origin API calls
When the iframe is on waitlist.example.com and loads from the same host, fetch("/api/waitlist/signup") is same-origin. No CORS change.
If you mistakenly host the form JS on a CDN subdomain that posts to another host, you need CORS on the API. The kit pattern keeps iframe src and API on one waitlist app so cookies, rate limits, and honeypot stay centralized.
Parent on example.com embedding waitlist.example.com does not require CORS for the form POST (browser posts from the iframe origin).
Step 5: Abuse protection still applies
The embed is a public surface. Honeypot and IP rate limiting run on the Route Handler before Prisma. Bots that discover /embed get the same silent honeypot responses as the main landing.
Consider a lower rate limit bucket for /embed if partners iframe it on high-traffic pages (optional middleware tag via custom header from embed layout).
Step 6: Height and mobile
Iframes do not auto-resize. Options:
Fixed height (
220px) and compact form (this guide).postMessagefrom embed to parent withscrollHeight(more code, smoother UX).
// Optional inside EmbedWaitlistForm after mount
useEffect(() => {
const height = document.documentElement.scrollHeight;
window.parent.postMessage({ type: "waitlist-embed-height", height }, "*");
}, []);
Parent listens and sets iframe.style.height. Restrict postMessage target origin in production.
Step 7: Environment and deploy
Embeds fail silently when APP_URL / canonical status links point at localhost. Before production, align public URL env vars (see the waitlist Vercel env checklist in this series: nextjs-waitlist-env-variables-vercel-checklist when published). Minimum:
NEXT_PUBLIC_APP_URL=https://waitlist.example.comfor share links and redirectsResend keys if double opt-in is on
Step 8: Double opt-in from embed
When double opt-in is enabled, the embed should show the same “check your email” state as the landing page instead of jumping to the status page immediately.
Return JSON from signup:
return NextResponse.json({
pendingConfirm: true,
message: "Check your inbox to confirm.",
});
In EmbedWaitlistForm, branch on pendingConfirm and render inline copy inside the iframe (parent user may still be on a blog post). Do not redirect to status until confirmedAt is set via the confirm link.
Step 9: Status page URLs and referral share
After confirmation, send users to /waitlist/status/[referralCode] on the waitlist app origin, not the parent marketing domain. That keeps referral share links consistent with status page + referral links.
If marketing wants a “you are #42” teaser on the parent domain, use postMessage to pass a non-PII summary (position) after signup. Avoid embedding full email in messages.
Step 10: Test matrix before launch
Scenario Expected Embed on allowed parent Form visible, submit works Embed on blocked parent Browser refuses to frame ?ref= on parent propagated Row has referredById Honeypot filled 200, no DB row Rate limit exceeded 429 or soft message Mobile Safari iframe Inputs focusable, consent tappable
Use BrowserStack or real devices; iframe forms break when font-size or tap targets are too small inside 200px height.
Step 11: Analytics without leaking PII
Fire parent-page analytics on postMessage success (campaign id only), not on keystrokes inside the iframe. Inside the waitlist app, log server-side signup counts per embed referrer header or a hidden source=embed field in JSON.
Step 12: Legal and consent copy on embed
GDPR-friendly embeds repeat the same consent checkbox text as the landing page. Link to privacy terms hosted on the waitlist app. Short height iframes still need a visible consent control; do not hide required legal copy in the parent page only.
Step 13: Pair with webhooks (later)
When webhook on confirmed signup ships, embed signups trigger the same webhook as landing signups. source: embed in metadata helps CRMs segment traffic.
Step 14: Performance
Load /embed with minimal JS. No hero images, no third-party widgets. Target LCP under 1.5s so marketing pages are not penalized for iframe weight. Use loading="lazy" on the parent iframe.
Step 15: Staging vs production embed URLs
Use https://waitlist-staging.example.com/embed on staging parents only. Search engines should noindex embed routes via robots metadata in app/embed/layout.tsx so thin pages do not compete with your main landing SEO.
export const metadata = { robots: { index: false, follow: false } };
Troubleshooting
Blank iframe
Parent CSP blocks framing child, or child frame-ancestors omits parent. Check browser console for Refused to frame.
Referrals not attributed
ref empty in embed. Pass ?ref= on iframe src from parent query string.
Double opt-in link opens wrong host
Confirm email templates use production APP_URL, not preview deployment URLs.
Form submits but no redirect
Popup blockers rarely affect top navigation. Prefer window.top.location.href over window.open.
Implementation notes from production waitlists
Single top level navigation: Never call window.parent.location on cross-origin parents you do not control. It throws. Only redirect window.top when frame-ancestors allow framing from that parent.
Cookie banners on parent: Parent cookie overlays can cover the iframe on mobile. Ask marketing to reserve minimum height or delay the banner until after first scroll.
i18n: Keep embed copy minimal. Pass ?lang= and read it in EmbedPage if you localize later.
Accessibility: The iframe title attribute is required. Parent page should not duplicate a second invisible form for “SEO.”
Third-party CMP: If the parent runs consent management that blocks scripts, ensure the iframe src still loads (it is third-party content under GDPR interpretations on some sites).
Rate limit optics: When a partner iframe drives traffic spikes, rate limiting returns the same message as landing. Customize copy for embed via optional embed=1 field in JSON so UI says “Try again in a minute” without leaking stack traces.
CSP on waitlist app: Global CSP must not block your own /embed scripts. Test next dev and production headers separately.
Subdomain referrals: If marketing is www and waitlist is waitlist, referral share URLs in status should still use the canonical waitlist host from env.
Preview deployments: Vercel preview URLs change per branch. Do not embed preview iframes in production marketing pages or referrals break on every deploy.
Schema sync: Embed uses the same Prisma models as landing (waitlist schema). No duplicate tables.
Webhook payloads: Include source: "embed" in webhook JSON when you add integrations so automation routes embed signups differently if needed.
Step 16: Design checklist for marketing partners
Provide partners a one-page doc: iframe HTML, allowed parent origins, UTM guidance, and support contact. Partners should not restyle your form with CSS that targets cross-origin iframe contents (browsers block this). They control iframe dimensions only.
Step 17: Error states inside the iframe
Show inline errors for 400 validation (bad email) without navigating the parent. Rate-limit responses might say “Try again shortly” because parent users cannot see your main site toast stack.
const [error, setError] = useState<string | null>(null);
// setError from res.json() on failure
Step 18: Content Security Policy on parent sites
Some marketing stacks set script-src strictly but allow arbitrary iframes. Others block all frames. Test Webflow, Framer, and WordPress configurations before promising embed compatibility.
Step 19: Branding
Minimal embed CSS should accept optional ?theme=light query params for background transparency on dark marketing sites. Keep contrast WCAG-compliant; partners will blame your product if the form is illegible on their hero image.
Step 20: Future: script tag widget
An iframe-first launch ships faster than a JavaScript SDK. When you add a script widget later, keep one backend endpoint so metrics and abuse rules stay unified.
Embeds in the kit
Launch Waitlist Kit from Skryptix includes:
Landing, referrals, queue position, status page
/embedroute pattern, signup API, honeypot, rate limitsOptional double opt-in, admin CMS, webhooks
FAQ
What is the best URL for an embeddable waitlist in Next.js?
Use a dedicated route such as /embed with a minimal layout, loaded in an <iframe> on marketing sites. Share one POST /api/waitlist/signup handler with the main landing.
How do I pass referral codes into an embedded waitlist form?
Put ?ref=CODE on the iframe src, or copy ref from the parent page query into the iframe URL in a small script.
Do I need CORS for a waitlist iframe?
Usually no. The form runs inside the iframe on the waitlist domain and posts to the same origin API.
How do I prevent other sites from embedding my waitlist?
Set Content-Security-Policy: frame-ancestors to an allowlist of parent origins on /embed.
Can I embed on Webflow or WordPress?
Yes. Paste the iframe HTML into an embed block. Ensure HTTPS and allowed frame-ancestors.
Should the embed include honeypot fields?
Yes. Reuse the same honeypot field name and server checks as the main form so bots cannot bypass abuse controls via /embed.
What height should the iframe be?
Start around 200–260px for email + consent + button. Use postMessage resizing if you add more fields.
Can I use the embed on localhost marketing sites?
Yes for dev. Add http://localhost:3000 to frame-ancestors temporarily. Remove before production. Use separate env files for each allowlist.
Does embed affect referral queue position math?
No. Signup logic is identical
