@litemetrics/node 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # @litemetrics/node
2
+
3
+ Self-hosted analytics server for Litemetrics. Includes event collection, query API, site management, GeoIP enrichment, and bot filtering.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @litemetrics/node
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```ts
14
+ import express from 'express';
15
+ import { createCollector } from '@litemetrics/node';
16
+
17
+ const app = express();
18
+ app.use(express.json());
19
+
20
+ const collector = await createCollector({
21
+ db: { url: 'http://localhost:8123' }, // ClickHouse (default)
22
+ adminSecret: 'your-admin-secret',
23
+ geoip: true,
24
+ cors: { origins: [] }, // Allow all origins
25
+ });
26
+
27
+ // Event collection endpoint (receives tracker data)
28
+ app.post('/api/collect', collector.handler());
29
+
30
+ // Query API (stats, time series, retention)
31
+ app.get('/api/stats', collector.queryHandler());
32
+
33
+ // Event & user listing
34
+ app.all('/api/events', collector.eventsHandler());
35
+ app.all('/api/users/*', collector.usersHandler());
36
+
37
+ // Site management (CRUD)
38
+ app.all('/api/sites/*', collector.sitesHandler());
39
+
40
+ // Serve tracker script
41
+ app.use(express.static('node_modules/@litemetrics/tracker/dist'));
42
+
43
+ app.listen(3000);
44
+ ```
45
+
46
+ ## Database Adapters
47
+
48
+ ### ClickHouse (Default)
49
+
50
+ ```ts
51
+ const collector = await createCollector({
52
+ db: { url: 'http://localhost:8123' },
53
+ });
54
+ ```
55
+
56
+ Uses `MergeTree` for events and `ReplacingMergeTree` for sites. Tables are auto-created on init.
57
+
58
+ ### MongoDB
59
+
60
+ ```ts
61
+ const collector = await createCollector({
62
+ db: { adapter: 'mongodb', url: 'mongodb://localhost:27017/litemetrics' },
63
+ });
64
+ ```
65
+
66
+ ## Features
67
+
68
+ - **Event Collection** - Receives batched events from the browser tracker
69
+ - **Bot Filtering** - Automatically drops events from known bots and crawlers
70
+ - **GeoIP Enrichment** - Resolves country/city from IP using MaxMind GeoLite2
71
+ - **User-Agent Parsing** - Extracts browser, OS, and device type
72
+ - **Hostname Filtering** - Only count events from allowed hostnames per site
73
+ - **Query API** - Built-in metrics for pages, events, conversions, and behavioral insights
74
+ - **Segmentation Filters** - Filter any metric/time series by geo, device, UTM, referrer, or event metadata
75
+ - **Time Series** - Hourly/daily/weekly/monthly breakdowns
76
+ - **Retention Analysis** - Weekly cohort retention
77
+ - **Site Management** - Multi-tenant CRUD with secret key auth
78
+ - **Server-Side Tracking** - Track events and identify users from your backend
79
+
80
+ ## Server-Side Tracking
81
+
82
+ ```ts
83
+ // Track events from your backend
84
+ await collector.track('site-id', 'Purchase', { amount: 99 }, { userId: 'user-123' });
85
+
86
+ // Identify users
87
+ await collector.identify('site-id', 'user-123', { plan: 'pro' });
88
+ ```
89
+
90
+ ## Metrics
91
+
92
+ | Metric | Description |
93
+ |--------|-------------|
94
+ | `pageviews` | Total page views |
95
+ | `visitors` | Unique visitors |
96
+ | `sessions` | Unique sessions |
97
+ | `events` | Custom events count |
98
+ | `conversions` | Conversion events count |
99
+ | `top_pages` | Most visited pages |
100
+ | `top_referrers` | Top traffic sources |
101
+ | `top_countries` | Visitors by country |
102
+ | `top_cities` | Visitors by city |
103
+ | `top_events` | Most common custom events |
104
+ | `top_conversions` | Most common conversion events |
105
+ | `top_exit_pages` | Last page in session |
106
+ | `top_transitions` | Page-to-page transitions |
107
+ | `top_scroll_pages` | Pages with most scroll depth events |
108
+ | `top_button_clicks` | Most clicked buttons (auto events) |
109
+ | `top_link_targets` | Most clicked link targets |
110
+ | `top_browsers` | Browser breakdown |
111
+ | `top_os` | OS breakdown |
112
+ | `top_devices` | Device type breakdown |
113
+
114
+ ## License
115
+
116
+ MIT