Skip to content

How to send signals

A signal is one thing that happened in your product: an event, about one person (an end user) at one of your customers (an account). Keepem reads signals to see who is onboarding, who has gone quiet and who needs a nudge. Your product is a tenant with its own API key, and Keepem creates an account or an end user the first time a signal names them.

Everything arrives through one front door, POST /api/public/ingest. The browser snippet posts to it, and your own server can too. Billing events come in through your tenant's Stripe webhook and are stored the same way, beside your product's signals.

The front door

Post each signal as JSON to https://keepem.club/api/public/ingest, with your tenant's key as api_key:

curl -X POST https://keepem.club/api/public/ingest \
  -H "Content-Type: application/json" \
  -d '{
    "api_key": "lh_…",
    "external_user_id": "user-123",
    "external_account_id": "account-456",
    "event_name": "quote_saved",
    "properties": { "quote_id": "q-789" },
    "identity": { "name": "Dana Smith", "email": "dana@example.com", "role": "owner" },
    "account": { "name": "Example Co", "plan": "pro" }
  }'

A 200 answer carries the stored event's id. The key only adds signals to your tenant, so it is safe in a browser.

The body

A JSON object of at most 64 KB. Any content type is read as JSON, so a text/plain beacon works. Unknown fields are ignored. A missing field, null and a blank string all mean "not sent", and a value that isn't sent never overwrites one already stored. Text is trimmed.

Field Needed What it takes What happens
api_key yes lh_ and 32 letters or digits Picks the tenant. Public by design.
external_user_id yes text or a number, 1 to 255 characters Your id for the person. Created the first time it is seen.
external_account_id yes text or a number, 1 to 255 characters Your id for the customer (a restaurant, a shop). Created the first time it is seen.
event_name yes text, 1 to 200 characters See "Naming events" below.
properties no a JSON object, nested up to 32 levels Stored as sent. {} when missing.
occurred_at no ISO 8601 date-time with seconds and a time zone, years 1970 to 9999 Your clock. When missing, the time the signal arrived.
source no any text Kept, lowercased, cut to 32 characters. api when missing. Never an error.
snippet_version no text, up to 50 characters
page_origin no text, up to 2048 characters
identity no { name, email, phone, role }: text up to 500, 320, 50 and 100 characters (phone may be a number) Fills in the end user.
account no { name, plan }: text up to 500 and 200 characters Fills in the account.

One event is stored per signal, on the key's tenant. The account and the end user are found by their ids and created when new, and an end user belongs to the account of their latest signal.

The answers

Status When Body
200 Stored. { "id": "<event id>" }
204 A browser's OPTIONS preflight. none
400 The body isn't a JSON object, is over 64 KB, or a field is missing or can't be stored. { "error": "invalid_body", "details": [{ "field", "message" }] }
401 No api_key, one that isn't the issued shape, or one that is unknown or revoked. Unknown and revoked answer alike. { "error": "invalid_api_key" }, plus details naming api_key when it is missing
429 The tenant is over its limit (600 a minute unless set otherwise, at most 6000), or the call waited over a second for its turn. Nothing is stored. { "error": "rate_limited", "details": { "retry_after_seconds": n } } and a Retry-After header
500 Only if the database call itself fails. No body the contract accepts should get here. { "error": "internal_error" }

Every answer allows any origin (Access-Control-Allow-Origin: *, POST, OPTIONS, content-type, no credentials), and none sets a cookie.

The rate limit

A tenant may send 600 signals a minute, unless Keepem has set another limit for it (never more than 6000). It can send a burst of up to its whole limit at once, then keep to the rate. Past the limit the answer is 429 and nothing is stored: send the signal again after the Retry-After seconds.

The browser snippet

lh.js sends page views, who is signed in and the events you track, straight from the browser. Load it from Keepem, and identify the user before you start it, so the first page view carries them:

<script src="https://keepem.club/api/public/lh.js"></script>
<script>
  // Once the user is signed in:
  LongHaul.identify({
    id: user.id, email: user.email, name: user.name,
    accountId: account.id, accountName: account.name, plan: account.plan,
  });
  LongHaul.init({ key: "lh_…" });
</script>

