locallytics
v0.1.9
Published
Self-hosted, privacy-first analytics SDK for Next.js
Maintainers
Readme
Locallytics
Self-hosted, privacy-first analytics SDK for Next.js.
Installation
npm install locallyticsQuick Start
1. Setup Database
Use our CLI to set up your PostgreSQL database automatically:
npx locallytics-cli migrate2. Add API Route
// app/api/analytics/route.ts
import { locallytics } from "locallytics";
const analytics = await locallytics({
database: process.env.DATABASE_URL!,
});
export const { GET, POST } = analytics;3. Add Tracker
// app/layout.tsx
import { LocallyticsGrabber } from "locallytics";
export default function RootLayout({ children }) {
return (
<html>
<body>
{children}
<LocallyticsGrabber />
</body>
</html>
);
}4. Fetch Data
// app/page.tsx
import { LocallyticsData } from "locallytics";
export default async function Home() {
const data = await LocallyticsData(); // Simple! No arguments.
return <pre>{JSON.stringify(data, null, 2)}</pre>;
}Features
- Privacy: No cookies, hashed IPs, supports Do Not Track.
- Simplicity: Zero-config data fetching.
- Speed: Lightweight (< 5KB) and fast.
License
MIT
