Tagline: "Analytics that live with your app."
Self-contained analytics SDK that runs entirely on your infrastructure – no external servers, no tracking scripts, no cost.
This is a monorepo containing the Locallytics packages:
packages/- Contains all the packageslocallytics/- The main Locallytics packagecli/- The Locallytics CLI
docs/- Documentation and guides for the project
Locallytics is a privacy-first analytics solution where developers drop in an <AnalyticsGrabber /> component to collect data and use AnalyticsJSON() to fetch metrics, all powered by their own database and hosting.
- Lightweight: No external dependencies
- Simple: Easy to set up and use
- Fast: Event batching with reliable delivery
- Secure: Do Not Track (DNT) support
- Flexible: Supports PostgreSQL and SQLite
- Private: No cookies, runs on your infrastructure
- Type Safe: Full TypeScript support
- Install the package:
npm install locallytics
# or
yarn add locallytics
# or
pnpm add locallytics- Set up the client
import { locallytics } from "locallytics";
export const analytics = await locallytics({
database: process.env.DATABASE_URL!,
});
export const { GET, POST } = analytics;- Run migrations
# Generate schema (creates ./locallytics/schema.sql)
npx locallytics generate
# Run migrations
npx locallytics migrate- Add AnalyticsGrabber to your layout:
// app/layout.tsx
import { AnalyticsGrabber } from "locallytics";
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html>
<body>
{children}
<AnalyticsGrabber />
</body>
</html>
);
}- Fetch analytics data:
// app/analytics/page.tsx
import { AnalyticsJSON } from "locallytics";
import { headers } from "next/headers";
export default async function AnalyticsPage() {
const data = await AnalyticsJSON({ headersReader: headers });
return (
<div>
<h1>Pageviews: {data.pageviews}</h1>
<h2>Unique Visitors: {data.uniqueVisitors}</h2>
<pre>{JSON.stringify(data, null, 2)}</pre>
</div>
);
}pageviews- Total page viewsuniqueVisitors- Unique visitor counttopPages- Most visited pages with countsdailyStats- Daily pageviews and unique visitorstopReferrers- Top referrer sourcestopEvents- Custom event counts
MIT