Skip to Content
🚀 We just launched! Please star us on Github!

API

Track events from server-side applications, mobile apps, or any platform using the HTTP API with authentication.

Overview

The /api/track endpoint accepts tracking requests with API key authentication, bypassing domain validation. This enables server-side tracking, mobile app analytics, and programmatic event collection.

Data Enrichment

  • Geolocation: IP addresses are resolved to country, region, city, and coordinates using MaxMind GeoLite2 database
  • Device Info: User agent strings are parsed to extract browser, operating system, and device type information

Steps

Generate API Key

In your site dashboard: Settings → API Key tab → Generate API Key

Include in Requests

curl -X POST 'https://app.rybbit.io/api/track' \ -H 'Content-Type: application/json' \ -d '{ "api_key": "rb_your_api_key_here", "site_id": "123", "type": "pageview", "pathname": "/api/users", "hostname": "api.example.com", "page_title": "User API Endpoint", "user_agent": "MyApp/1.0 (Linux; x64)", "ip_address": "192.168.1.1" }'

Parameters

ParameterTypeRequiredDescription
api_keystringRequiredYour generated API key (starts with rb_)
site_idstringRequiredYour site ID
typestringOptionalEvent type: pageview or custom_event (defaults to pageview)
pathnamestringOptionalPage path
hostnamestringOptionalDomain name
page_titlestringOptionalPage title (max 512 chars)
referrerstringOptionalReferrer URL (max 2048 chars)
user_idstringOptionalCustom user identifier (max 255 chars)
user_agentstringOptionalCustom user agent string (max 512 chars) - will be parsed for browser/OS/device info
ip_addressstringOptionalCustom IP for geolocation - will be resolved to location data
querystringstringOptionalQuery parameters
languagestringOptionalLanguage code (e.g., “en”)
screenWidthnumberOptionalScreen width in logical pixels (density-independent pixels)
screenHeightnumberOptionalScreen height in logical pixels (density-independent pixels)
event_namestringCustom events onlyEvent name (required for custom events, max 256 chars)
propertiesstringCustom events onlyJSON string with event data (max 2048 chars)

Language Examples

const trackEvent = async (eventData) => { const response = await fetch('https://app.rybbit.io/api/track', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ api_key: process.env.RYBBIT_API_KEY, site_id: process.env.RYBBIT_SITE_ID, ...eventData }) }); return response.json(); }; // Track a pageview await trackEvent({ type: 'pageview', pathname: '/api/users', hostname: 'api.example.com' }); // Track a custom event await trackEvent({ type: 'custom_event', pathname: '/checkout', event_name: 'purchase', properties: JSON.stringify({ amount: 99.99, currency: 'USD' }) });

Response Format

Success Response

{ "success": true }

Error Response

{ "success": false, "error": "Invalid API key", "details": { "fieldErrors": {}, "formErrors": ["Custom events require event_name"] } }

Rate Limiting

API key authenticated requests are rate limited to 20 requests per second per API key on Rybbit Cloud. Self-hosted instances have no rate limits.

When you exceed the rate limit, you’ll receive a 429 status code:

{ "success": false, "error": "Rate limit exceeded. Maximum 20 requests per second per API key." }

Best Practices

Environment Variables: Store your API key and site ID as environment variables to keep them secure.

đźš«

API Key Security: Never expose API keys in client-side code or public repositories.

Error Handling

Common error scenarios:

  • Invalid API key: Check that your API key starts with rb_ and hasn’t been revoked
  • Site not found: Verify your site ID is correct
  • Invalid payload: Ensure required fields are present and data types match
  • JSON parsing errors: For custom events, ensure properties field contains valid JSON
  • Rate limit exceeded: Reduce request frequency or implement request queuing with delays
Last updated on
Rybbit
Copyright 2025 © Rybbit.