New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@litemetrics/node

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@litemetrics/node

Node.js analytics collector with DB adapters and query API

Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
7
75%
Maintainers
1
Weekly downloads
 
Created
Source

@litemetrics/node

Self-hosted analytics server for Litemetrics. Includes event collection, query API, site management, GeoIP enrichment, and bot filtering.

Installation

npm install @litemetrics/node

Quick Start

import express from 'express';
import { createCollector } from '@litemetrics/node';

const app = express();
app.use(express.json());

const collector = await createCollector({
  db: { url: 'http://localhost:8123' }, // ClickHouse (default)
  adminSecret: 'your-admin-secret',
  geoip: true,
  cors: { origins: [] }, // Allow all origins
});

// Event collection endpoint (receives tracker data)
app.post('/api/collect', collector.handler());

// Query API (stats, time series, retention)
app.get('/api/stats', collector.queryHandler());

// Event & user listing
app.all('/api/events', collector.eventsHandler());
app.all('/api/users/*', collector.usersHandler());

// Site management (CRUD)
app.all('/api/sites/*', collector.sitesHandler());

// Serve tracker script
app.use(express.static('node_modules/@litemetrics/tracker/dist'));

app.listen(3000);

Database Adapters

ClickHouse (Default)

const collector = await createCollector({
  db: { url: 'http://localhost:8123' },
});

Uses MergeTree for events and ReplacingMergeTree for sites. Tables are auto-created on init.

MongoDB

const collector = await createCollector({
  db: { adapter: 'mongodb', url: 'mongodb://localhost:27017/litemetrics' },
});

Features

  • Event Collection - Receives batched events from the browser tracker
  • Bot Filtering - Automatically drops events from known bots and crawlers
  • GeoIP Enrichment - Resolves country/city from IP using MaxMind GeoLite2
  • User-Agent Parsing - Extracts browser, OS, and device type
  • Hostname Filtering - Only count events from allowed hostnames per site (matched against request Origin/Referer)
  • Query API - Built-in metrics for pages, events, conversions, and behavioral insights
  • Segmentation Filters - Filter any metric/time series by geo, device, UTM, referrer, or event metadata
  • Time Series - Hourly/daily/weekly/monthly breakdowns
  • Retention Analysis - Weekly cohort retention
  • Site Management - Multi-tenant CRUD with secret key auth
  • Server-Side Tracking - Track events and identify users from your backend

Server-Side Tracking

// Track events from your backend
await collector.track('site-id', 'Purchase', { amount: 99 }, { userId: 'user-123' });

// Identify users
await collector.identify('site-id', 'user-123', { plan: 'pro' });

Identity Merging

Litemetrics automatically links anonymous visitors to identified users. After a user is identified, subsequent events are merged across all linked visitor IDs. GET /api/users/:identifier accepts either a visitorId or a userId and returns a merged profile when available.

Backfill (one-time)

If you already have identify events, run the backfill script once to populate the identity map:

bun packages/node/src/backfill-identity.ts --adapter clickhouse --url http://localhost:8123

Metrics

MetricDescription
pageviewsTotal page views
visitorsUnique visitors
sessionsUnique sessions
eventsCustom events count
conversionsConversion events count
top_pagesMost visited pages
top_referrersTop traffic sources
top_countriesVisitors by country
top_citiesVisitors by city
top_eventsMost common custom events
top_conversionsMost common conversion events
top_exit_pagesLast page in session
top_transitionsPage-to-page transitions
top_scroll_pagesPages with most scroll depth events
top_button_clicksMost clicked buttons (auto events)
top_link_targetsMost clicked link targets
top_browsersBrowser breakdown
top_osOS breakdown
top_devicesDevice type breakdown

License

MIT

Keywords

analytics

FAQs

Package last updated on 10 Feb 2026

Related posts