Revenue Tracking

Track, analyze, and visualize revenue data from your events with built-in revenue metrics.

How Revenue Tracking Works

Serla automatically extracts and indexes revenue data from your events. Simply include monetary values in your event metadata, and Serla will make it queryable for analytics, reporting, and dashboards.

Tracking Revenue Events

Send revenue data by including amount and currency in your event metadata:

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

const serla = new Serla('YOUR_API_KEY');

// Identify user
serla.identify('user_123');

// Track purchase with revenue
await serla.send('purchase_completed', {
  amount: 29.99,
  currency: 'USD',
  plan: 'pro',
  billing_cycle: 'monthly'
});

Serla automatically detects revenue properties and extracts them to the revenueAmount and revenueCurrency fields for fast querying.

Revenue Event Examples

Subscription Purchase

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

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

await serla.send('subscription_created', {
  amount: 29.99,
  currency: 'USD',
  plan: 'pro',
  billing_cycle: 'monthly',
  trial_days: 0
});

One-time Purchase

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

const serla = new Serla(process.env.SERLA_API_KEY);
serla.identify(user.id);

await serla.send('purchase_completed', {
  amount: 99.00,
  currency: 'USD',
  product_id: 'prod_abc123',
  quantity: 1,
  payment_method: 'card'
});

Refund

serla.identify(user.id);

await serla.send('refund_processed', {
  amount: -29.99,  // Negative for refunds
  currency: 'USD',
  reason: 'customer_request',
  original_order_id: 'ord_xyz789'
});

Querying Revenue Data

Get total revenue for a specific time period:

curl -X GET "https://serla.dev/api/analytics/revenue?projectId=proj_123&startDate=2025-01-01&endDate=2025-01-31" \
  -H "Authorization: Bearer YOUR_API_KEY"

Revenue Dashboard

The Revenue dashboard (Dashboard → Revenue) provides real-time revenue analytics:

  • Total Revenue: Sum of all revenue events for the selected time period
  • Revenue Trend: Time-series chart showing daily/weekly/monthly revenue trends
  • Top Revenue Events: Breakdown by event type (subscriptions, purchases, upgrades)

Common Revenue Metrics

Monthly Recurring Revenue (MRR)

  • Type: Sum
  • Event Names: subscription_created, subscription_renewed
  • Property Path: metadata.amount
  • Filters: metadata.billing_cycle = "monthly"

Average Revenue Per User (ARPU)

  • Type: Ratio
  • Numerator: Sum of all revenue events (metadata.amount)
  • Denominator: Unique count of userId

Customer Lifetime Value (LTV)

  • Type: Sum
  • Event Names: All revenue events
  • Property Path: metadata.amount
  • Group By: userId (to see per-user LTV)

Multi-currency Support

Serla stores currency alongside revenue amounts. When querying, you can:

  • Filter by specific currency (?currency=USD)
  • View revenue segmented by currency
  • Convert currencies in your application logic before tracking

Note: Serla does not perform automatic currency conversion. If you track revenue in multiple currencies, convert to a base currency in your application before sending events.

Best Practices

  • Always include currency: Even if you only use USD, include it for future flexibility
  • Use consistent amount format: Store in smallest currency unit (cents) or as decimal (29.99)
  • Track all revenue events: Subscriptions, one-time purchases, upgrades, downgrades, refunds
  • Include context: Add plan, billing cycle, payment method for better analytics
  • Use negative amounts for refunds: Makes it easy to calculate net revenue

Common Revenue Events

  • subscription_created - New subscription started
  • subscription_renewed - Recurring subscription payment
  • subscription_upgraded - Customer upgraded to higher tier
  • subscription_downgraded - Customer downgraded to lower tier
  • purchase_completed - One-time purchase
  • refund_processed - Refund issued (use negative amount)
  • chargeback_received - Payment disputed (use negative amount)

Pro Tip: Combine revenue tracking with conversion funnels to understand which marketing channels and user paths drive the most revenue. Create custom metrics for MRR, churn, and LTV to track business health over time.