Skip to content

Commit 95b70ed

Browse files
Add config to disable redirect hits tracking (#571)
1 parent 4117ac2 commit 95b70ed

5 files changed

Lines changed: 40 additions & 3 deletions

File tree

DOCUMENTATION.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,20 @@ Alternatively, you may store redirects in the database by changing the driver:
223223

224224
Then run `php please seo-pro:database-redirects` to publish the migration and import existing redirects.
225225

226+
#### Hit Tracking
227+
228+
Out of the box, SEO Pro tracks the number of hits and the timestamp of the last hit for each redirect. If you store redirects in flat files, this can lead to frequent file changes creating noise in version control.
229+
230+
You may disable hit tracking in the config:
231+
232+
```php
233+
// config/statamic/seo-pro.php
234+
235+
'redirects' => [
236+
'track_hits' => false,
237+
],
238+
```
239+
226240
### Multi-Site
227241

228242
Redirects and errors are scoped to individual sites. Each redirect belongs to a single site, and the source URL is stored relative to the site root. For example, a redirect with the source `/about` on the French site will only match requests to `example.com/fr/about` (or `example.fr/about`, depending on your site configuration).

config/seo-pro.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
'directory' => base_path('content/seo-pro/redirects'),
7070
'preserve_query_string' => true,
7171
'default_response_code' => 301,
72+
'track_hits' => true,
7273
'automatic_redirects' => [
7374
'enabled' => env('SEO_PRO_AUTOMATIC_REDIRECTS', false),
7475
'collections' => ['*'],

src/Redirects/HandleRedirects.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public function __invoke(Request $request)
2727
return;
2828
}
2929

30-
RecordRedirectHit::dispatch($redirect->id());
30+
if (config('statamic.seo-pro.redirects.track_hits', true)) {
31+
RecordRedirectHit::dispatch($redirect->id());
32+
}
3133

3234
return redirect(
3335
$this->resolveDestination($redirect, $path, $request),

src/Redirects/RedirectBlueprint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __invoke(): FieldsBlueprint
7171
'type' => 'integer',
7272
'display' => __('seo-pro::messages.hits'),
7373
'default' => 0,
74-
'listable' => true,
74+
'listable' => config('statamic.seo-pro.redirects.track_hits', true),
7575
'read_only' => true,
7676
'visibility' => 'hidden',
7777
],
@@ -82,7 +82,7 @@ public function __invoke(): FieldsBlueprint
8282
'type' => 'date',
8383
'display' => __('seo-pro::messages.last_hit_at'),
8484
'time_enabled' => true,
85-
'listable' => true,
85+
'listable' => config('statamic.seo-pro.redirects.track_hits', true),
8686
'read_only' => true,
8787
'visibility' => 'hidden',
8888
],

tests/Redirects/HandleRedirectsTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,26 @@ public function it_does_not_dispatch_a_redirect_hit_job_when_no_redirect_matches
181181
Queue::assertNotPushed(RecordRedirectHit::class);
182182
}
183183

184+
#[Test]
185+
public function it_does_not_dispatch_a_redirect_hit_job_when_tracking_is_disabled()
186+
{
187+
Queue::fake();
188+
189+
config(['statamic.seo-pro.redirects.track_hits' => false]);
190+
191+
Facades\Redirect::make()
192+
->id('abc')
193+
->source('/old-url')
194+
->destination('/new-url')
195+
->responseCode(301)
196+
->enabled(true)
197+
->save();
198+
199+
$this->get('/old-url')->assertRedirect('/new-url');
200+
201+
Queue::assertNotPushed(RecordRedirectHit::class);
202+
}
203+
184204
#[Test]
185205
public function it_dispatches_a_record_error_job_when_no_redirect_matches()
186206
{

0 commit comments

Comments
 (0)