Identify users from your server

Link a visitor to a user from your backend with a secret identify key when sign-in finishes on the server.

Updated

Some apps finish sign-in on the server: cookie sessions, magic links, OAuth callbacks or webhooks. In that case you can tell Boostra who the visitor is from your backend, with no browser code.

Create an identify key#

  1. Open your project and go to Settings.
  2. In the Advanced card, find Identify from your server.
  3. Click Generate key. The key starts with bsk_.
  4. Copy it right away: "Copy it now. It is shown once." Store it in your server's secrets, never in browser code.

If the key leaks, click Rotate key in the same place. The old key stops working and you get a new one.

Send the request#

The endpoint sits next to the ingest endpoint in your snippet: take the data-endpoint value and replace analytics-ingest with analytics-identify. The settings card shows the full URL in its code examples.

POST <data-endpoint host>/functions/v1/analytics-identify
Authorization: Bearer bsk_...
Content-Type: application/json
{ "visitorId": "<value of the _boostra_vid cookie>", "userId": "<stable id>", "email": "<optional>" }
  • visitorId is the value of the _boostra_vid cookie the tracker sets on your domain. Read it from the incoming request.
  • userId, email and traits follow the same rules as the browser identify call.
  • You can also send the key in an x-boostra-key header instead of Authorization.
  • The endpoint does not accept browser requests (no CORS). Call it from your server only.

Example: Express#

app.post("/login", async (req, res) => {
  const user = await signIn(req.body);
  const visitorId = req.cookies._boostra_vid;
  if (visitorId) {
    fetch(process.env.BOOSTRA_IDENTIFY_URL, {
      method: "POST",
      headers: { "content-type": "application/json", authorization: `Bearer ${process.env.BOOSTRA_IDENTIFY_KEY}` },
      body: JSON.stringify({ visitorId, userId: user.id, email: user.email }),
    }).catch(() => {});
  }
  res.json({ ok: true });
});

The settings card has ready-made recipes for Express, Next.js middleware, Supabase Edge Function and Laravel, with your endpoint filled in. Click Copy code on the one you need. If your framework encrypts cookies (Laravel does), exclude _boostra_vid from encryption so your code can read it.

Fire the request without waiting for it, as in the example, so a slow response never delays your login.

Related articles