Releases: decker-dev/better-analytics
v0.10.1: Patch Release Latest
This is a patch release that includes minor bug fixes and improvements to the Better Analytics SDK.
🐛 Bug Fixes
- Minor performance optimizations
- Improved error handling in edge cases
- Enhanced TypeScript type definitions
📦 Package Updates
- Updated dependencies to latest stable versions
- Improved build process
v0.10.0: Next.js Server Auto-Initialization
This release dramatically improves the Next.js integration by introducing zero-config server tracking and fixing critical compatibility issues between client and server environments.
✨ New Features
🚀 Zero-Config Server Tracking
# Just set environment variables - no manual initialization needed!
NEXT_PUBLIC_BA_SITE=my-app// API Routes - works automatically
import { trackServer } from "better-analytics/next";
export async function POST(request) {
// ✨ Auto-initialized from env vars!
await trackServer('api_call', { endpoint: '/users' }, { request });
}
// Server Actions - works automatically
'use server';
import { trackServer, identifyServer } from "better-analytics/next";
export async function createUser(formData) {
await identifyServer('user123', { email: formData.get('email') });
await trackServer('user_signup', { method: 'form' });
}v0.9.0
This release introduces fundamental improvements to the Expo module, dramatically increasing the reliability of data collection in mobile environments and fixing a key issue with automatic tracking.
✨ New Features
- Offline Event Queuing (Expo): A robust queueing system using
AsyncStoragehas been implemented. If an event is triggered while the device is offline, it is saved locally. The library will automatically attempt to send all queued events when the connection is restored, ensuring that critical user data is not lost due to connectivity issues.
🐛 Bug Fixes
- Navigation Tracking in Expo Router: A critical bug in the
useExpoRouterTrackinghook implementation, which violated the rules of React Hooks, has been fixed. Automatic screen view tracking now works reliably and correctly withexpo-router.
v0.8.0 Expo Router Auto-Tracking
✨ New Features
🎯 Zero-Config Navigation
// Just add the Provider - automatic tracking!
<AnalyticsProvider site="my-app" />trackNavigation: trueby default - no configuration needed- Smart route detection:
/profile/settings→profile_settings - Parameters included automatically
- Works with Expo Router out-of-the-box
🧹 Simplified API
// Cleaner API
import { init, track, useAnalytics } from "better-analytics/expo";- Removed unnecessary aliases (
trackRN,initRN, etc.) - Simpler function names (
initExpo→init)
🔧 Improvements
- Enhanced debug logging for navigation
- Dynamic Expo Router imports (no crashes if not installed)
- Better error handling
- TypeScript improvements
📦 Installation
npm install better-analytics @react-native-async-storage/async-storage
npx expo install expo-device expo-application expo-localization expo-network expo-router🎯 Usage
// app/_layout.js
import { AnalyticsProvider } from "better-analytics/expo";
export default function RootLayout() {
return (
<AnalyticsProvider site="my-app">
<Stack />
</AnalyticsProvider>
);
}Better Analytics v0.7.0 - Expo-First Support + Platform-Specific Types
Better Analytics v0.7.0 - Expo Support + Platform-Specific Types
🎯 Major Features
- 📱 Expo Support: Complete Expo integration optimized for the Expo ecosystem with native device information
- 🎯 Platform-Specific Types: Separate TypeScript types for web, mobile, and server to prevent confusion and improve DX
- 🔄 Navigation Tracking: Automatic screen navigation tracking for mobile apps
- 💾 Mobile Offline Support: AsyncStorage-based event queuing for offline scenarios
- 📱 Native Device Info: Rich device metadata using Expo modules (Device, Application, Localization, Network)
- 🎯 Provider Pattern: React Context-based AnalyticsProvider for app-wide configuration
📦 Installation
# For Expo projects (Recommended)
npm install better-analytics @react-native-async-storage/async-storage
npx expo install expo-device expo-application expo-localization expo-network🚀 Quick Start
Provider Setup (Recommended)
import { AnalyticsProvider } from "better-analytics/expo";
export default function App() {
return (
<AnalyticsProvider
site="my-app"
debug={__DEV__}
trackNavigation={true}
>
<YourAppContent />
</AnalyticsProvider>
);
}Manual Setup
import { initExpo } from "better-analytics/expo";
initExpo({
site: 'my-app',
debug: __DEV__,
trackNavigation: true
});Usage in Components
import { useAnalytics } from "better-analytics/expo";
function HomeScreen() {
const { track, trackScreen, identify } = useAnalytics();
useEffect(() => {
trackScreen('Home');
}, []);
const handleSignup = async () => {
await identify('user123', {
email: 'user@example.com',
platform: Platform.OS
});
track('signup_completed', {
method: 'email',
screen: 'home'
});
};
}🎯 Platform-Specific TypeScript Types
Web/Browser Types (Core & Next.js)
import { EventData } from "better-analytics";
// Only web-relevant properties: viewportWidth, page, connectionType
const webEvent: EventData = {
device: {
viewportWidth: 1200, // ✅ Web-specific
connectionType: '4g' // ✅ Web-specific
},
page: { // ✅ Web-specific
title: 'My Page',
loadTime: 1250
}
// ❌ No mobile properties (platform, brand, app, etc.)
};Mobile Types (Expo)
import { EventData } from "better-analytics/expo";
// Only mobile-relevant properties: platform, brand, model, app
const mobileEvent: EventData = {
device: {
platform: 'ios', // ✅ Mobile-specific
brand: 'Apple', // ✅ Mobile-specific
model: 'iPhone 14' // ✅ Mobile-specific
},
app: { // ✅ Mobile-specific
version: '1.0.0',
bundleId: 'com.myapp'
}
// ❌ No web properties (viewportWidth, page, etc.)
};📱 Mobile-Specific Features
- Native Device Information: Platform, screen dimensions, device model, brand, OS version
- App Metadata: App version, build number, bundle ID
- Session Management: Persistent sessions with 30-minute timeout using AsyncStorage
- Device Fingerprinting: Lightweight device ID generation and persistence
- Network Awareness: Automatic offline detection and event queuing
- Screen Tracking: Specialized
trackScreen()for mobile navigation patterns
🏗️ Technical Improvements
- Type Safety: Platform-specific types prevent confusion and improve IntelliSense
- Zero Web Dependencies: Separate mobile-optimized bundle with React Native APIs
- Expo Modules: Full integration with Expo's device information APIs
- Graceful Fallbacks: Works even when optional Expo modules are unavailable
- Bundle Size: Only 1.8KB gzipped for the Expo adapter
📦 Bundle Sizes
| Platform | Size (gzipped) |
|---|---|
| Web/Browser | 2.1KB |
| Next.js | 2.3KB |
| Expo | 1.8KB |
| Server | 1.9KB |
🔄 Migration from 0.6.0
No breaking changes! Existing web and server code continues to work. New Expo support is additive.
New APIs
initExpo()- Initialize Expo analyticsuseAnalytics()- React hook for Expo componentstrackScreen()- Mobile-optimized screen tracking
v0.6.0 - Server-Side Tracking & Advanced Features
Major Features
- 🖥️ Server-Side Tracking: Complete server-side analytics for Node.js, Edge Functions, Cloudflare Workers
- 🔄 beforeSend Middleware: Transform or filter events before sending
- 📱 Offline Support: Automatic retry with localStorage queue
- 🚦 Route Computation: Automatic route pattern detection for SPAs (e.g.,
/user/[id]) - 📦 Event Batching: Server-side performance optimization
- 👤 User Identification: New
identify()API for user tracking - ⏱️ Queue System: Capture events before SDK initialization
- 🔗 Session Stitching: Maintain session continuity between client and server
New APIs
Client-Side
// Initialize with beforeSend
init({
site: 'my-app',
beforeSend: (event) => {
if (event.url?.includes('/admin')) return null;
return event;
}
});
// Identify users
identify('user123', {
email: 'user@example.com',
plan: 'pro'
});Server-Side
import { initServer, trackServer } from "better-analytics/server";
// Initialize with batching
initServer({
site: 'my-app',
batch: { size: 50, interval: 5000 }
});
// Track from API routes
await trackServer('api_call', props, {
request,
user: { id: 'user123', sessionId: 'session456' }
});This release transforms Better Analytics from a simple client-side tracker to a complete analytics solution suitable for modern full-stack applications.
v0.4.0 - SaaS Integration & Simplified Setup
Major Changes
- SaaS Integration: Now uses Better Analytics SaaS (
https://better-analytics.app/api/collect) as the default endpoint - Required Site Parameter: The
siteparameter is now required, whileendpointis optional - Simplified Setup: You can now start tracking with just
init({ site: 'my-app' })- no endpoint configuration needed unless you want to use your own server
Breaking Changes
// Before (v0.3.0 and earlier)
init({ endpoint: '/api/collect', site: 'my-app' });
// After (v0.4.0) - Uses Better Analytics SaaS by default
init({ site: 'my-app' });
// Or with custom endpoint
init({ site: 'my-app', endpoint: '/api/collect' });New Features
Default SaaS Integration
import { init, track } from "better-analytics";
// Automatically sends to Better Analytics SaaS
init({ site: 'my-app' });
track('user_signup', { plan: 'pro' });Simplified Next.js Setup
import { Analytics } from "better-analytics/next";
// Just add your site ID - works immediately
<Analytics site="my-app" />
// Environment variable approach
// .env.local: NEXT_PUBLIC_BA_SITE=my-app
<Analytics />This update makes Better Analytics much easier to get started with while maintaining full flexibility for custom implementations.