Complete REST API and WebSocket documentation for LiveWebTraffic.
https://livewebtraffic.com/api
Currently, LiveWebTraffic does not require authentication for public endpoints. Your tracking code serves as your site identifier.
Register a new website and receive a unique tracking code.
| Parameter | Type | Required | Description |
|---|---|---|---|
url |
String | Yes | Your website URL |
email |
String | No | Contact email (optional) |
fetch('https://livewebtraffic.com/api/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
url: 'https://mywebsite.com',
email: 'contact@mywebsite.com'
})
})
.then(res => res.json())
.then(data => console.log(data));
{
"success": true,
"trackingCode": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"url": "https://mywebsite.com",
"scriptTag": "<script src=\"https://livewebtraffic.com/dist/widget.bundle.js\"></script>..."
}
{
"success": false,
"error": "URL is required"
}
Retrieve visitor history for a specific tracking code.
| Parameter | Type | Description |
|---|---|---|
trackingCode |
String | Your unique tracking code |
fetch('https://livewebtraffic.com/api/history/a1b2c3d4-e5f6-7890-abcd-ef1234567890')
.then(res => res.json())
.then(data => console.log(data));
{
"hits": [
{
"ts": 1703529600000,
"ip": "192.168.1.1",
"city": "New York",
"country": "US",
"lat": 40.7128,
"lon": -74.0060,
"referrer": "google.com",
"path": "/",
"ua": "Mozilla/5.0..."
}
]
}
Retrieve all visitor history across all sites (admin only - future feature).
fetch('https://livewebtraffic.com/api/history')
.then(res => res.json())
.then(data => console.log(data));
{
"hits": [
{
"trackingCode": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"ts": 1703529600000,
"ip": "192.168.1.1",
"city": "New York",
"country": "US"
}
]
}
Connect to real-time visitor stream using WebSocket.
wss://livewebtraffic.com?code=YOUR_TRACKING_CODE
| Parameter | Type | Required | Description |
|---|---|---|---|
code |
String | Yes | Your tracking code (filters events to your site only) |
const ws = new WebSocket('wss://livewebtraffic.com?code=a1b2c3d4-e5f6-7890-abcd-ef1234567890');
ws.onopen = () => {
console.log('Connected to LiveWebTraffic');
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received:', data);
};
ws.onerror = (error) => {
console.error('WebSocket error:', error);
};
ws.onclose = () => {
console.log('Disconnected');
};
Sent immediately after connection with recent visitor history.
{
"type": "welcome",
"history": [
{
"ts": 1703529600000,
"city": "New York",
"country": "US",
"referrer": "google.com"
}
]
}
Sent when a new visitor arrives on your website.
{
"type": "hit",
"ts": 1703529600000,
"ip": "192.168.1.1",
"city": "London",
"country": "GB",
"lat": 51.5074,
"lon": -0.1278,
"referrer": "twitter.com",
"path": "/pricing",
"ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0"
}
Sent when an error occurs.
{
"type": "error",
"message": "Invalid tracking code"
}
Initialize the LiveWebTraffic widget on your website.
| Option | Type | Default | Description |
|---|---|---|---|
trackingCode |
String | Required | Your unique tracking code |
ws |
String | Required | WebSocket server URL |
containerId |
String | null | Custom container element ID |
position |
String | 'bottom-right' | Widget position: 'bottom-right', 'bottom-left', 'top-right', 'top-left' |
theme |
String | 'light' | Theme: 'light' or 'dark' |
// Basic initialization
LiveWidget.init({
trackingCode: 'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
ws: 'wss://livewebtraffic.com'
});
// Custom container
LiveWidget.init({
trackingCode: 'your-code',
ws: 'wss://livewebtraffic.com',
containerId: 'my-widget-container'
});
// Dark theme, top-left position
LiveWidget.init({
trackingCode: 'your-code',
ws: 'wss://livewebtraffic.com',
position: 'top-left',
theme: 'dark'
});
Structure of visitor data returned in API responses and WebSocket messages:
| Field | Type | Description | Example |
|---|---|---|---|
ts |
Number | Unix timestamp (milliseconds) | 1703529600000 |
ip |
String | Visitor IP address (anonymized) | "192.168.1.1" |
city |
String | City name | "New York" |
country |
String | ISO country code | "US" |
lat |
Number | Latitude coordinate | 40.7128 |
lon |
Number | Longitude coordinate | -74.0060 |
referrer |
String | Referring website | "google.com" |
path |
String | Page path visited | "/pricing" |
ua |
String | User agent string | "Mozilla/5.0..." |
Currently, there are no rate limits. Fair use is expected.
| Code | Message | Description |
|---|---|---|
| 400 | Bad Request | Invalid or missing parameters |
| 404 | Not Found | Tracking code not found |
| 500 | Internal Server Error | Server-side error occurred |
Questions? Check out the Documentation or contact support@livewebtraffic.com