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
Pageview
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
Parameter | Type | Required | Description |
---|---|---|---|
api_key | string | Required | Your generated API key (starts with rb_ ) |
site_id | string | Required | Your site ID |
type | string | Optional | Event type: pageview or custom_event (defaults to pageview ) |
pathname | string | Optional | Page path |
hostname | string | Optional | Domain name |
page_title | string | Optional | Page title (max 512 chars) |
referrer | string | Optional | Referrer URL (max 2048 chars) |
user_id | string | Optional | Custom user identifier (max 255 chars) |
user_agent | string | Optional | Custom user agent string (max 512 chars) - will be parsed for browser/OS/device info |
ip_address | string | Optional | Custom IP for geolocation - will be resolved to location data |
querystring | string | Optional | Query parameters |
language | string | Optional | Language code (e.g., “en”) |
screenWidth | number | Optional | Screen width in logical pixels (density-independent pixels) |
screenHeight | number | Optional | Screen height in logical pixels (density-independent pixels) |
event_name | string | Custom events only | Event name (required for custom events, max 256 chars) |
properties | string | Custom events only | JSON string with event data (max 2048 chars) |
Language Examples
Node.js
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