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.
aggregate, timeseries, breakdown, pages, sources, countries, browsers, devices and realtimeVisitors as first-class methods, which maps directly to the common dashboard widgets a PM would spec (traffic trend, top pages, acquisition mix, live activity). That makes "build an in-app analytics tab" a plausible roadmap item instead of a PostHog-UI-only dependency.query escape hatch covers the long tail of custom HogQL without forcing you off the package.POSTHOG_HOST plus US/EU/self-hosted support means the same code path works for a SaaS on PostHog Cloud and an enterprise deployment that must keep analytics data in its own infrastructure — a real procurement unblocker.AuthenticationException, RateLimitException and PostHogException let engineering degrade gracefully (stale cache, hidden widget) rather than 500 the page. This is the difference between "analytics is a nice-to-have that can fail silently" and "analytics can take down the dashboard," and it should be an explicit acceptance criterion in the spec.spatie/laravel-settings and seeded from env, which shortens the security review conversation versus a bespoke implementation storing a key in plain config.Adopt when most of these hold:
query.spatie/laravel-settings and its settings table/migration to the application — it is a reasonable but non-trivial architectural dependency for a reporting feature.Look elsewhere or wait when:
realtimeVisitors.To executives: We can put product analytics directly inside our own product — traffic trends, top pages, acquisition sources, geography, device/browser mix and live visitor counts — without sending users to a third-party dashboard and without building an analytics backend. It is a small, single-purpose Laravel package, it works with PostHog Cloud in the US or EU or with a self-hosted instance (which matters for data-residency conversations), credentials are encrypted at rest, and failures surface as typed errors we can handle so analytics never takes down a page. The trade-off is honest: it is a first release, it only reads data (we still use PostHog's SDK to collect it), and it requires a personal API key with account-level scope.
To engineering: A typed facade over PostHog's HogQL query API — nine opinionated methods plus a raw query escape hatch, config seeded from POSTHOG_PERSONAL_API_KEY / POSTHOG_PROJECT_ID / POSTHOG_HOST, key encrypted via spatie/laravel-settings. Requires PHP 8.2+ and Laravel 11–13. What it does not give us: caching, retries/backoff, batching, or any ingestion. Plan to wrap calls in our own cache and resilience layer, particularly for the realtime widget, and treat the personal API key as a scoped secret with a rotation story before this goes anywhere near production.
How can I help you explore Laravel packages today?