Filter out bots from stats

This commit is contained in:
Florine W. Dekker 2021-05-03 18:45:30 +02:00
parent b6365b113a
commit 4d6eae5f14
Signed by: FWDekker
GPG Key ID: 78B3EAF58145AF25
2 changed files with 8 additions and 2 deletions

View File

@ -6,6 +6,12 @@
*/
function goatcounter_record_hit(string $path)
{
if (isset($_SERVER["HTTP_USER_AGENT"])
&& preg_match("/bot|crawl|slurp|spider|mediapartners/i", $_SERVER["HTTP_USER_AGENT"])) {
return;
}
$token = file_get_contents(".goat.token");
$ch = curl_init();
@ -17,7 +23,7 @@ function goatcounter_record_hit(string $path)
"hits" => array(array(
"path" => $path,
"ip" => $_SERVER["REMOTE_ADDR"],
"ref" => $_SERVER["HTTP_REFERER"],
"ref" => $_SERVER["HTTP_REFERER"] ?? "",
"user_agent" => $_SERVER["HTTP_USER_AGENT"]
))
))

2
dist/index.php vendored
View File

@ -107,7 +107,7 @@ if ($target != null && !$needs_confirmation) {
$("#header").appendChild(header({title: "fwdkr.co"}));
$("#footer").appendChild(footer({
vcsURL: "https://git.fwdekker.com/FWDekker/fwdkr.co/",
version: "v1.3.1"
version: "v1.3.2"
}));
});
</script>