Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Metrics Posthog Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

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:

  • Does the package publish its own settings migration/config, or must the host app create and manage the settings table?
  • Are queries paginated, cached, or queued, or does each facade call execute synchronously against PostHog?
  • What HogQL/PostHog API version is assumed for self-hosted deployments?
  • How are project ID and host validated across US, EU, and self-hosted environments?
  • Is there support for multiple projects/tenants, or one project per application instance?
  • What is the expected behavior for realtime visitor polling under rate limits?
  • Are raw query calls sanitized, logged, or subject to PII controls?

Integration Approach

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:

  1. Confirm PostHog project, host, and personal API key permissions.
  2. Install package and settings dependency; publish/configure migrations and settings.
  3. Seed non-production environment with a read-only key and test aggregate/timeseries.
  4. Implement exception handling for auth, rate limit, and generic PostHog failures.
  5. Add caching or queued jobs for expensive dashboards before wider rollout.
  6. Validate self-hosted compatibility if applicable.
  7. Roll out internal reporting first, then customer-facing metrics after load and privacy review.

Operational Impact

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc