Backend and server events
Events from your server that nothing can block
Some events happen where no browser can see them: a payment webhook, a sign-up your backend finishes, a renewal from a nightly job, an action in a CLI. Send them from your server with a secret key, so an ad blocker or a closed tab never loses them, and they land in the same reports as your page views.
Who it's for
Backend developers, and any team whose key actions happen on a server, in a worker or behind an API.
What you get
| Feature | What it does | Guide |
|---|---|---|
@viakite/node | Batches, retries with backoff, flush and shutdown, for Node.js 18 and later | Node.js |
| The events endpoint | Plain JSON over HTTP from any language | Server-side events |
| Event ids | A retry is stored once | Retries never count twice |
| The visitor's address and user agent | Server events tied to the visitor and their source | Who the visitor is |
| Revenue and identify | Payments and user traits from your backend | Revenue, Identify users |
Set it up
Create a secret key
In Settings → API keys, choose New key, pick only the
analytics.sendscope, and limit it to the project. Copy the Project ID (prj_…) from Settings → General. Keep the key in your server's environment asVIAKITE_SECRET_KEY.Send events
src/viakite.ts1import { Viakite } from "@viakite/node";23export const viakite = new Viakite({4secretKey: process.env.VIAKITE_SECRET_KEY!,5project: "prj_…",6});78// In a request handler:9viakite.track("Signup", { method: "google" }, {10userId: user.id,11ip: req.ip,12userAgent: req.headers["user-agent"],13});1415// In a payment webhook, with the payment's id so a retry counts once:16viakite.track("Purchase", { revenue: 499, currency: "INR", plan: "pro" }, { id: payment.id, userId: user.id });terminal1curl https://us.e.vk.viabio.me/v1/events \2-H "Authorization: Bearer $VIAKITE_SECRET_KEY" \3-H "Content-Type: application/json" \4-d '{5"type": "event",6"id": "pay_01JD8X2M4N5P6Q7R8S",7"project": "prj_…",8"name": "Purchase",9"user_id": "user_8231",10"props": { "revenue": 499, "currency": "INR", "plan": "pro" }11}'The answer is
202with{ "accepted": 1, "dropped": 0 }. A list of up to 100 events goes in one request.Send what waits before you exit
@viakite/nodesends when 20 events wait, every 10 seconds, and onflush(). Callshutdown()before the process exits, andflush()before a serverless function returns:src/server.ts1process.on("SIGTERM", async () => {2await viakite.shutdown();3process.exit(0);4});Identify from the server
ts1viakite.identify("user_8231", { plan: "pro", company: "Acme" });Over HTTP, send
"type": "identify"with auser_idandtraits.
What to watch
- No location. Server events have no country or city: the edge in front of a browser gives those, and your server's would be wrong.
- One visitor without the request. Without
ipand user agent, events with auser_idcount that user as one visitor for the day; events with none of the three all count as your server, one visitor a day. - Duplicates. A repeated
idis caught for 10 minutes on the server that got it; a much later retry can still count twice. - Plan limits. Events past your plan's limit or a spend cap are answered
202and counted as dropped. Don't retry them. Sending events isn't counted against the API rate limit.
Go: not published yet
The Go SDK is built, but its module isn't public yet, so go get github.com/viakite/viakite-go doesn't work today. From Go, post to the events endpoint over HTTP as above.