UNPKG

better-analytics

Version:

Zero-dependency micro-analytics JavaScript SDK < 3KB gzipped with React/Next.js/Expo support

36 lines (33 loc) 1.64 kB
import React from 'react'; import { B as BeforeSend } from '../types-DzHHnKL8.js'; interface AnalyticsProps { /** API endpoint to send analytics data to (optional, defaults to Better Analytics SaaS) */ api?: string; /** Alternative name for api prop (for compatibility with init() function) */ endpoint?: string; /** Site identifier to track which project/user is sending data (required, or use NEXT_PUBLIC_BA_SITE) */ site?: string; /** Custom environment variable name for URL (default: NEXT_PUBLIC_BA_URL) */ urlEnvVar?: string; /** Custom environment variable name for site (default: NEXT_PUBLIC_BA_SITE) */ siteEnvVar?: string; /** Override environment detection (development/production) */ mode?: 'development' | 'production' | 'auto'; /** Enable debug mode to log events to console */ debug?: boolean; /** Modify event data before sending - return null to ignore event */ beforeSend?: BeforeSend; } /** * Analytics component that automatically tracks page views in Next.js applications * * Usage: * <Analytics site="my-site" /> // Uses Better Analytics SaaS (default) with your site ID * <Analytics site="my-site" api="/api/collect" /> // Custom endpoint with site ID * <Analytics /> // Uses NEXT_PUBLIC_BA_SITE (required) and optional NEXT_PUBLIC_BA_URL * <Analytics urlEnvVar="CUSTOM_URL" siteEnvVar="CUSTOM_SITE" /> // Custom env vars * * Similar to Vercel Analytics - just add to your layout and it works automatically */ declare function Analytics(props?: AnalyticsProps): React.ReactElement | null; export { Analytics, type AnalyticsProps };