Skip to content

Commit 59df15f

Browse files
committed
Add optional AJAX exceptions
1 parent 184a28d commit 59df15f

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

bin/Visits.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ class Visits extends \Tatter\Visits\Config\Visits
2727
// how many minutes before a visit counts as new instead of incrementing a previous view count
2828
// set to zero to record each visit as its own page view (not recommended)
2929
public $resetMinutes = 60;
30+
31+
// Whether to ignore AJAX requests when recording
32+
public $ignoreAjax = true;
3033
}

src/Config/Visits.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ class Visits extends BaseConfig
1414
// how many minutes before a visit counts as new instead of incrementing a previous view count
1515
// set to zero to record each page view as unique (not recommended)
1616
public $resetMinutes = 60;
17+
18+
// Whether to ignore AJAX requests when recording
19+
public $ignoreAjax = true;
1720
}

src/Visits.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public function __construct(BaseConfig $config, $db = null)
8787
// add a new visit, or increase the view count on an existing one
8888
public function record()
8989
{
90+
// Check for ignored AJAX requests
91+
if (Services::request()->isAJAX() && $this->config->ignoreAjax)
92+
return;
93+
9094
$visits = new VisitModel();
9195
$visit = new Visit();
9296

0 commit comments

Comments
 (0)