An open API service indexing awesome lists of open source software.

https://github.com/remcostoeten/honolytics

Self-hosted analytics built with HONO, TypeScript & modern web tech. Privacy-focused, lightweight, developer-friendly.
https://github.com/remcostoeten/honolytics

analytics edge-runtime hono privacy self-hosted typescript

Last synced: about 2 months ago
JSON representation

Self-hosted analytics built with HONO, TypeScript & modern web tech. Privacy-focused, lightweight, developer-friendly.

Awesome Lists containing this project

README

          

# Honolytics

A lightweight analytics solution built with Hono.js featuring:

- **Real-time Analytics Collection** - Track pageviews, users, sessions, and custom events
- **Hooks** - React hooks for building analytics dashboards with centralized configuration
- **High Performance** - Built on Hono.js for blazing-fast performance
- **Privacy-First** - Self-hosted analytics solution you control
- **Multi-Platform** - Works with React, Next.js, and vanilla JavaScript

> [!NOTE]
> Current version (0.1) has no storage included. You bring your own server and database. In upcomming version I will implement various storage solutions.

## Quick Start

### 1. Install Hooks

```bash
bun add honolytics
```

### 2. Wrap Your App with Provider

```tsx
import { HonolyticsProvider } from 'honolytics'

function App() {
return (

< />

)
}
```

### 3. Use Analytics Hooks

```tsx
import { useAnalytics, useTotals } from 'honolytics'

function () {
const { data, loading, error } = useAnalytics()
const { data: totals } = useTotals()

if (loading) return

Loading...

if (error) return
Error: {error}

return (


Analytics


Users: {totals?.users}


Sessions: {totals?.sessions}


Page Views: {totals?.pageviews}



)
}
```

## Packages

### [honolytics](./packages/hooks/)

React hooks for building analytics s with centralized configuration.

**Key Features:**
- **Centralized Configuration** - Set API config once, use everywhere
- **Backward Compatible** - Existing code still works
- **Specialized Hooks** - Individual hooks for different data slices
- **Live Updates** - Built-in polling support
- **TypeScript** - Full type safety

**Available Hooks:**
- `useAnalytics()` - Complete analytics data
- `useTotals()` - Total metrics (users, sessions, pageviews)
- `useTimeseries()` - Time-series data points
- `useTopPages()` - Top pages breakdown
- `useCountries()` - Country breakdown
- `useBrowsers()` - Browser breakdown
- `useDevices()` - Device breakdown

[Full Documentation](./packages/hooks/README.md)

## Development

This project uses a monorepo structure with:
- **Bun** for package management
- **TypeScript** for type safety
- **React** for UI components

```bash
# Install dependencies
bun install

# Build all packages
bun run build

# Type check
bun run typecheck
```

## Usage Examples

### Basic
```tsx
function Simple() {
const { data: totals, loading } = useTotals()

if (loading) return

Loading...

return (


Users: {totals?.users}

Sessions: {totals?.sessions}

Page Views: {totals?.pageviews}

Avg Duration: {totals?.avgDuration}ms


)
}
```

### With Date Range
```tsx
function MonthlyReport() {
const lastMonth = {
from: new Date(2024, 9, 1),
to: new Date(2024, 9, 31)
}

const { data } = useAnalytics({
dateRange: lastMonth
})

return

October 2024 Analytics

}
```

### Live with Polling
```tsx
function Live() {
const { data } = useAnalytics({
pollingInterval: 30000 // Refresh every 30 seconds
})

return

Live Analytics (auto-refreshing)

}
```

## Contributing

1. Fork the repository
2. Create your feature branch (`git checkout -b feat/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feat/amazing-feature`)
5. Open a Pull Request

## License

This project is licensed under the MIT License.

---
xxx,
Remco Stoeten
Stars are appreciated for my e-penor growth