qodenl/laravel-posthog
A Laravel package for integrating PostHog analytics into your app. Track events, identify users, and send data to PostHog through a simple, configurable API, making product analytics and feature flag workflows easier to add to Laravel projects.
getFeatureFlagPayload() returns a flag's decoded payload from the same cached evaluation as getFeatureFlag(), with no extra /flags request, and works under local evaluation. That makes payload-driven gating (limits, copy variants, pricing tests, config overrides) viable for high-traffic endpoints where per-request network calls or latency were previously a blocker — an "is PostHog fast enough for this?" decision becomes a yes.POSTHOG_RELEASE_ID is attached as $release_id to every event, including $feature_flag_called. This lets us answer "what did this deploy do to the funnel/flag metrics?" without building custom deploy markers or correlating timestamps. That it survives config:cache and PHP-FPM without clear_env = no removes the most common ops failure mode for this pattern.captureException() plus opt-in handler-wide reporting means one vendor for analytics, flags, and errors instead of standing up a second integration. For a Laravel app, using this thin maintained wrapper beats owning our own glue for config caching, queue IP capture, and exception hooks.POSTHOG_CAPTURE_IP (default off) fixes the "all our users appear to be in the datacenter" problem when events are dispatched to queues, and resolveIpUsing() covers proxies like Cloudflare. Any geo/regional segmentation we've been half-trusting is now fixable — and because it's opt-in, privacy review is a scoped decision rather than a blocker.Adoption criteria:
/flags API calls. The payload + local-evaluation work is the strongest argument for this release specifically.config:cache in production (most of us do) and want release tagging to actually work.Look elsewhere when:
posthog-php or a standard OTel pipeline may be the better center of gravity).capture_ip and handler-wide exception reporting both widen the data footprint.Validate before adopting: interaction with any custom exception handler, whether IP capture is consistent with our privacy notice and consent state, and that queued payloads don't carry IPs where they shouldn't. Pin the version, since the posthog-php 4.14 bump shifts local-evaluation matching semantics for flags.
For executives: a small, low-risk upgrade that makes our analytics materially more useful. Experiments now resolve on our servers from cache, so we can gate features and read variant payloads without added latency or API cost. Every event is stamped with the release that produced it, so we can read the impact of a deploy instead of guessing. Errors flow into the same tool we already pay for, and geographic reporting becomes accurate even though our queue workers — not our users — were previously supplying the IP. IP collection is opt-in and off by default. The one real cost is a platform requirement: we need to be on Laravel 12 or 13.
For engineering: a minor version bump with one breaking change (Laravel 11 dropped) and four additive capabilities: getFeatureFlagPayload() reading cached/local evaluations, POSTHOG_RELEASE_ID that is config-cache and PHP-FPM safe, captureException() with opt-in handler-wide reporting, and POSTHOG_CAPTURE_IP with resolveIpUsing() for proxies like Cloudflare. No migration work beyond the framework version and deliberately enabling the new flags; explicit $release_id and $ip in event properties still take precedence, so existing call sites keep their behavior.
How can I help you explore Laravel packages today?