Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.saytics.com/llms.txt

Use this file to discover all available pages before exploring further.

Server-side tracking is ideal for events you can’t trust from the browser — payments, subscription changes, or any action your backend controls. Because these events originate on your server, they can’t be blocked by ad blockers and are less susceptible to data loss from network issues or tab closures.

When to use server-side vs client-side

Choose the right tracking layer for each type of event.
Use server-side forUse client-side for
Purchases and refundsUI interactions
Subscription changesPage views
Backend-triggered workflowsButton clicks
Webhook-driven eventsForm submissions
A common pattern is to track UI interactions client-side and confirm revenue or subscription events server-side, so critical business data is always captured accurately.

Node.js SDK

Install the server-side SDK in your Node.js project.
npm install @saytics/node
Initialize with your secret key. Keep this key out of your frontend code and environment variables that are exposed to the browser.
const Saytics = require('@saytics/node');
const saytics = new Saytics('YOUR_SECRET_KEY');
Once initialized, call saytics.track to record events from your backend.
// Track an event
await saytics.track({
  userId: 'user_456',
  event: 'Subscription Upgraded',
  properties: {
    plan: 'pro',
    mrr: 49.99,
    billing_cycle: 'monthly'
  }
});

HTTP API

If you’re working in a language other than Node.js, or you want to send events directly from a webhook handler, use the HTTP API. Send a POST request to /v1/events with your event payload.
curl -X POST https://api.saytics.com/v1/events \
  -H "Authorization: Bearer YOUR_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "user_456",
    "event": "Subscription Upgraded",
    "properties": {
      "plan": "pro",
      "mrr": 49.99
    },
    "timestamp": "2024-01-15T10:30:00Z"
  }'
The timestamp field is optional. If omitted, Saytics uses the time the request is received. Include it when replaying historical events or processing delayed webhooks.
Use your secret key (not write key) for server-side requests. Never expose your secret key in client-side code.

Batching events

The Node.js SDK automatically queues events and flushes them to Saytics in batches, which reduces network overhead in long-running server processes. In serverless environments (such as AWS Lambda or Vercel Edge Functions), the process may exit before the queue has a chance to flush automatically. Call saytics.flush() explicitly at the end of your handler to ensure all events are sent.
export async function handler(event) {
  await saytics.track({
    userId: event.userId,
    event: 'Order Completed',
    properties: { orderId: event.orderId }
  });

  // Flush before the function exits
  await saytics.flush();
}

Next steps