@@ -43,6 +43,18 @@ Apply the middleware to your web routes by appending it in the `withMiddleware`
4343})
4444` ` `
4545
46+ You can also apply the middleware to specific routes or groups:
47+
48+ ` ` ` php
49+ use Pirsch\H ttp\M iddleware\T rackPageview;
50+
51+ Route::middleware(TrackPageview::class)->group(function () {
52+ Route::get(' /' , function () {
53+ return view(' welcome' );
54+ });
55+ });
56+ ` ` `
57+
4658# ### Manually
4759
4860If you want to manually track pageviews instead, you can use the ` Pirsch::track()` method.
@@ -69,3 +81,74 @@ Pirsch::track(
6981 ],
7082);
7183` ` `
84+
85+ # ## Filter pages
86+
87+ You can configure the ` TrackPageview` middleware to exclude specific pages from being tracked.
88+
89+ On a specific rouute, you can exclude pages by adding a ` except` property to the middleware class:
90+
91+ ` ` ` php
92+ use Pirsch\H ttp\M iddleware\T rackPageview;
93+
94+ Route::middleware(TrackPageview::class.':url/to/exclude/*')->group(function () {
95+ Route::get(' /' , function () {
96+ return view(' welcome' );
97+ });
98+ });
99+ ` ` `
100+
101+ Multiple urls can be excluded by separating them with a comma:
102+
103+ ` ` ` php
104+ use Pirsch\H ttp\M iddleware\T rackPageview;
105+
106+ Route::middleware(TrackPageview::class.':url/to/exclude/*,url/to/exclude2/*')->group(function () {
107+ Route::get(' /' , function () {
108+ return view(' welcome' );
109+ });
110+ });
111+ ` ` `
112+
113+ To exclude pages globally, you can create a new middleware that extends the ` TrackPageview` middleware and add an ` except` property:
114+
115+ ` ` ` php
116+ namespace App\H ttp\M iddleware;
117+
118+ use Pirsch\H ttp\M iddleware\T rackPageview as Middleware;
119+
120+ class TrackPageview extends Middleware
121+ {
122+ /**
123+ * The URIs that should be excluded from tracking.
124+ *
125+ * @var array< int,string>
126+ * /
127+ protected array $except = [
128+ ' url/to/exclude/*' ,
129+ ];
130+
131+ /**
132+ * The Headers that should be excluded from tracking.
133+ *
134+ * @var array< int,string>
135+ * /
136+ protected array $exceptHeaders = [
137+ ' X-ExcludedHeader' ,
138+ ];
139+ }
140+ ` ` `
141+
142+ - ` except` is an array with all URIs paths taht you want to exclude from tracking.
143+ - ` exceptHeaders` is an array with all Headers that you want to exclude from tracking.
144+
145+ Then replace the ` TrackPageview` middleware with this one on your ` bootstrap/app.php` middleware configuration:
146+
147+ ` ` ` diff
148+ -> withMiddleware(function (Middleware $middleware ) {
149+ $middleware -> web(append: [
150+ - \P irsch\H ttp\M iddleware\T rackPageview::class,
151+ + \A pp\H ttp\M iddleware\T rackPageview::class,
152+ ]);
153+ })
154+ ` ` `
0 commit comments