Skip to content

Commit 22136fe

Browse files
committed
Add config option to ignore paths
1 parent dbd36bd commit 22136fe

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

app/Http/Middleware/AnalyticsMiddleware.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ public function handle(Request $request, Closure $next)
2727

2828
// Use the terminate method to execute code after the response is sent.
2929
app()->terminating(function () use ($request) {
30+
$path = $request->path();
31+
$excludedPaths = Config::get('analytics.excluded_paths', []);
32+
33+
// Check if the current path matches any excluded paths
34+
foreach ($excludedPaths as $excludedPath) {
35+
if (str_is($excludedPath, $path)) {
36+
return;
37+
}
38+
}
39+
3040
PageView::fromRequest($request);
3141
});
3242

config/analytics.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,20 @@
3636
*/
3737
'view_count_cache_duration' => 3600, // 1 hour
3838

39+
/*
40+
|--------------------------------------------------------------------------
41+
| Excluded Paths
42+
|--------------------------------------------------------------------------
43+
|
44+
| List of paths that should be excluded from analytics tracking.
45+
| Supports wildcards using * (e.g. 'api/*', 'admin/*').
46+
|
47+
*/
48+
'excluded_paths' => [
49+
// Examples:
50+
// 'api/*',
51+
// 'admin/*',
52+
// 'health-check',
53+
],
54+
3955
];

0 commit comments

Comments
 (0)