Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin committed Apr 4, 2024
1 parent 5a42a13 commit e58f18e
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ Apply the middleware to your web routes by appending it in the `withMiddleware`
})
```

You can also apply the middleware to specific routes or groups:

```php
use Pirsch\Http\Middleware\TrackPageview;
Route::middleware(TrackPageview::class)->group(function () {
Route::get('/', function () {
return view('welcome');
});
});
```
#### Manually
If you want to manually track pageviews instead, you can use the `Pirsch::track()` method.
Expand Down Expand Up @@ -74,7 +86,31 @@ Pirsch::track(
You can configure the `TrackPageview` middleware to exclude specific pages from being tracked.
Create a new middleware like this:
On a specific rouute, you can exclude pages by adding a `except` property to the middleware class:
```php
use Pirsch\Http\Middleware\TrackPageview;
Route::middleware(TrackPageview::class.':url/to/exclude/*')->group(function () {
Route::get('/', function () {
return view('welcome');
});
});
```
Multiple urls can be excluded by separating them with a comma:
```php
use Pirsch\Http\Middleware\TrackPageview;
Route::middleware(TrackPageview::class.':url/to/exclude/*,url/to/exclude2/*')->group(function () {
Route::get('/', function () {
return view('welcome');
});
});
```
To exclude pages globally, you can create a new middleware that extends the `TrackPageview` middleware and add an `except` property:
```php
namespace App\Http\Middleware;
Expand All @@ -89,7 +125,7 @@ class TrackPageview extends Middleware
* @var array<int,string>
*/
protected array $except = [
'url/to/exclude',
'url/to/exclude/*',
];
/**
Expand Down

0 comments on commit e58f18e

Please sign in to comment.