Readers subscribe to your newsletter through a form. Each campaign has one signup form, and you can use it in three ways. Open the Forms section of your dashboard (select your campaign first if you have several) to get the snippet or the links, which are unique to your campaign.
| Method | What you do | Who designs the form |
|---|---|---|
| Embed on your site | Paste a snippet in your pages | Hakanai |
| Hosted page | Share a link | Hakanai |
| Your own form | Write an HTML form or call the API | You |
Every subscriber confirms their address by email before receiving the first issue, see double opt-in.
For the embed and the hosted page, the Forms section lets you change:
http:// or https://).A text left empty uses the default text, shown as a placeholder in the field. A live preview shows the result as you type, and the changes apply after you click Save changes.
Paste this snippet where the form should appear, replacing YOUR_CAMPAIGN_ID with the id of your campaign (the dashboard gives you the snippet ready to copy):
<div data-hakanai-form="YOUR_CAMPAIGN_ID"></div>
<script src="https://broadcast.hakanai.io/embed.js" async></script>
The script is a single file without dependency, about 10 kB, 4 kB compressed. It reads your form settings, draws the form in place of the div, and sends the signup from the reader's browser. You can put several forms in the same page, and forms added to the page after it loaded are picked up as well.
The form is drawn inside a shadow DOM, so the CSS of your site does not change it and its CSS does not leak into your page. It follows the light or dark mode of the reader's system. To force one, add data-theme="light" or data-theme="dark" to the div:
<div data-hakanai-form="YOUR_CAMPAIGN_ID" data-theme="dark"></div>
If the settings cannot be loaded (wrong id, network error), nothing is displayed and a warning is written to the browser console.
The hosted page is a signup page served by Hakanai, with the same form as the embed:
https://broadcast.hakanai.io/campaign/YOUR_CAMPAIGN_ID/subscribe
Link to it from your site, your social profiles or anywhere else. When the address is passed in the URL (?email=...), the page subscribes that address directly instead of showing the form. This is what plain HTML forms use, see below.
If you want full control over the design, build the form yourself. The dashboard gives you two URLs.
Use it as the action of a plain HTML form, with method="POST". The URL belongs to Hakanai and does not change, even if your campaign later moves to a verified custom sending domain, so a form pasted once keeps working.
<form action="https://broadcast.hakanai.io/f/YOUR_CAMPAIGN_ID" method="POST">
<input type="email" name="email" placeholder="you@example.com" required>
<input type="text" name="first_name" placeholder="First name">
<input type="text" name="website" style="display:none" tabindex="-1" autocomplete="off">
<button type="submit">Subscribe</button>
</form>
email is required.first_name is optional. Add it only if you turned on the first name field.website is a hidden spam trap that must stay empty. Keep it hidden: signups where it is filled are treated as spam.When the form is submitted, the browser is redirected to the current signup form of the campaign and the reader sees the confirmation page. If the campaign cannot receive signups there yet, the reader lands on the hosted page, which subscribes the address. Opening the URL in a browser (a GET request) redirects to the hosted page.
This URL is meant for HTML form posts. To send the signup from JavaScript and keep the reader on your site, use the API URL or the JSON endpoint below. Forms that already point to the URLs below keep working.
To keep the reader on your website, send the signup with JavaScript. The endpoint accepts GET and POST, as long as the address is passed in the query string:
<form id="newsletterHakanai">
<input type="email" name="email" placeholder="you@example.com" required>
<button type="submit">Subscribe</button>
</form>
<script>
document.getElementById('newsletterHakanai').addEventListener('submit', function (event) {
event.preventDefault()
var email = this.elements.email.value
fetch('https://broadcast.hakanai.io/api/campaign/YOUR_CAMPAIGN_ID/subscribe?email=' + encodeURIComponent(email), {
method: 'POST'
})
.then(function (response) { return response.json() })
.then(function (data) { console.log('Success:', data) })
.catch(function (error) { console.error('Error:', error) })
})
</script>
| Status | Meaning |
|---|---|
200 | The subscriber has been registered. A confirmation email is sent. |
400 | The email parameter is missing or invalid, or the address is already subscribed to this campaign. |
404 | No campaign matches the id in the URL. |
The embed posts to a JSON endpoint, which you can also call from your own code. The URL is returned by the public settings of your form:
GET https://broadcast.hakanai.io/api/public/campaign/YOUR_CAMPAIGN_ID/form
The answer contains postUrl, the address to post to. Use it for JSON calls rather than the form action URL above, which is made for HTML form posts. Send a POST request with Content-Type: application/json and Accept: application/json:
{ "email": "reader@example.com", "first_name": "Sam", "website": "" }
first_name is optional. website is a hidden field meant to stay empty: signups where it is filled are treated as spam, so do not display it to readers. A successful signup answers 200 with { "ok": true, "pending": true, "message": "..." }. Errors answer 400 or 429 (more than 5 attempts per minute from the same address) with { "ok": false, "message": "..." }. These endpoints accept requests from any website.
While the sending domain of a campaign is not verified yet, postUrl is null and the embed falls back to the API URL above.