Official SDKs

Single-file SDKs for TypeScript, JavaScript, and Python. Download one file and start tracking events in 30 seconds.

Installation

Download the SDK file and add it to your project. No npm, no pip required.

# TypeScript/JavaScript
curl -o lib/serla.ts https://serla.dev/sdk/serla.ts
# or
curl -o lib/serla.js https://serla.dev/sdk/serla.js

# Python
curl -o serla.py https://serla.dev/sdk/serla.py
pip install requests  # Only dependency

Quick Start

import { Serla } from './lib/serla';

const serla = new Serla('sk_live_YOUR_API_KEY');

// Track events
await serla.send('user_signup', { plan: 'pro' });
await serla.send('button_click', { button: 'checkout' });

// Identify users
serla.identify('user_123');
await serla.send('page_view');  // Now includes userId

API Reference

Initialize

new Serla(apiKey, options?)

const serla = new Serla('sk_live_YOUR_API_KEY', {
  debug: true  // Optional: log events to console
});

send(eventName, metadata?)

Track an event with optional metadata.

await serla.send('purchase_completed', {
  amount: 99.99,
  currency: 'USD',
  product: 'Pro Plan'
});

identify(userId)

Set user ID for all subsequent events.

serla.identify('user_12345');
await serla.send('page_view');  // Includes userId

serla.identify(null);  // Clear user ID

setSession(sessionId)

Set session ID for analytics tracking.

serla.setSession('sess_abc123');
await serla.send('page_view');  // Includes sessionId

Framework Examples

Next.js

import { Serla } from '@/lib/serla';

const serla = new Serla(process.env.SERLA_API_KEY!);

export async function POST(request: Request) {
  const { email, plan } = await request.json();

  await serla.send('user_signup', { email, plan });

  return Response.json({ success: true });
}

Express

const { Serla } = require('./lib/serla');
const serla = new Serla('sk_live_YOUR_API_KEY');

app.post('/api/signup', async (req, res) => {
  const { email, plan } = req.body;

  await serla.send('user_signup', { email, plan });

  res.json({ success: true });
});

Flask

from flask import Flask, request, jsonify
from serla import Serla

serla = Serla('sk_live_YOUR_API_KEY')

@app.route('/api/signup', methods=['POST'])
def signup():
    data = request.json
    serla.send('user_signup', data)
    return jsonify({'success': True})

Automatic Enrichment

All events are automatically enriched with additional data:

  • Geographic: Country, city, timezone from IP
  • Device: Browser, OS, device type from User-Agent
  • UTM: Campaign tracking from URL parameters
  • Session: Referrer, bounce rate, page views