Add a newsletter signup to your Astro site
Drop one Astro component into any page to collect double-opt-in newsletter subscribers and lead metadata — no backend, no build plugin, no ESP.
1 · Drop in the component
Create a free account, copy your publishable key from the portal, and paste it where you see pk_live_YOUR_KEY below. The key is safe in client-side code.
<form id="ec-form">
<input type="email" name="email" placeholder="you@example.com" required />
<button type="submit">Subscribe</button>
<p id="ec-msg" role="status" aria-live="polite"></p>
</form>
<script>
const form = document.getElementById('ec-form');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const msg = document.getElementById('ec-msg');
try {
const res = await fetch('https://api.ec.emcognito.com/subscribe', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Publishable-Key': 'pk_live_YOUR_KEY',
},
body: JSON.stringify({
email: form.email.value,
// Optional: provider, spend_band, region, workload, notes
}),
});
if (!res.ok) throw new Error(await res.text());
msg.textContent = 'Check your inbox to confirm your subscription.';
form.reset();
} catch {
msg.textContent = 'Something went wrong — please try again.';
}
});
</script>2 · Subscribers confirm by email
emcognito sends a confirmation email automatically — double opt-in is on by default. The address is recorded as pending and only joins your verified list after the person clicks the link. Bounces and complaints are suppressed for you.
3 · Use your list anywhere
Verified subscribers appear in your owner portal (search, filter, CSV export). Read them server-side with a secret key over GET /v1/subscribers, or get a signed webhook the moment someone confirms — so new subscribers flow straight into your stack. You own the list; emcognito is the collection layer, not an ESP.
FAQ
Does this work with a statically built Astro site?
Yes. The publishable key is safe in client-side code, so the form posts directly to emcognito from the browser — no SSR adapter or server route required. If you prefer to keep the key server-side, Astro API endpoints work too (see the full docs).
Do subscribers get a confirmation email?
Yes — double opt-in is on by default. The subscriber is recorded as pending and only added to your verified list after they click the confirmation link emcognito sends.
