定制 temperbit/larahog 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

temperbit/larahog

Composer 安装命令:

composer require temperbit/larahog

包简介

The Laravel-native PostHog experience.

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

The Laravel-native PostHog experience. LaraHog wraps the PostHog PHP SDK into a first-class Laravel package with multi-connection support, queue-based dispatch, and Octane compatibility out of the box.

Requirements

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

Support us

We invest a lot of resources into creating awesome software. You can support us by sponsoring us on GitHub.

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

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

Variable Default Description
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

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

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

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

Aliasing identities

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

Group identities

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

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

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

Dispatch Modes

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

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

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

larahog:status

Displays the current configuration and tests connectivity to PostHog:

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

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

temperbit/larahog 适用场景与选型建议

temperbit/larahog 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「analytics」 「laravel」 「event tracking」 「product analytics」 「posthog」 「temperbit」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 temperbit/larahog 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 temperbit/larahog 我们能提供哪些服务?
定制开发 / 二次开发

基于 temperbit/larahog 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 26
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-16