{"id":26849620,"url":"https://github.com/ziming/laravel-statsig","last_synced_at":"2026-03-17T20:00:33.040Z","repository":{"id":171844482,"uuid":"648307236","full_name":"ziming/laravel-statsig","owner":"ziming","description":"Laravel Package for Statsig","archived":false,"fork":false,"pushed_at":"2025-11-25T03:11:15.000Z","size":102,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-28T13:07:16.121Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"https://statsig.com/updates#6/12/2023","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/ziming.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["ziming"]}},"created_at":"2023-06-01T17:04:35.000Z","updated_at":"2025-11-25T03:11:12.000Z","dependencies_parsed_at":"2023-11-29T06:30:25.029Z","dependency_job_id":"d0ab22f3-e42e-4535-a4ad-b94229835db2","html_url":"https://github.com/ziming/laravel-statsig","commit_stats":null,"previous_names":["ziming/laravel-statsig"],"tags_count":20,"template":false,"template_full_name":"spatie/package-skeleton-laravel","purl":"pkg:github/ziming/laravel-statsig","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziming%2Flaravel-statsig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziming%2Flaravel-statsig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziming%2Flaravel-statsig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziming%2Flaravel-statsig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ziming","download_url":"https://codeload.github.com/ziming/laravel-statsig/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziming%2Flaravel-statsig/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30630001,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T17:32:55.572Z","status":"ssl_error","status_checked_at":"2026-03-17T17:32:38.732Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["hacktoberfest"],"created_at":"2025-03-30T21:37:02.577Z","updated_at":"2026-03-17T20:00:33.012Z","avatar_url":"https://github.com/ziming.png","language":"PHP","funding_links":["https://github.com/sponsors/ziming"],"categories":[],"sub_categories":[],"readme":"# laravel-statsig\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/ziming/laravel-statsig.svg?style=flat-square)](https://packagist.org/packages/ziming/laravel-statsig)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/ziming/laravel-statsig/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/ziming/laravel-statsig/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/ziming/laravel-statsig/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/ziming/laravel-statsig/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/ziming/laravel-statsig.svg?style=flat-square)](https://packagist.org/packages/ziming/laravel-statsig)\n\nLaravel Package for Statsig. A Feature Gate \u0026 A/B Testing Platform\n\nUpdate: As of Aug/Sept 2023, Statsig has decided to cut lots of features from their free tier. Which also mean that if you have a problem with the paid tier features, I will not be able to help you anymore as I am not a paid tier user.\n\n## Support us\n\nDonations are welcomed too as an alternative. Anything goes. \n\nYou can also let Stasig know that [this package referred you there](https://statsig.com/updates#6/12/2023)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require ziming/laravel-statsig\n```\n\nAdd the following 2 commands to your laravel project `app/Console/Kernel.php`\n\n```php\n\u003c?php\n\nnamespace App\\Console;\n\nuse Illuminate\\Console\\Scheduling\\Schedule;\nuse Ziming\\LaravelStatsig\\Commands\\StatsigSendCommand;\nuse Ziming\\LaravelStatsig\\Commands\\StatsigSyncCommand;\n\nclass Kernel extends ConsoleKernel\n{\n    /**\n     * Define the application's command schedule.\n     */\n    protected function schedule(Schedule $schedule): void\n    {\n        // https://docs.statsig.com/server/phpSDK#sync\n        $schedule-\u003ecommand(StatsigSyncCommand::class)-\u003eeveryMinute();\n        \n        // https://docs.statsig.com/server/phpSDK#send\n        $schedule-\u003ecommand(StatsigSendCommand::class)-\u003eeveryMinute();\n    }\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"statsig-config\"\n```\n\nThis is the contents of the published config file:\n\n```php\nuse Statsig\\Adapters\\LocalFileDataAdapter;\nuse Statsig\\Adapters\\LocalFileLoggingAdapter;\n\nreturn [\n    'secret' =\u003e env('STATSIG_SECRET_KEY'),\n\n    'data_adapter' =\u003e LocalFileDataAdapter::class,\n    \n    // arguments to the Data Adapter class constructor\n    'data_adapter_arguments' =\u003e [\n        // '/tmp/statsig/', // empty array for the default directory for the default Data Adapter\n    ],\n\n    'logging_adapter' =\u003e LocalFileLoggingAdapter::class,\n    \n    // arguments to the Logging Adapter class constructor\n    'logging_adapter_arguments' =\u003e [\n        // '/tmp/statsig.logs', // empty array for the default file path for the default Logging Adapter\n    ],\n];\n```\n\n## Usage\n\n```php\nuse Illuminate\\Support\\Facades\\App;\nuse Illuminate\\Foundation\\Auth\\User;\nuse Illuminate\\Support\\Facades\\Auth;\nuse Statsig\\StatsigUser;\nuse Ziming\\LaravelStatsig\\Facades\\LaravelStatsig;\nuse Ziming\\LaravelStatsig\\LaravelStatsigEvent;\nuse Ziming\\LaravelStatsig\\LaravelStatsigUserConfiguration;\n\n$laravelStatsig = new Ziming\\LaravelStatsig();\n$user = Auth::user();\n$laravelStatsig-\u003echeckGate($user, 'gate_name');\n\n// The Facade Version is fine too\nLaravelStatsig::checkGate($user, 'gate_name');\n\n// You can set add this to 1 of your ServiceProviders boot() method to\n// override the default laravel user to Statsig user conversion code too if you want\nLaravelStatsigUserConfiguration::setConversionCallable(function (User $laravelUser): StatsigUser {\n        $statsigUser = StatsigUser::withUserID((string) $laravelUser-\u003egetAuthIdentifier());\n        $statsigUser-\u003esetEmail($laravelUser-\u003egetEmailForVerification());\n        $statsigUser-\u003esetIP(request()-\u003eip());\n        $statsigUser-\u003esetLocale(App::currentLocale());\n        $statsigUser-\u003esetUserAgent(request()-\u003euserAgent());\n        \n        // $statsigUser-\u003esetCountry('US');\n        \n        return $statsigUser;\n});\n\n// Lastly you can also use LaravelStatsigEvent instead of StatsigEvent\n// as it accepts a laravel user object\n// See Useful References at the end of the read me for some best practices to follow for events naming conventions\n\n$statsigEvent = new LaravelStatsigEvent('event_name');\n\n// Giving it a value is optional\n$statsigEvent-\u003esetValue('string-or-float-or-int-or-whatever-primitive-type');\n\n// Extra event metadata is optional too. See the official Statsig docs on how many you can send\n$statsigEvent-\u003esetMetadata([\n    'key' =\u003e 'value' \n]);\n\n// You can also use this convenience method\nLaravelStatsig::logEventWithAuthUser($statsigEvent);\n\n// or this\n$statsigEvent-\u003esetUser(Auth::user());\n$laravelStatsig-\u003elogEvent($statsigEvent);\n```\n\nA handy blade directive is also provided to check against Statsig Feature Gates in your frontend blade templates\n\nIt is confusingly named in all lowercase to match the official laravel naming conventions for blade directives.\n\n```blade\n@statsigcheckgate('gate_name')\n    \u003cp\u003eThis is shown if this statsig gate return true for the authenticated user\u003c/p\u003e\n@endstatsigcheckgate\n\n@statsigcheckgate('gate_name', 'user-identifier')\n    \u003cp\u003eThis is usually used for guest user but can be ur authenticated user identifier too\u003c/p\u003e\n@endstatsigcheckgate\n\n@statsigcheckgate('gate_name', $user)\n    \u003cp\u003e$user can be a StatsigUser or a laravel user instance\u003c/p\u003e\n@endstatsigcheckgate\n```\n\nLastly, a helper function is also provided if you want to be even more concise in your blade templates.\nIt is named in snake case, following laravel naming conventions for global helper functions.\n\nLike the blade directive, currently it can only be used if the user is logged in.\n\n```blade\n\u003cdiv class=\"{{ statsig_check_gate('gate_name') ? 'border-red' : '' }}\"\u003e\nThe Authenticated user will be used to check if it passes this gate\n\u003c/div\u003e\n\n\u003cdiv class=\"{{ statsig_check_gate('gate_name', 'user-identifier') ? 'border-red' : '' }}\"\u003e\nThis is usually used for guest user but can be ur authenticated user identifier too\n\u003c/div\u003e\n\n\u003cdiv class=\"{{ statsig_check_gate('gate_name', $user) ? 'border-red' : '' }}\"\u003e\nUse this is you want to pass in a statsig user or laravel user instance\n\u003c/div\u003e\n```\n## Testing\n\nNo tests currently, feel free to PR\n\n```bash\ncomposer test\n```\n## Useful References\n\nBelow are links to some good reads that I think would benefit you in getting started:\n\n### Experimentation\n- https://www.geteppo.com/blog\n\n### Event Naming Best Practices\n- https://segment.com/academy/collecting-data/naming-conventions-for-clean-data/\n- https://davidwells.io/blog/clean-analytics\n- https://databeats.community/p/product-analytics-components-of-event-data\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](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- [ziming](https://github.com/ziming)\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%2Fziming%2Flaravel-statsig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fziming%2Flaravel-statsig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziming%2Flaravel-statsig/lists"}