PHPackages                             temperbit/larahog - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. temperbit/larahog

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

temperbit/larahog
=================

The Laravel-native PostHog experience.

v1.0.0(1mo ago)01MITPHPPHP ^8.3CI passing

Since Apr 16Pushed 1mo agoCompare

[ Source](https://github.com/TemperBit/LaraHog)[ Packagist](https://packagist.org/packages/temperbit/larahog)[ Docs](https://temperb.it/larahog)[ GitHub Sponsors](https://github.com/temperbit)[ RSS](/packages/temperbit-larahog/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (14)Versions (2)Used By (0)

LaraHog
=======

[](#larahog)

[![Latest Version on Packagist](https://camo.githubusercontent.com/fc3fd5d5669370aa4d7ff28ab660dc94cc57415819810fc5719d292e182f5d48/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74656d7065726269742f6c617261686f672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/temperbit/larahog)[![GitHub Tests Action Status](https://camo.githubusercontent.com/d6dcb5d83e5a2665eb0b8bbcef74782602aceab4e28f5ec0737eb743d3df1e9e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f74656d7065726269742f6c617261686f672f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/temperbit/larahog/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/bf19784dea8064f74ebcc5032b87936edc672808acda217b7608090a3ac1066c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f74656d7065726269742f6c617261686f672f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/temperbit/larahog/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/d2abd4dd79badfe44a650d178ffa5a7dceb82cbb744d1194549acde98602cb58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74656d7065726269742f6c617261686f672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/temperbit/larahog)

The Laravel-native PostHog experience. LaraHog wraps the [PostHog PHP SDK](https://github.com/PostHog/posthog-php) into a first-class Laravel package with multi-connection support, queue-based dispatch, and Octane compatibility out of the box.

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 11, 12, or 13

Support us
----------

[](#support-us)

We invest a lot of resources into creating awesome software. You can support us by [sponsoring us on GitHub](https://github.com/sponsors/temperbit).

Installation
------------

[](#installation)

```
composer require temperbit/larahog
```

Publish the config file:

```
php artisan vendor:publish --tag="larahog-config"
```

Add your PostHog project token to `.env`:

```
POSTHOG_PROJECT_TOKEN=phc_your_project_token
```

Configuration
-------------

[](#configuration)

The published config file will be at `config/larahog.php`.

VariableDefaultDescription`POSTHOG_CONNECTION``default`Default connection name`POSTHOG_ENABLED``true`Enable/disable the default connection`POSTHOG_PROJECT_TOKEN``""`Your PostHog project API key`POSTHOG_HOST``https://us.i.posthog.com`PostHog instance URL`POSTHOG_DISPATCH_MODE``sync``sync` or `queue``POSTHOG_QUEUE_CONNECTION``null`Laravel queue connection (when using queue mode)`POSTHOG_QUEUE_NAME``default`Laravel queue name (when using queue mode)### Multi-connection support

[](#multi-connection-support)

You can define multiple PostHog connections for different projects:

```
// config/larahog.php
'connections' => [
    'default' => [
        'project_token' => env('POSTHOG_PROJECT_TOKEN'),
        // ...
    ],
    'marketing' => [
        'project_token' => env('POSTHOG_MARKETING_TOKEN'),
        // ...
    ],
],
```

Then target a specific connection:

```
LaraHog::connection('marketing')->capture('user-123', 'campaign_clicked');
```

Usage
-----

[](#usage)

### Capturing events

[](#capturing-events)

```
use TemperBit\LaraHog\Facades\LaraHog;

// Basic event
LaraHog::capture('user-123', 'page_viewed');

// With properties
LaraHog::capture('user-123', 'purchase_completed', [
    'amount' => 49.99,
    'currency' => 'USD',
]);

// With group association
LaraHog::capture('user-123', 'report_exported', [], [
    'company' => 'company-456',
]);

// Anonymous event
LaraHog::capture(null, 'landing_page_viewed');
```

### Identifying users

[](#identifying-users)

```
LaraHog::identify('user-123', [
    'name' => 'Jane Doe',
    'email' => 'jane@example.com',
    'plan' => 'enterprise',
]);
```

### Aliasing identities

[](#aliasing-identities)

```
LaraHog::alias('user-123', 'anonymous-session-abc');
```

### Group identities

[](#group-identities)

```
LaraHog::groupIdentify('company', 'company-456', [
    'name' => 'Acme Corp',
    'industry' => 'SaaS',
]);
```

### Flushing

[](#flushing)

LaraHog automatically flushes pending events when the application terminates. You can also flush manually:

```
LaraHog::flush();    // Flush the default connection
LaraHog::flushAll(); // Flush all connections
```

### Checking status

[](#checking-status)

```
if (LaraHog::isEnabled()) {
    // ...
}
```

Dispatch Modes
--------------

[](#dispatch-modes)

### Sync (default)

[](#sync-default)

Events are buffered in memory by the PostHog SDK and sent in batches at the end of the request lifecycle. This is the simplest setup and works well for most applications.

```
POSTHOG_DISPATCH_MODE=sync
```

### Queue

[](#queue)

Events are dispatched to a Laravel queue for asynchronous processing. This moves PostHog API calls out of the request path entirely.

```
POSTHOG_DISPATCH_MODE=queue
POSTHOG_QUEUE_CONNECTION=redis
POSTHOG_QUEUE_NAME=analytics
```

Octane Compatibility
--------------------

[](#octane-compatibility)

LaraHog uses a `PostHog\Client` instance (not the static `PostHog::init()` method), so each request gets a clean state. Multi-connection support is handled through the `LaraHogManager` singleton, which lazily resolves connections. This design is safe to use with Laravel Octane.

Artisan Commands
----------------

[](#artisan-commands)

### `larahog:status`

[](#larahogstatus)

Displays the current configuration and tests connectivity to PostHog:

```
php artisan larahog:status
php artisan larahog:status --connection=marketing
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [TemperBit](https://github.com/temperbit)
- [Anand Capur](https://github.com/arcdigital)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance89

Actively maintained with recent releases

Popularity1

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

55d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/53413269f9ef839022f59d939bc3e0217db52c5ae1d3756aef2b4eab3f38c4ac?d=identicon)[arcdigital](/maintainers/arcdigital)

---

Top Contributors

[![arcdigital](https://avatars.githubusercontent.com/u/551002?v=4)](https://github.com/arcdigital "arcdigital (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

laravelanalyticsposthogproduct analyticsevent trackingtemperbitlarahog

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/temperbit-larahog/health.svg)

```
[![Health](https://phpackages.com/badges/temperbit-larahog/health.svg)](https://phpackages.com/packages/temperbit-larahog)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.8k33.0M871](/packages/spatie-laravel-data)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.3M41](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

327482.0k25](/packages/codewithdennis-filament-select-tree)[nativephp/desktop

NativePHP for Desktop

37833.6k8](/packages/nativephp-desktop)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124581.3k](/packages/worksome-exchange)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3913.7k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
