Kelp email capture
Subscribe and unsubscribe contacts with createKelpEmail - capture only, not campaigns or automated flows.
Kelp email capture records opt-in and opt-out. createKelpEmail emits email_subscribed and email_unsubscribed on the same events host as analytics. This is capture only - it does not send campaigns or run flows.
Hosts and keys: Get your keys.
Setup
Pass your createAnalytics instance as tracker so email and analytics share one buffer.
import { createKelpClient, createIdentity, createAnalytics } from '@kelpclick/client';
import { createKelpEmail } from '@kelpclick/client/email';
const kelp = createKelpClient({
searchUrl: 'https://{TENANT_ID}-search.kelp.click',
analyticsUrl: 'https://{TENANT_ID}-events.kelp.click',
apiKey: process.env.KELP_API_KEY!,
});
const identity = createIdentity();
const analytics = createAnalytics({ client: kelp, identity });
const email = createKelpEmail({ identity, tracker: analytics });subscribe and unsubscribe
subscribe calls identity.identify({ email }) and emits email_subscribed. unsubscribe emits email_unsubscribed and does not reset identity.
Both helpers accept a nested Email object (or a flat address string, which maps to { email } only). On the object form, source is optional (capture point, e.g. 'footer-form'). Put other extras in meta (or event metadata).
email.subscribe({
email: 'shopper@example.com',
source: 'footer-form',
listId: 'newsletter',
details: { firstName: 'Sam', lastName: 'Shopper' },
meta: { formId: 'footer-form' },
});
// Flat string still works - mapped to { email } only
email.subscribe('shopper@example.com');
email.unsubscribe({
email: 'shopper@example.com',
listId: 'newsletter',
});flush() posts the buffer now. close() flushes and stops the interval.
You can also POST email_subscribed / email_unsubscribed directly to the events API.
Event fields (nested Email)
On the wire, email kinds carry a nested Email DTO - not flat root email / source / listId.
| Field | Notes |
|---|---|
email | Required address when the object is present |
source | Optional capture point, e.g. 'footer-form' (object form only) |
listId | Optional target list |
campaignId | Optional campaign id (reserved open/click kinds) |
details | Optional person fields: name, firstName, lastName, phone |
meta | Optional email-scoped JSON overflow (separate from event metadata) |
email_opened and email_clicked are reserved kinds and are not emitted by the client yet.
See Events for the full Email / Attribution / purchase field reference, and Identity.