{"id":20621314,"url":"https://github.com/secrethash/laravel-mixpanel","last_synced_at":"2025-04-15T12:14:47.600Z","repository":{"id":261658457,"uuid":"878274199","full_name":"secrethash/laravel-mixpanel","owner":"secrethash","description":"Mixpanel PHP SDK bridge for Laravel","archived":false,"fork":false,"pushed_at":"2025-04-14T10:08:57.000Z","size":39,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T20:54:05.766Z","etag":null,"topics":["laravel","mixpanel","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/secrethash.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"secrethash"}},"created_at":"2024-10-25T04:55:17.000Z","updated_at":"2025-03-01T08:39:14.000Z","dependencies_parsed_at":"2024-11-10T18:02:30.495Z","dependency_job_id":null,"html_url":"https://github.com/secrethash/laravel-mixpanel","commit_stats":null,"previous_names":["secrethash/laravel-mixpanel"],"tags_count":3,"template":false,"template_full_name":"spatie/package-skeleton-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secrethash%2Flaravel-mixpanel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secrethash%2Flaravel-mixpanel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secrethash%2Flaravel-mixpanel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secrethash%2Flaravel-mixpanel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/secrethash","download_url":"https://codeload.github.com/secrethash/laravel-mixpanel/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961201,"owners_count":21189991,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","mixpanel","php"],"created_at":"2024-11-16T12:17:28.663Z","updated_at":"2025-04-15T12:14:47.580Z","avatar_url":"https://github.com/secrethash.png","language":"PHP","funding_links":["https://github.com/sponsors/secrethash"],"categories":[],"sub_categories":[],"readme":"# Mixpanel for Laravel\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/secrethash/laravel-mixpanel.svg?style=flat-square)](https://packagist.org/packages/secrethash/laravel-mixpanel)\n[![Tests](https://img.shields.io/github/actions/workflow/status/secrethash/laravel-mixpanel/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/secrethash/laravel-mixpanel/actions/workflows/run-tests.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/secrethash/laravel-mixpanel.svg?style=flat-square)](https://packagist.org/packages/secrethash/laravel-mixpanel)\n\n---\n\u003e :construction: Under active development, but might be useable.\n\u003e\n\u003e :star2: Contributions are welcomed \u0026 appreciated.\n---\n\n![secrethash/laravel-mixpanel Banner](https://banners.beyondco.de/Laravel%20Mixpanel.png?theme=light\u0026packageManager=composer+require\u0026packageName=secrethash%2Flaravel-mixpanel\u0026pattern=graphPaper\u0026style=style_1\u0026description=Mixpanel+PHP+SDK+bridge+for+Laravel\u0026md=1\u0026showWatermark=0\u0026fontSize=100px\u0026images=chart-pie)\n\nThis package provides a sane [Mixpanel PHP SDK](https://github.com/mixpanel/mixpanel-php/) bridge for Laravel applications.\n\n## Pre-requisites\n\n- Laravel: `^9.x`\n- PHP: `^8.2`\n- Mixpanel API Project Token\n\n## Installation\n\n1. Install the package via composer:\n\n    ```bash\n    composer require secrethash/laravel-mixpanel\n    ```\n\n2. Publish the Migrations and Config:\n    - Publish all resources [`migrations`, `config`]:\n\n        ```bash\n        php artisan vendor:publish --provider=\"Secrethash\\Mixpanel\\MixpanelServiceProvider\"\n        ```\n\n    - Publish only migrations:\n\n        ```bash\n        php artisan vendor:publish --tag=\"laravel-mixpanel-migrations\"\n        ```\n\n    - Publish only config:\n\n        ```bash\n        php artisan vendor:publish --tag=\"laravel-mixpanel-config\"\n        ```\n\n## Idealogies\n\n### 1. Events \u0026 Listeners\n\nWe use Laravel's event and listeners to track and send data to Mixpanel. This makes it easier to hook into events as and when needed.\n\nAlthough the package does not force to use events and listeners in your application while tracking, but it's still recommended for maintainability. Similarly we will also take the example of events and listeners in the examples below.\n\n### 2. Events Naming Consistency\n\nWe enforce a validation to make sure all the events sent are an instance of the class set in config key `laravel-mixpanel.tracker.events`. This should be a string backed enum.  This is done to avoid event name inconsistency on mixpanel eg: `User Registered` and `User Created`\n\n### 3. User Auto-identification\n\nEnabled by default, we try early identification of the user using a user tracker (uuid). Every user is given a unique uuid which is saved in the database column defined in the config key `laravel-mixpanel.tracker.database_column`.\n\n### 4. Consumers Strategy\n\nConsumer strategies are also bridged with the [Mixpanel PHP SDK](https://github.com/mixpanel/mixpanel-php/tree/master/lib/ConsumerStrategies) Consumer Strategies. Additionally, we have also added an custom consumer implementation `dry` which uses the custom [`Secrethash\\Mixpanel\\Consumers\\DebugConsumer::class`](./config/laravel-mixpanel.php#L63). Currently these consumers are supported:\n\n| Consumer | Provider | Description | Live | Debugging |\n|----------|----------|-------------|------|-----------|\n|   `dry`  |  Custom  | Used for Dry Runs  | :x: | :white_check_mark: |\n| `socket` | Mixpanel | Socket Connection based consumer | :white_check_mark: | :white_check_mark: |\n|  `curl`  | Mixpanel | cUrl based consumer | :white_check_mark: | :white_check_mark: |\n|  `file`  | Mixpanel | File based consumer | :white_check_mark:| :white_check_mark:|\n\n\u003e Debugging can be enabled by setting config `laravel-mixpanel.debug.enabled` to `true`. More details in the [debugging section](#debugging)\n\n## Usage\n\n1. Tracking an event is as easy as:\n\n    ```php\n    use Secrethash\\Mixpanel\\Mixpanel;\n    use Secrethash\\Mixpanel\\Enums\\TrackingEvents;\n\n    $data = [\n        'registration_status' =\u003e 'success',\n        'account_status' =\u003e 'verified',\n    ];\n\n    Mixpanel::track(TrackingEvents::userRegistered, $data);\n    ```\n\n2. The config should to be updated to set according to the requirements. Most of the configurations can be updated from `.env`.\n3. A few key configurations can be set or overridden during Runtime for flexibility:\n\n    ```php\n    use Secrethash\\Mixpanel\\Mixpanel;\n    ...\n    class AppServiceProvider extends ServiceProvider\n    {\n        ...\n        public function boot()\n        {\n            ...\n            // Enable/disable tracking for specific cases\n            if (environment('testing')) {\n                Mixpanel::$track = false;\n            }\n\n            // Add additional User Identity Attributes or Overwrite the set attributes\n            Mixpanel::$identityAttr = array_merge(\n                Mixpanel::$identityAttr,\n                ['phone','status']\n            );\n\n            // Although this can be updated from the config in `laravel-mixpanel.tracker.database_column`,\n            // This can be useful to override the config value if needed\n            Mixpanel::$userIdentityKey = 'uuid';\n        }\n    }\n    ```\n\n4. The package also provides a lot of helpful integration details in the `php artisan about` command:\n\n    ```bash\n    php artisan about\n    ```\n\n    ```txt\n    Laravel Mixpanel Integration .................................................................  \n    Active .............................................................................. INACTIVE  \n    Current State ......................................... Tracking Disabled due to missing Token  \n    Debugging ........................................................................... DISABLED  \n    Mixpanel Consumer ..................................................................... socket  \n    Mixpanel Host ........................................................................ DEFAULT  \n    Mixpanel Token ......................................................................... UNSET  \n    User Identity Attributes ........................................... name, last_name, username  \n    User Identity Key ........................................................... mixpanel_tracker\n    ```\n\n## Examples\n\n### 1. Tracking an Order Successful Event\n\n- Order **Event**\n\n    ```php\n    \u003c?php\n\n    namespace App\\Events;\n\n    use App\\Models\\Order;\n    use Secrethash\\Mixpanel\\Contracts\\MixpanelEvent;\n    use Illuminate\\Broadcasting\\InteractsWithSockets;\n    use Illuminate\\Foundation\\Events\\Dispatchable;\n    use Illuminate\\Queue\\SerializesModels;\n\n    class OrderSuccessfulEvent implements MixpanelEvent\n    {\n        use Dispatchable, InteractsWithSockets, SerializesModels;\n\n        /**\n        * Create a new event instance.\n        *\n        * @return void\n        */\n        public function __construct(\n            public Order $order\n        ) {\n        }\n    }\n    ```\n\n- Order **Listener**\n\n    ```php\n    \u003c?php\n\n    namespace App\\Listeners;\n\n    use App\\Enums\\TrackingEvents;\n    use App\\Events\\OrderSuccessfulEvent;\n    use Secrethash\\Mixpanel\\Mixpanel;\n    use Secrethash\\Mixpanel\\Listeners\\BaseTrackingListener;\n\n    class OrderSuccessTrackingListener extends BaseTrackingListener\n    {\n        /**\n        * Handle the Event Listening\n        *\n        * @return void\n        */\n        public function handle(OrderSuccessfulEvent $event)\n        {\n            $order = $event-\u003eorder;\n\n            Mixpanel::track(TrackingEvents::OrderSuccessful, [\n                'order_id' =\u003e $order-\u003eid,\n                'seller' =\u003e [\n                    'id' =\u003e $order-\u003eproduct-\u003eseller?-\u003eid,\n                    'name' =\u003e $order-\u003eproduct-\u003eseller?-\u003efull_name,\n                ],\n                'amount' =\u003e $order-\u003eamount,\n                'currency' =\u003e $order-\u003ecurrency,\n                'status' =\u003e $order-\u003estatus,\n            ]);\n        }\n    }\n\n    ```\n\n- **Register the event and listener** by adding the mapping to `App\\Providers\\EventServiceProvider::$listen`\n\n    ```php\n    \u003c?php\n\n    namespace App\\Providers;\n\n    use Illuminate\\Foundation\\Support\\Providers\\EventServiceProvider;\n    use App\\Events\\OrderSuccessfulEvent;\n    use App\\Listeners\\OrderSuccessTrackingListener;\n\n    class EventServiceProvider extends EventServiceProvider\n    {\n        protected $listen = [\n            ...\n            OrderSuccessfulEvent::class =\u003e [\n                OrderSuccessTrackingListener::class,\n            ],\n        ];\n        ...\n    }\n    ```\n\n## Debugging\n\nAll the debugging consumers are custom implementations to make the development process a breeze. All the above mentioned [consumer strategies](#4-consumers-strategy) have custom debugging consumers implemented too.\n\nSetting the Mixpanel in debugging mode can be done by setting the `.env` variable `MIXPANEL_DEBUG=true`. Custom Debugging Consumers can also be added and replaced directly in the config `laravel-mixpanel.consumers.*`.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Shashwat Mishra](https://github.com/secrethash)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecrethash%2Flaravel-mixpanel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsecrethash%2Flaravel-mixpanel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecrethash%2Flaravel-mixpanel/lists"}