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#
- Open your project and go to Settings.
- In the Advanced card, find Identify from your server.
- Click Generate key. The key starts with
bsk_. - 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>" }visitorIdis the value of the_boostra_vidcookie the tracker sets on your domain. Read it from the incoming request.userId,emailandtraitsfollow the same rules as the browser identify call.- You can also send the key in an
x-boostra-keyheader instead ofAuthorization. - 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
-
Identify signed-in users
Call identify after sign-in and reset on sign-out so visits, funnels and revenue are tied to real users.
Read article -
The window.boostra JavaScript API
Every command the tracking snippet exposes on window.boostra, with signatures and examples.
Read article -
Cookies and browser storage
The first-party cookies and storage keys the Boostra tracker sets on your site, and what each one is for.
Read article