jeffersongoncalves/laravel-metrics-posthog
A Laravel package that integrates PostHog metrics, letting you capture and send product analytics events from your app with minimal setup. Useful for tracking user behavior and wiring PostHog into Laravel's metrics tooling.
Architecture fit: This package is a read-oriented Laravel client for PostHog analytics through the HogQL query API. It fits applications that need server-side reporting, dashboards, internal analytics, or product metrics pulled from PostHog, but it is not an event instrumentation/capture SDK. Architecture fit is strongest where PostHog is already the analytics source of truth and Laravel needs controlled query access for admin dashboards, scheduled reports, or customer-facing metrics.
Integration feasibility: Feasible for Laravel 11/12/13 on PHP 8.2+. The PostHog facade provides a compact API surface for common analytics queries: aggregates, timeseries, breakdowns, pages, sources, countries, browsers, devices, realtime visitors, and raw HogQL. Settings are managed through spatie/laravel-settings, with the personal API key encrypted and seeded from environment variables. This is a conventional Laravel integration pattern, but it introduces a dependency on the settings package and its persistence model.
Technical risk: The main risk is scope confusion: this package queries PostHog; it does not replace PostHog capture libraries or guarantee event schema quality. Query reliability depends on PostHog project configuration, HogQL compatibility, API rate limits, and self-hosted PostHog version parity. Storing settings in the database means key rotation, encryption via APP_KEY, and deployment seeding need explicit operational handling. Typed exceptions improve failure handling, but dashboards must still account for auth expiry, rate limiting, query timeouts, and malformed/raw HogQL.
Key questions:
query calls sanitized, logged, or subject to PII controls?Stack fit: Good fit for Laravel teams already using PostHog and comfortable with facades, service container binding, environment-driven configuration, and spatie/laravel-settings. It is less suitable for teams expecting a drop-in analytics capture SDK or a vendor-neutral analytics abstraction.
Migration path: Add the package via Composer, configure POSTHOG_PERSONAL_API_KEY, POSTHOG_PROJECT_ID, and POSTHOG_HOST, then ensure the settings persistence layer and encryption are correctly deployed. Existing PostHog instrumentation remains unchanged; this package should be introduced as a reporting/query layer, not as a replacement for capture SDKs. Start with internal admin dashboards or scheduled reports before exposing metrics to customers.
Compatibility: Requires PHP 8.2+ and Laravel 11, 12, or 13. Confirm the host application’s spatie/laravel-settings version aligns with the package. Validate self-hosted PostHog compatibility early because HogQL behavior can differ by PostHog release. EU/US cloud host selection should be environment-specific, and personal API keys should be scoped to the minimum required project permissions.
Sequencing:
aggregate/timeseries.Maintenance: Low-to-moderate. Routine maintenance includes PostHog API key rotation, settings row integrity, encryption key management, dependency updates, and PostHog/HogQL compatibility checks. Because settings are database-backed, environment promotion and key rotation need runbook coverage.
Support: Support burden will center on query correctness and permissions rather than package installation. Teams will need someone who understands HogQL, PostHog event schemas, and the difference between capture and query APIs. Typed exceptions help triage, but support should define expected responses for expired keys, rate limits, and self-hosted API drift.
Scaling: Synchronous HogQL queries can become a bottleneck if used directly in request paths. Realtime visitor widgets and dashboard queries should be cached, debounced, or moved to queued jobs. Rate limits and query cost should be monitored per environment. Multi-tenant use is not implied by the release notes; a single project ID per app instance appears to be the default expectation.
Failure modes: Authentication failures from expired/revoked keys; rate-limit exhaustion from dashboard polling; query timeouts or expensive HogQL; schema drift in PostHog events; self-hosted version incompatibility; missing settings migration; encryption failures after APP_KEY rotation; and incorrect environment host/project configuration. Each should have explicit user-facing fallbacks, especially for customer-facing dashboards.
Ramp-up: Laravel developers should ramp quickly on the facade and settings pattern. The real learning curve is PostHog project structure, HogQL query design, API key scoping, and cost/rate-limit behavior. A short internal proof of concept with one aggregate query, one timeseries query, and failure-path testing is sufficient to validate fit before broader adoption.
How can I help you explore Laravel packages today?