REST API
Update an existing page view tracking entry with engagement metrics. Use this to send periodic updates or final metrics when the user leaves.
PUT
{{baseUrl}}/v1/analytics/track/:idAuth required
| Property | Type | Description | Default |
|---|---|---|---|
id* | string | Page view ID (e.g., 'pv_xyz789') | - |
| Property | Type | Description | Default |
|---|---|---|---|
timeOnPage | number | Total time spent in seconds | - |
scrollDepth | number | Maximum scroll depth (0-100%) | - |
exitPosition | number | Scroll position when leaving (0-100%) | - |
bounced | boolean | Whether user bounced (< 5 seconds) | - |
events | PageEvent[] | Additional custom events | - |
| Property | Type | Description | Default |
|---|---|---|---|
success* | boolean | Whether update succeeded | - |
cURL Command
curl -X PUT "https://api.simplist.blog/v1/analytics/track/pv_xyz789" \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"timeOnPage\":125,\"scrollDepth\":85,\"exitPosition\":85,\"bounced\":false}"{
"timeOnPage": 125,
"scrollDepth": 85,
"exitPosition": 85,
"bounced": false,
"events": [
{
"type": "button_click",
"element": "share-button",
"timeOffset": 45000
}
]
}{
"data": {
"success": true
}
}- Initialize tracking with POST/v1/analytics/track
- Store the returned ID
- Update periodically (every 30s) with current metrics
- Send final update when user leaves page
// 1. Initialize
const response = await fetch('https://api.simplist.blog/v1/analytics/track', {
method: 'POST',
headers: {
'X-API-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ slug: 'my-article', timeOnPage: 0 })
})
const { id } = await response.json()
// 2. Update periodically
setInterval(async () => {
await fetch(`https://api.simplist.blog/v1/analytics/track/${id}`, {
method: 'PUT',
headers: {
'X-API-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
timeOnPage: getTimeOnPage(),
scrollDepth: getScrollDepth()
})
})
}, 30000)
// 3. Final update on unload
window.addEventListener('beforeunload', async () => {
await fetch(`https://api.simplist.blog/v1/analytics/track/${id}`, {
method: 'PUT',
headers: {
'X-API-Key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
timeOnPage: getTimeOnPage(),
scrollDepth: getScrollDepth(),
exitPosition: getScrollDepth(),
bounced: getTimeOnPage() < 5
})
})
})If you're using TypeScript/JavaScript, you can use the SDK instead: client.analytics.update()