How to build an OptinMonster alternative
How to build an OptinMonster alternative with one accessible popup, confirmed subscriptions, and a private lead table. Test consent, failures, and deployment.
How to build an OptinMonster alternative starts with one accessible lead form with explicit consent.
We will build one optional signup popup and a private lead list. Begin with the OptinMonster catalog prompt. The OptinMonster post explains why a small campaign can be enough. Leave behavioral targeting and exit intent outside this version.
How to build an OptinMonster alternative with one campaign
Choose a single offer and write the actual consent text before creating the form. A person should know which newsletter they are joining and how to leave it. Opening the popup should be an explicit button action for the first release. That avoids timers interrupting reading and makes accessibility checks easier to reproduce.
Keep an inline form available if JavaScript fails. The popup is an enhancement around that same server endpoint. Do not make the email field accessible only through a client-side component. A successful request means the confirmation process started; it does not immediately mean the address belongs to the person who typed it.
| Record | Purpose | Key fields |
|---|---|---|
| Campaign | Published offer | Name, consent revision, status |
| Signup request | Pending confirmation | Normalized email, token hash, expiry |
| Subscription | Confirmed consent | Campaign, email, confirmation time |
| Suppression | Stop delivery | Email, reason, timestamp |
Step 1 Build an accessible dialog
Use a native dialog element with an accessible heading and close button. Opening it moves focus inside. Closing it restores focus to the opener. Escape should close it. Keep the content usable at narrow widths and increased text size, including when a phone keyboard covers part of the screen.
Build one campaign page with an inline email signup form. Enhance its
Subscribe button with a native accessible dialog containing the same form.
Support keyboard open, Escape, close and focus restoration. Preserve the
inline flow without JavaScript. Include consent text, privacy link and
server-rendered validation errors associated with the email field.
Navigate using only the keyboard. Submit an invalid address and confirm the error is announced and visible beside the field. Close and reopen the dialog; it should not submit anything. With JavaScript disabled, complete the inline form and receive a normal HTML response. Test zoom without clipping the close control.
Step 2 Save a pending request before confirmation
Normalize email consistently while preserving the entered address for display when appropriate. Keep domain handling conservative; avoid stripping dots or plus aliases based on guesses about a provider. Give pending requests a lifetime and store only the hash of a random confirmation token. A confirmed subscription needs its consent text revision.
Implement pending signups with bounded email validation, campaign status
checks and expiring single-use confirmation tokens stored as hashes.
Rate-limit by appropriate coarse abuse signals without building visitor
profiles. Return the same public response for new and existing addresses.
Keep confirmation delivery in an outbox with a unique request id.
Try an existing subscriber, an address still pending and a new address. Public messages should avoid disclosing which one is on the list. Turn the campaign off while a form is open and submit it. The server should reject the request because campaign status is enforced again at write time.
Step 3 Confirm once and preserve consent history
The confirmation route checks the token hash, expiry and campaign. Consuming it and creating the subscription happen together. Refreshing a successful confirmation should show a stable outcome. A bad or expired link should offer a fresh signup flow without revealing the associated email address.
Build token confirmation as an atomic state transition. Save the campaign,
consent revision and confirmation timestamp with the subscription. A token
cannot confirm another campaign or another address. Repeated confirmation
returns a safe completed state. Expired and malformed links show a clear
retry path without exposing subscriber details.
Create a token, advance the clock beyond expiry in a test environment and open it. Verify that no subscription appears. Confirm another token twice and inspect the database for a single subscription. If consent wording changes between request and confirmation, keep the version the person accepted or require a fresh request with the new text.
Step 4 Suppress before sending anything else
This build sends only confirmation email through an established delivery provider. If you later add campaigns, the suppression check belongs immediately before each delivery attempt. An unsubscribe can arrive after a send job was queued. A frozen recipient list still needs that final check when delivery begins.
Add a single-use unsubscribe capability scoped to the subscription. Save
suppression durably and make retries idempotent. The private lead table
shows pending, confirmed and suppressed states separately. Export only
confirmed unsuppressed subscribers for the chosen campaign. Protect CSV
cells that spreadsheet software could interpret as formulas.
Unsubscribe a fixture address and confirm it disappears from the eligible export. Repeat the unsubscribe link and expect a stable result. An administrator should see why the address is suppressed, while public routes disclose only the action outcome. Test a database failure so the page cannot claim success before the suppression is saved.
Skip targeting rules until this flow works
Leave exit intent, countdowns, A/B assignment and behavioral profiles out. A campaign with no subscribers needs an empty state that explains how to test confirmation. A disabled campaign needs a distinct status. The Tally guide covers broader forms, while the Mailchimp guide covers delivery to a consented list.
Keep the server responsible for ownership
Use Astro server rendering with ordinary forms, HTMX for partial updates, and Alpine for local preview state. A Node.js server and SQLite are enough for the first deployment. Use a single persistent disk with backups. If your hosting platform cannot keep a local database across deployments, choose a managed relational database before adding real records.
Put the authenticated account id in server session state. Never trust a hidden owner field submitted by a form. Every lookup should constrain the record by both its id and its account. A record that exists for another account should remain inaccessible through exports, detail pages, background jobs and attachment downloads too.
Implement an authenticated Astro application with server-rendered forms.
All reads and mutations enforce account ownership on the server. Add CSRF
protection, bounded inputs and parameterized queries. HTMX responses use
the same authorization as full pages. Keep credentials server-only. Provide
a complete empty state and a separate recoverable database-error state.
Create two test accounts. Save a record under one, then substitute its id in requests from the other. Exercise a normal HTML request and the partial-update endpoint. Both must refuse access. Signing out must invalidate the session rather than only hiding the navigation. Keep sensitive values out of request logs and exception pages.
Make writes safe to retry
A browser can lose the response after a database commit. Refreshing the page or pressing the button again should return the result of that operation. Give important mutations a unique request id and save it with the outcome inside the transaction. Reusing that id with different input should produce a conflict, rather than quietly reusing an unrelated result.
Use revision checks for edits from multiple tabs. The form submits the revision it loaded. A stale revision gets a clear conflict screen that preserves the attempted input. The owner can reload the current record and choose which change to make. Avoid automatically merging fields whose relationship affects a calculation or publication decision.
Add idempotency tokens to important mutations and revision checks to edits.
Persist the request token and state change together. Duplicate identical
requests return the saved outcome. A reused token with different input is
rejected. A stale edit preserves the attempted values and offers reload.
Test a lost response after commit and two concurrent edits.
Check the database after retrying. A reassuring success message is insufficient if duplicate rows remain underneath. Also stop the process during a write in a test database. On restart, the operation should be complete or absent. Document where an external service would require a separate retry policy before introducing one.
Deploy with a restore path
Build the app, run its migrations against an empty staging database, and create the first owner through a private setup route or command. Disable that setup route afterwards. Configure HTTPS, secure session cookies and a persistent volume. Keep the database outside the release directory so replacing application files cannot replace live data.
Make a consistent database backup with the database engine’s supported backup mechanism. Copying an actively written file without understanding its journal mode can produce an incomplete backup. Encrypt backup storage through your hosting provider or an established backup tool, and keep access credentials outside the source repository.
Write deployment instructions for the chosen Node.js host, persistent
SQLite volume, migrations, HTTPS and server secrets. Add a health endpoint
that reports readiness without exposing records. Back up the database and
restore it into an isolated instance. Verify representative records and
permissions after restore. Document rollback with schema compatibility.
After deployment, use the real hostname. Sign in, create a harmless fixture, complete the core workflow, export it and sign out. Check the index and detail view after each change. Then try a missing id, a request with an expired session, and an intentionally unavailable database in staging. Each failure should tell the owner what they can do next.
Keep operational logs small. Record action ids, elapsed time and error categories, while omitting private payloads. Set an explicit retention policy and check disk usage. Before inviting anyone else, restore one backup into a separate environment and confirm that the application starts with the restored data. Save the recovery instructions beside the deployment configuration.