NPMv0.6.0Node.js 18+MIT License
@junglans/trail-server
Embedded Analytics & On-Page Heatmap Backend Middleware for Express and Next.js
An ultra-fast, zero-cloud-telemetry backend middleware that stores all incoming application events in your own local SQLite database under /api/jungtrail. Powered by better-sqlite3 with Write-Ahead Logging (WAL) for sub-millisecond event ingestion.
INGESTION LATENCY
<0.8ms
PEER DEPENDENCIES
Express >=4.0
DATA PERSISTENCE
Local SQLite
EXTERNAL TRAFFIC
Zero Bytes
1. Installation
Install @junglans/trail-server using your favorite package manager. All dependencies are minimal and zero-leakage.
Install Command
npm install @junglans/trail-server2. Quickstart & Implementation
Get up and running in less than 30 seconds. Copy and paste the code snippets below directly into your codebase.
Code Examples
import express from 'express';
import { jungtrailMiddleware } from '@junglans/trail-server';
const app = express();
app.use(express.json());
// Mount the analytics API onto Express
app.use('/api/jungtrail', jungtrailMiddleware({
dbName: 'analytics.db',
dbPath: './data/analytics.db',
adminKey: process.env.JUNGLANS_ADMIN_KEY || 'production-secret-key',
cors: true,
retentionDays: 90
}));
app.listen(8000, () => {
console.log('Junglans Trail server active on port 8000');
});File: server.jsjavascript
3. REST Ingestion & Analytics Endpoints
All endpoints are mounted automatically onto your host server under /api/jungtrail.
| Method | Endpoint | Authorization | Description |
|---|---|---|---|
| POST | /api/jungtrail/events | Public / Write Key | Ingests client and backend batches of user interactions, clicks, rage clicks, Web Vitals, and errors. |
| GET | /api/jungtrail/heatmap | Admin Key Required | Returns coordinates, element selectors, and click density clusters formatted for live canvas heatmap rendering. |
| GET | /api/jungtrail/stats | Admin Key Required | Retrieves aggregate KPIs: unique sessions, total page views, bounce rate, average time-on-page, top referral paths. |
| GET | /api/jungtrail/stats/ecommerce | Admin Key Required | Calculates e-commerce conversion rates, cart abandonment funnel metrics, total revenue, and average order value. |
| GET | /api/jungtrail/export | Admin Key Required | Streams a full JSON or CSV export of all indexed telemetry records for offline reporting and data warehousing. |
4. Configuration Options
Configurable parameters passed into the initialization middleware or factory functions.
| Option | Type | Default | Description |
|---|---|---|---|
| dbName | string | 'analytics.db' | Filename of the SQLite database created in the target directory. |
| dbPath | string | './data/analytics.db' | Relative or absolute filesystem path where database and WAL journal files are maintained. |
| adminKey | string | undefined | Secret passphrase required to access /stats, /heatmap, and /export endpoints. |
| cors | boolean | true | Enables Cross-Origin Resource Sharing headers for multi-domain frontend clients. |
| retentionDays | number | 90 | Automatic rolling retention period after which old event rows are vacuumed. |