Signals go to the host the script came from, here https://keepem.club/api/public/ingest; pass endpoint to init() to send them somewhere else. A signal without an end user or an account is refused (400), which is why identify() comes first. The script keeps nothing in cookies or browser storage, and a post that fails is ignored, so your page keeps working.

The script tag can carry the key instead, as data-lh-key="lh_…" (and data-lh-endpoint): the script then calls init() as it loads. That first page view goes out before anyone is identified, so the front door refuses it; call identify() as soon as you know who is signed in.

The calls

  • LongHaul.init({ key, endpoint }) starts sending with your tenant's key. Signals made before it wait, up to 100, and go out now; then it sends a page view. endpoint is optional.
  • LongHaul.identify({ id, email, name, phone, role, accountId, accountName, plan }) says who is signed in and for which account, and sends identified. id (or email, when there is no id) becomes the external_user_id of every later signal and accountId its external_account_id. Those signals also carry name, email, phone and role as identity, and accountName and plan as account. Identify again for the same account without accountName or plan and the earlier ones stay; another accountId starts with neither.
  • LongHaul.track(name, properties) sends an event with your properties.
  • LongHaul.page() sends page_viewed with the page's path, title and referrer. init() sends the first one; in a single-page app, call it on each route change.
  • LongHaul.reset() forgets the user and the account, and drops any signal still waiting. The key stays. Call it from your sign-out handler, so the next person on that browser isn't taken for the last one.
  • LongHaul.version is the script's version. Every signal the snippet sends carries it as snippet_version, with source snippet, page_origin (your page's origin) and occurred_at (the browser's clock).

Clicks

<button data-lh-event="quote_saved" data-lh-prop-quote_id="q-789">Save quote</button>

A click on an element with data-lh-event, or on anything inside it, sends that event. Each data-lh-prop-* attribute becomes a property named after the rest of the attribute, and path is added, so the button above sends quote_saved with { "quote_id": "q-789", "path": "/quotes" } from a page at /quotes. Values are always text. Browsers lowercase attribute names (data-lh-prop-quoteId arrives as quoteid), so use snake_case.

Loading the script

GET /api/public/lh.js may be cached for 5 minutes. After that, a browser that already has this version gets a 304 instead of the file. Any site can load it.

Stripe

Connect the Stripe account that bills your product, and Keepem records its billing events as signals:

  1. In Stripe, add a webhook endpoint at https://keepem.club/api/public/stripe-webhook?tenant=<your tenant's slug>. Your tenant's Setup and Developer Handoff pages show this URL with the slug filled in.
  2. Subscribe it to these five events: invoice.payment_failed, customer.subscription.created, customer.subscription.updated, customer.subscription.deleted and checkout.session.completed.
  3. Copy the endpoint's signing secret (it starts with whsec_) into your tenant's Setup page. An owner or an admin of the tenant saves it there. Keepem keeps it encrypted, and no one can read it back.
  4. Setup shows a command that sends a test event, and each delivery as it arrives.

Keepem records every event the Stripe account sends on your tenant. If the account bills other products too, tag your events first (below).

A Stripe account that bills other products too

Every product an account bills sends its events to every endpoint on the account, so connected as it is, the other products' customers would land on your tenant. To keep only yours:

  1. Put longhaul_tenant in the metadata of your Checkout Sessions and of their subscriptions (subscription_data.metadata), set to your tenant's slug, as in the webhook URL. The invoices and changes that follow carry it too. For a subscription made before you added it, add it to the subscription's metadata in Stripe.
  2. Once your product sends it, an owner or an admin turns on "Record only tagged events" in Setup. Until your product sends the tag, every event is left out.

From then on Keepem records only events tagged with your slug, in any case. Every other event is answered 200 {"outcome": "ignored"}, and nothing from it is stored, not even in the delivery log. An event tagged for another tenant is never recorded on yours, whether the switch is on or off.

What Keepem records

Each of the five becomes a signal named stripe. and its type, such as stripe.invoice.payment_failed, at the time Stripe created the event. Stripe may deliver an event more than once; Keepem records it once. Other event types are answered 200 and ignored.

A billing signal is about the first of these that fits:

  1. The end user metadata.longhaul_user names: your own id for them. It is created if new, in the account metadata.longhaul_account names.
  2. The end user already linked to that Stripe customer.
  3. An end user with the buyer's email who isn't linked to a Stripe customer yet. When the email belongs only to end users linked to another Stripe customer, the event is logged as unmatched and no new end user is made; metadata.longhaul_user avoids that.
  4. A new end user for that email.

An event none of these fits, such as a subscription change for a customer Keepem hasn't linked yet, is logged in Setup as unmatched. Put longhaul_user and longhaul_account in the metadata of your Checkout Sessions and of their subscriptions (subscription_data.metadata), and Keepem never has to guess: the invoices and changes that follow carry them too.

Checkout metadata Keepem reads

Besides longhaul_user and longhaul_account, Keepem reads these keys. Each is optional. Stripe keeps every metadata value as text, and a value that doesn't fit is ignored, never an error: the webhook answers the same either way.

Key Where What it means Accepted
longhaul_welcome a Checkout Session This checkout is a new customer's first purchase: it starts the welcome below. true, in any case, with spaces around it trimmed
seats a Checkout Session, or a subscription The seats the account has bought. When they change, update the subscription's metadata: the newest event wins. The number is also what "near the seat limit" is measured against, so keep it current. a whole number from 1 to 1,000,000, digits only, trimmed
secondary_email a Checkout Session The onboarding contact the buyer named, such as someone in finance or operations. one email address that isn't the buyer's own
longhaul_setup_url a Checkout Session Where the buyer starts setting up. an https link, exactly as sent, of at most 2000 characters, to a public host name on the standard port, with no user name, password, control character or backslash
longhaul_tenant a Checkout Session, or a subscription The tenant this event is for, on a Stripe account that bills other products too (above). An event tagged with another value is not recorded. your tenant's slug, in any case, trimmed
source_campaign_id, utm_campaign, hl_deal_id, hl_product_id a Checkout Session, or a subscription Where the customer came from: the Hard Launch campaign (or, without one, the ad's utm_campaign), the Hard Launch deal this purchase closes, and your product's id in Hard Launch. The earliest checkout or subscription wins for the keys it carries, so a renewal never rewrites them; a later one only adds a missing key. Send the same values on the session and the subscription. The account's page shows them and the Accounts list filters by campaign. text of 1 to 255 characters, trimmed, with no control character

longhaul_setup_url must not sign anyone in. Everyone on your tenant in Keepem can read a checkout's metadata, and so can everyone with access to your Stripe account. Link a page that starts setup, or one that emails the buyer a fresh sign-in link. Keepem never makes, stores or passes on sign-in credentials.

The welcome

Every tenant has a built-in play, "Welcome after purchase", and it is on. It starts when a checkout in payment or subscription mode completes with longhaul_welcome set, once per account: a renewal, an add-on bought through another Checkout, a second flagged checkout or a replayed event starts nothing. Without longhaul_welcome there is no welcome, so customers you had before you set it never get one.

  • As it comes, the welcome is three emails: right away, after three days and after a week. All three go to the buyer, the checkout's own end user. Send longhaul_user and longhaul_account too, so they reach the right person at the right account.
  • The onboarding contact secondary_email names gets every email step of the welcome (as it comes, the same three), each opening with a line saying who added them, and none of its texts, call scripts, follow-ups or webhooks.
  • Your longhaul_setup_url is only in the buyer's first email. Every other email, the contact's first one included, uses your tenant's App link instead (see "Merge fields").
  • As it comes, the later emails stop once the account is activated (your health model's activation steps) or cancels, and never go to an account Keepem made from the checkout alone, which no product activity reaches (send longhaul_account), or to any account while your health model has no activation step.

You can rename the welcome, change its emails, steps and filters, or turn it off, but not delete it. Like every play's messages for now, its emails are written out and held, not sent (see "Merge fields"). The default play "Never activated 3 days: onboarding nudge" starts off; turned on, it nudges the same new customers again, so don't run both for accounts that a flagged checkout welcomes.

The webhook's answers

Status When Body
200 A verified event. { "outcome": "recorded", "id": "<event id>" }, or the outcome duplicate, unmatched or ignored (a type Keepem doesn't record, or another product's event)
400 The tenant in the URL doesn't exist, it has no secret saved, or the signature doesn't match it: one answer for all three. Or a correctly signed body that isn't a Stripe event. { "error": "invalid_signature", "details": "…" } or { "error": "invalid_event", "details": "…" }
413 The body is over 1 MB. { "error": "payload_too_large" }
500 The database failed. Stripe tries again. { "error": "internal_error" }

CSV import

Setup's "Import customers (CSV)" card is where a tenant's owners and admins bring in the customers the product already has, before their first signal: a CSV with the columns email, name, account and external id, each row an end user and their account, created straight away. The columns can have any names and come in any order: the card shows the first rows and you say which column is which (email is required). Up to 10 MB, with commas, semicolons, tabs or pipes, and with or without a header row.

  • Who a row is. A row needs an email or an external id. With an external id, it is the end user with that external_user_id, created with it if new, so use the id your product sends as external_user_id, not a CRM's or Stripe's own id: an external id never falls back to the email. Without one, it is the end user with that email, in any case, created with the lowercased email as their external_user_id.
  • Which account. The account whose name matches the account column (any case, and spacing aside), else the one whose external_account_id is that value, else a new account with that name. A new account made this way gets an id of Keepem's own: when your product later sends its own external_account_id for that customer, Keepem makes a second account, and each person moves to it with their next signal. Accounts your product has already sent are matched, by name or by id. A new person with no account in the file gets one of their own.
  • People already in Keepem take the file's email, name and account where they differ. Importing the same file again changes nothing.
  • Rejected rows (no email and no external id, a malformed email, or a value longer than the front door takes) come back as a file of those rows with the reason for each. Fix them and import that file.
  • Each new person gets an end_user_imported event with source csv, which Developer Handoff's live panel shows. It doesn't count as product activity in account health, nor as the tenant's last signal.

Naming events

  • Lowercase object_verb, with the words joined by underscores: quote_saved, module_completed, user_invited.
  • Past tense: the event has already happened when you send it.
  • Keep a name stable and put what varies in properties: module_completed with { "module": "food-safety" }, not food_safety_module_completed.
  • identified and page_viewed are Keepem's own names. The snippet sends them, and a server may send them too.
  • Names starting stripe. belong to the Stripe webhook: stripe.invoice.payment_failed, stripe.customer.subscription.deleted. Don't send them from your product. They would be stored, but only the webhook's count as billing.
  • The events that matter most are your health model's milestones. Add them on your tenant's Health model page, and Developer Handoff lists them as expected events, with when each last arrived.

Merge fields

Plays nudge an account when its health moves (it goes quiet, a payment fails, it hasn't activated after a few days) or when it sends a given event: by email, by text, with a call script or a follow-up for your team, or with a webhook. Their templates take these merge fields:

{{first_name}}  {{name}}  {{email}}
{{account_name}}  {{tenant_name}}
{{sender_name}}  {{event_date}}  {{setup_url}}

The person is the account's most recently seen end user with an email address (failing that, its most recently seen one). An onboarding contact named at checkout who has no activity of their own in your product is chosen only when nobody else is on the account. A welcome run writes to the buyer and, separately, to the onboarding contact (see "The welcome" under Stripe). {{first_name}} is the first word of the person's name. {{account_name}} falls back to the account's external ID, {{sender_name}} to the tenant's name, and {{event_date}} is the day the play's trigger happened (today, in a preview). {{setup_url}} is your tenant's App link (Settings, Email branding), except in the buyer's first welcome email, where it is the checkout's longhaul_setup_url when that is a link Keepem accepts; previews and test sends use the App link. A field Keepem doesn't know is refused when the template is saved; a field with no value for an account comes out empty. Every email ends with an unsubscribe link, and every text with "Reply STOP to opt out."

Keepem doesn't send anything from plays yet. Each email and text is written out in full and kept with the play, where you can read it, and a test you send yourself is kept the same way.

Developer Handoff

Every tenant has a Developer Handoff page with all of this filled in for it: the ingest address, its active keys, a server example and the snippet, the events it expects with when each last arrived, its Stripe webhook URL and events, and its last 10 signals as they land, with a button that sends a test signal. Sign in, open the tenant, then Developer handoff. It shows only the first characters of each key: the full key is shown once, when an owner or an admin creates it in Settings.