Add user agent to tracking

To enable fine grained filtering, and detect further bots / crawler to
block.
This commit is contained in:
Daniel Siepmann 2020-02-13 12:26:19 +01:00
parent cece44c735
commit 27819c73ef
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
6 changed files with 29 additions and 4 deletions

View file

@ -50,18 +50,25 @@ class Pageview
*/
private $url;
/**
* @var string
*/
private $userAgent;
public function __construct(
int $pageUid,
SiteLanguage $language,
\DateTimeImmutable $crdate,
int $pageType,
string $url
string $url,
string $userAgent
) {
$this->pageUid = $pageUid;
$this->language = $language;
$this->crdate = $crdate;
$this->pageType = $pageType;
$this->url = $url;
$this->userAgent = $userAgent;
}
public function getPageUid(): int
@ -88,4 +95,9 @@ class Pageview
{
return $this->url;
}
public function getUserAgent(): string
{
return $this->userAgent;
}
}

View file

@ -35,7 +35,8 @@ class Factory implements FromRequest
$request->getAttribute('language'),
new \DateTimeImmutable(),
static::getRouting($request)->getPageType(),
(string) $request->getUri()
(string) $request->getUri(),
$request->getHeader('User-Agent')[0] ?? ''
);
}

View file

@ -47,6 +47,7 @@ class Pageview
'type' => $pageview->getPageType(),
'sys_language_uid' => $pageview->getLanguage()->getLanguageId(),
'url' => $pageview->getUrl(),
'user_agent' => $pageview->getUserAgent(),
]
);
}

View file

@ -14,11 +14,11 @@ return [
],
'interface' => [
'always_description' => 0,
'showRecordFieldList' => 'url, type, sys_language_uid, crdate, tstamp, crdate, cruser_id'
'showRecordFieldList' => 'url, user_agent, type, sys_language_uid, crdate, tstamp, crdate, cruser_id'
],
'types' => [
'0' => [
'showitem' => 'sys_language_uid, pid, url, type, crdate',
'showitem' => 'sys_language_uid, pid, url, user_agent, type, crdate',
],
],
'columns' => [
@ -50,6 +50,13 @@ return [
'readOnly' => true,
]
],
'user_agent' => [
'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview.user_agent',
'config' => [
'type' => 'input',
'readOnly' => true,
],
],
'type' => [
'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview.type',
'config' => [

View file

@ -24,6 +24,9 @@
<trans-unit id="table.pageview.type">
<source>Pagetype</source>
</trans-unit>
<trans-unit id="table.pageview.user_agent">
<source>User agent</source>
</trans-unit>
</body>
</file>
</xliff>

View file

@ -1,4 +1,5 @@
CREATE TABLE tx_tracking_pageview (
url text,
user_agent text,
type int(11) unsigned DEFAULT '0' NOT NULL,
);