Skip to content

Commit 1402e51

Browse files
author
ziming
committed
Documentation improvements
1 parent 104c508 commit 1402e51

File tree

4 files changed

+72
-19
lines changed

4 files changed

+72
-19
lines changed

README.md

+42-13
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77

88
Laravel Package for Statsig. A Feature Gate & A/B Testing Platform with a somewhat decent free tier
99

10-
This package is still very early in development, but I have used it on a few small production sites for a while already.
10+
This package is still very early in development, but I have used it on a few small production sites for a while.
1111

12-
If you have used in production, it would be great to let me know any feedback :)
12+
If you have used in production, it would be great to let me know :)
1313

1414
It is basically a wrapper around the [Statsig PHP SDK](https://docs.statsig.com/server/phpSDK)
1515

1616
## Support us
1717

18-
The following features are being considered for the future. If any of it interest you, feel free to submit a PR.
18+
The following features are being considered for the future. Feel free to suggest or PR others
19+
feel free to submit a PR.
1920

20-
- New Adapters
21-
- New Middlewares
21+
- Custom IDs Support
2222
- More Convenience Traits & Methods
2323
- HTTP & Console API support
24-
- Octane/Vapor/Serverless Support (Probably far in the future)
24+
- Octane/Vapor/Serverless Support (It probably already works but it is not confirmed)
2525

2626
Donations are welcomed too as an alternative. Anything goes.
2727

@@ -74,13 +74,17 @@ return [
7474
'secret' => env('STATSIG_SECRET_KEY'),
7575

7676
'data_adapter' => LocalFileDataAdapter::class,
77+
78+
// arguments to the Data Adapter class constructor
7779
'data_adapter_arguments' => [
78-
// '/tmp/statsig/', leave blank for the default directory
80+
// '/tmp/statsig/', // empty array for the default directory for the default Data Adapter
7981
],
8082

8183
'logging_adapter' => LocalFileLoggingAdapter::class,
84+
85+
// arguments to the Logging Adapter class constructor
8286
'logging_adapter_arguments' => [
83-
// '/tmp/statsig.logs', leave blank for the default file path
87+
// '/tmp/statsig.logs', // empty array for the default file path for the default Logging Adapter
8488
],
8589
];
8690
```
@@ -123,6 +127,14 @@ LaravelStatsigUserConfiguration::setConversionCallable(function (User $laravelUs
123127

124128
$statsigEvent = new LaravelStatsigEvent('event_name');
125129

130+
// Giving it a value is optional
131+
$statsigEvent->setValue('string-or-float-or-int-or-whatever-primitive-type');
132+
133+
// Extra event metadata is optional too. See the official Statsig docs on how many you can send
134+
$statsigEvent->setMetadata([
135+
'key' => 'value'
136+
]);
137+
126138
// You can also use this convenience method
127139
LaravelStatsig::logEventWithAuthUser($statsigEvent);
128140

@@ -135,11 +147,17 @@ A handy blade directive is also provided to check against Statsig Feature Gates
135147

136148
It is confusingly named in all lowercase to match the official laravel naming conventions for blade directives.
137149

138-
Currently it can only be used if the user is logged in. Do not use it for your guest pages for now.
139-
140150
```blade
141151
@statsigcheckgate('gate_name')
142-
<p>This is shown if this statsig gate return true</p>
152+
<p>This is shown if this statsig gate return true for the authenticated user</p>
153+
@endstatsigcheckgate
154+
155+
@statsigcheckgate('gate_name', 'user-identifier')
156+
<p>This is usually used for guest user but can be ur authenticated user identifier too</p>
157+
@endstatsigcheckgate
158+
159+
@statsigcheckgate('gate_name', $user)
160+
<p>$user can be a StatsigUser or a laravel user instance</p>
143161
@endstatsigcheckgate
144162
```
145163

@@ -149,15 +167,26 @@ It is named in snake case, following laravel naming conventions for global helpe
149167
Like the blade directive, currently it can only be used if the user is logged in.
150168

151169
```blade
152-
<div class="{{ statsig_check_gate('awesome_feature') ? 'border-green' : '' }}">
170+
<div class="{{ statsig_check_gate('gate_name') ? 'border-red' : '' }}">
171+
The Authenticated user will be used to check if it passes this gate
172+
</div>
173+
174+
<div class="{{ statsig_check_gate('gate_name', 'user-identifier') ? 'border-red' : '' }}">
175+
This is usually used for guest user but can be ur authenticated user identifier too
176+
</div>
177+
178+
<div class="{{ statsig_check_gate('gate_name', $user) ? 'border-red' : '' }}">
179+
Use this is you want to pass in a statsig user or laravel user instance
153180
</div>
154181
```
155182
## Testing
156183

184+
No tests currently, feel free to PR
185+
157186
```bash
158187
composer test
159188
```
160-
## Userful References
189+
## Useful References
161190

162191
Below are links to some good reads that I think would benefit you in getting started:
163192

config/statsig.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
'secret' => env('STATSIG_SECRET_KEY', ''),
1111

1212
'data_adapter' => LocalFileDataAdapter::class,
13+
14+
// arguments to the Data Adapter class constructor
1315
'data_adapter_arguments' => [
14-
// '/tmp/statsig/', leave blank for the default directory
16+
// '/tmp/statsig/', // empty array for the default directory for the default Data Adapter
1517
],
1618

1719
'logging_adapter' => LocalFileLoggingAdapter::class,
20+
21+
// arguments to the Logging Adapter class constructor
1822
'logging_adapter_arguments' => [
19-
// '/tmp/statsig.logs', leave blank for the default file path
23+
// '/tmp/statsig.logs', // empty array for the default file path for the default Logging Adapter
2024
],
2125
];

src/LaravelStatsigServiceProvider.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace Ziming\LaravelStatsig;
66

7+
use Illuminate\Contracts\Auth\Authenticatable;
78
use Illuminate\Support\Facades\Auth;
89
use Illuminate\Support\Facades\Blade;
910
use Spatie\LaravelPackageTools\Package;
1011
use Spatie\LaravelPackageTools\PackageServiceProvider;
12+
use Statsig\StatsigUser;
1113
use Ziming\LaravelStatsig\Commands\StatsigSendCommand;
1214
use Ziming\LaravelStatsig\Commands\StatsigSyncCommand;
1315
use Ziming\LaravelStatsig\Facades\LaravelStatsig;
@@ -32,8 +34,16 @@ public function configurePackage(Package $package): void
3234

3335
public function packageBooted(): void
3436
{
35-
Blade::if('statsigcheckgate', function (string $gateName) {
36-
return LaravelStatsig::checkGate(Auth::user(), $gateName);
37+
Blade::if('statsigcheckgate', function (string $gateName, string|StatsigUser|Authenticatable $userOrUserId = null) {
38+
if ($userOrUserId === null) {
39+
return LaravelStatsig::checkGate(Auth::user(), $gateName);
40+
}
41+
42+
if (is_string($userOrUserId)) {
43+
$userOrUserId = StatsigUser::withUserID($userOrUserId);
44+
}
45+
46+
return LaravelStatsig::checkGate($userOrUserId, $gateName);
3747
});
3848
}
3949
}

src/helpers.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22

33
declare(strict_types=1);
44

5+
use Illuminate\Contracts\Auth\Authenticatable;
56
use Illuminate\Support\Facades\Auth;
7+
use Statsig\StatsigUser;
68
use Ziming\LaravelStatsig\Facades\LaravelStatsig;
79

810
if (! function_exists('statsig_check_gate')) {
9-
function statsig_check_gate(string $name): bool
11+
function statsig_check_gate(string $gateName, string|StatsigUser|Authenticatable $userOrUserId = null): bool
1012
{
11-
return LaravelStatsig::checkGate(Auth::user(), $name);
13+
if ($userOrUserId === null) {
14+
return LaravelStatsig::checkGate(Auth::user(), $gateName);
15+
}
16+
17+
if (is_string($userOrUserId)) {
18+
$userOrUserId = StatsigUser::withUserID($userOrUserId);
19+
}
20+
21+
return LaravelStatsig::checkGate($userOrUserId, $gateName);
1222
}
1323
}

0 commit comments

Comments
 (0)