mirror of
https://github.com/DanielSiepmann/tracking.git
synced 2024-11-22 13:56:09 +01:00
Add first basic tracking for page views
This commit is contained in:
parent
cfb5b79404
commit
cece44c735
13 changed files with 460 additions and 0 deletions
91
Classes/Domain/Model/Pageview.php
Normal file
91
Classes/Domain/Model/Pageview.php
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DanielSiepmann\Tracking\Domain\Model;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
|
|
||||||
|
class Pageview
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $pageUid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SiteLanguage
|
||||||
|
*/
|
||||||
|
private $language;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \DateTimeImmutable
|
||||||
|
*/
|
||||||
|
private $crdate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $pageType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $url;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
int $pageUid,
|
||||||
|
SiteLanguage $language,
|
||||||
|
\DateTimeImmutable $crdate,
|
||||||
|
int $pageType,
|
||||||
|
string $url
|
||||||
|
) {
|
||||||
|
$this->pageUid = $pageUid;
|
||||||
|
$this->language = $language;
|
||||||
|
$this->crdate = $crdate;
|
||||||
|
$this->pageType = $pageType;
|
||||||
|
$this->url = $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPageUid(): int
|
||||||
|
{
|
||||||
|
return $this->pageUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLanguage(): SiteLanguage
|
||||||
|
{
|
||||||
|
return $this->language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCrdate(): \DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->crdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPageType(): int
|
||||||
|
{
|
||||||
|
return $this->pageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUrl(): string
|
||||||
|
{
|
||||||
|
return $this->url;
|
||||||
|
}
|
||||||
|
}
|
46
Classes/Domain/Pageview/Factory.php
Normal file
46
Classes/Domain/Pageview/Factory.php
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DanielSiepmann\Tracking\Domain\Pageview;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use DanielSiepmann\Tracking\Domain\Model\Pageview;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use TYPO3\CMS\Core\Routing\PageArguments;
|
||||||
|
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||||
|
|
||||||
|
class Factory implements FromRequest
|
||||||
|
{
|
||||||
|
public static function fromRequest(ServerRequestInterface $request): Pageview
|
||||||
|
{
|
||||||
|
return new PageView(
|
||||||
|
static::getRouting($request)->getPageId(),
|
||||||
|
$request->getAttribute('language'),
|
||||||
|
new \DateTimeImmutable(),
|
||||||
|
static::getRouting($request)->getPageType(),
|
||||||
|
(string) $request->getUri()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getRouting(ServerRequestInterface $request): PageArguments
|
||||||
|
{
|
||||||
|
return $request->getAttribute('routing');
|
||||||
|
}
|
||||||
|
}
|
30
Classes/Domain/Pageview/FromRequest.php
Normal file
30
Classes/Domain/Pageview/FromRequest.php
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DanielSiepmann\Tracking\Domain\Pageview;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use DanielSiepmann\Tracking\Domain\Model\Pageview;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
|
interface FromRequest
|
||||||
|
{
|
||||||
|
public static function fromRequest(ServerRequestInterface $request): Pageview;
|
||||||
|
}
|
53
Classes/Domain/Repository/Pageview.php
Normal file
53
Classes/Domain/Repository/Pageview.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DanielSiepmann\Tracking\Domain\Repository;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use DanielSiepmann\Tracking\Domain\Model\Pageview as Model;
|
||||||
|
use TYPO3\CMS\Core\Database\Connection;
|
||||||
|
|
||||||
|
class Pageview
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Connection
|
||||||
|
*/
|
||||||
|
private $connection;
|
||||||
|
|
||||||
|
public function __construct(Connection $connection)
|
||||||
|
{
|
||||||
|
$this->connection = $connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add(Model $pageview)
|
||||||
|
{
|
||||||
|
$this->connection->insert(
|
||||||
|
'tx_tracking_pageview',
|
||||||
|
[
|
||||||
|
'pid' => $pageview->getPageUid(),
|
||||||
|
'crdate' => $pageview->getCrdate()->format('U'),
|
||||||
|
'tstamp' => $pageview->getCrdate()->format('U'),
|
||||||
|
'type' => $pageview->getPageType(),
|
||||||
|
'sys_language_uid' => $pageview->getLanguage()->getLanguageId(),
|
||||||
|
'url' => $pageview->getUrl(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
51
Classes/Middleware/Pageview.php
Normal file
51
Classes/Middleware/Pageview.php
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DanielSiepmann\Tracking\Middleware;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use DanielSiepmann\Tracking\Domain\Pageview\Factory;
|
||||||
|
use DanielSiepmann\Tracking\Domain\Repository\Pageview as Repository;
|
||||||
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
use Psr\Http\Server\MiddlewareInterface;
|
||||||
|
use Psr\Http\Server\RequestHandlerInterface;
|
||||||
|
|
||||||
|
class Pageview implements MiddlewareInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Repository
|
||||||
|
*/
|
||||||
|
private $repository;
|
||||||
|
|
||||||
|
public function __construct(Repository $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function process(
|
||||||
|
ServerRequestInterface $request,
|
||||||
|
RequestHandlerInterface $handler
|
||||||
|
): ResponseInterface {
|
||||||
|
$this->repository->add(Factory::fromRequest($request));
|
||||||
|
|
||||||
|
return $handler->handle($request);
|
||||||
|
}
|
||||||
|
}
|
15
Configuration/RequestMiddlewares.php
Normal file
15
Configuration/RequestMiddlewares.php
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'frontend' => [
|
||||||
|
'tracking-pageview' => [
|
||||||
|
'target' => \DanielSiepmann\Tracking\Middleware\Pageview::class,
|
||||||
|
'before' => [
|
||||||
|
'typo3/cms-frontend/content-length-headers',
|
||||||
|
],
|
||||||
|
'after' => [
|
||||||
|
'typo3/cms-frontend/shortcut-and-mountpoint-redirect',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
20
Configuration/Services.yaml
Normal file
20
Configuration/Services.yaml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
services:
|
||||||
|
_defaults:
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
public: false
|
||||||
|
|
||||||
|
DanielSiepmann\Tracking\:
|
||||||
|
resource: '../Classes/*'
|
||||||
|
|
||||||
|
DanielSiepmann\DI\DatabaseConnection\Pageview:
|
||||||
|
factory:
|
||||||
|
- '@TYPO3\CMS\Core\Database\ConnectionPool'
|
||||||
|
- 'getConnectionForTable'
|
||||||
|
arguments:
|
||||||
|
- 'tx_tracking_pageview'
|
||||||
|
|
||||||
|
DanielSiepmann\Tracking\Domain\Repository\Pageview:
|
||||||
|
public: true
|
||||||
|
arguments:
|
||||||
|
- '@DanielSiepmann\DI\DatabaseConnection\Pageview'
|
71
Configuration/TCA/tx_tracking_pageview.php
Normal file
71
Configuration/TCA/tx_tracking_pageview.php
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'ctrl' => [
|
||||||
|
'label' => 'url',
|
||||||
|
'label_alt' => 'crdate',
|
||||||
|
'label_alt_force' => true,
|
||||||
|
'sortby' => 'crdate',
|
||||||
|
'tstamp' => 'tstamp',
|
||||||
|
'crdate' => 'crdate',
|
||||||
|
'cruser_id' => 'cruser_id',
|
||||||
|
'languageField' => 'sys_language_uid',
|
||||||
|
'title' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview',
|
||||||
|
'searchFields' => 'uid, url'
|
||||||
|
],
|
||||||
|
'interface' => [
|
||||||
|
'always_description' => 0,
|
||||||
|
'showRecordFieldList' => 'url, type, sys_language_uid, crdate, tstamp, crdate, cruser_id'
|
||||||
|
],
|
||||||
|
'types' => [
|
||||||
|
'0' => [
|
||||||
|
'showitem' => 'sys_language_uid, pid, url, type, crdate',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'columns' => [
|
||||||
|
'pid' => [
|
||||||
|
'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview.pid',
|
||||||
|
'config' => [
|
||||||
|
'type' => 'select',
|
||||||
|
'readOnly' => true,
|
||||||
|
'renderType' => 'selectSingle',
|
||||||
|
'foreign_table' => 'pages',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'crdate' => [
|
||||||
|
'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview.crdate',
|
||||||
|
'config' => [
|
||||||
|
'type' => 'input',
|
||||||
|
'eval' => 'datetime',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'sys_language_uid' => [
|
||||||
|
'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview.sys_language',
|
||||||
|
'config' => [
|
||||||
|
'type' => 'select',
|
||||||
|
'renderType' => 'selectSingle',
|
||||||
|
'foreign_table' => 'sys_language',
|
||||||
|
'items' => [
|
||||||
|
['LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview.sys_language.0', 0],
|
||||||
|
],
|
||||||
|
'readOnly' => true,
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'type' => [
|
||||||
|
'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview.type',
|
||||||
|
'config' => [
|
||||||
|
'type' => 'input',
|
||||||
|
'readOnly' => true,
|
||||||
|
'eval' => 'int',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'url' => [
|
||||||
|
'label' => 'LLL:EXT:tracking/Resources/Private/Language/locallang_tca.xlf:table.pageview.url',
|
||||||
|
'config' => [
|
||||||
|
'readOnly' => true,
|
||||||
|
'type' => 'input',
|
||||||
|
'size' => 50,
|
||||||
|
'max' => 255,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
29
Resources/Private/Language/locallang_tca.xlf
Normal file
29
Resources/Private/Language/locallang_tca.xlf
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
|
||||||
|
<file source-language="en" datatype="plaintext">
|
||||||
|
<header/>
|
||||||
|
<body>
|
||||||
|
<trans-unit id="table.pageview">
|
||||||
|
<source>Pageview</source>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="table.pageview.pid">
|
||||||
|
<source>Page</source>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="table.pageview.url">
|
||||||
|
<source>URL</source>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="table.pageview.sys_language">
|
||||||
|
<source>System language</source>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="table.pageview.sys_language.0">
|
||||||
|
<source>Default system language</source>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="table.pageview.crdate">
|
||||||
|
<source>Date + Time</source>
|
||||||
|
</trans-unit>
|
||||||
|
<trans-unit id="table.pageview.type">
|
||||||
|
<source>Pagetype</source>
|
||||||
|
</trans-unit>
|
||||||
|
</body>
|
||||||
|
</file>
|
||||||
|
</xliff>
|
26
composer.json
Normal file
26
composer.json
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"name": "danielsiepmann/tracking",
|
||||||
|
"description": "Tracking for TYPO3",
|
||||||
|
"type": "typo3-cms-extension",
|
||||||
|
"license": "GPL-2.0-or-later",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Daniel Siepmann",
|
||||||
|
"email": "coding@daniel-siepmann.de"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"DanielSiepmann\\Tracking\\": "Classes/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": "^7.3.0",
|
||||||
|
"typo3/cms-core": "10.x-dev"
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"typo3/cms": {
|
||||||
|
"extension-key": "tracking"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
ext_emconf.php
Normal file
21
ext_emconf.php
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
$EM_CONF[$_EXTKEY] = [
|
||||||
|
'title' => 'Tracking',
|
||||||
|
'description' => 'Tracks page visits in TYPO3.',
|
||||||
|
'category' => 'fe',
|
||||||
|
'state' => 'stable',
|
||||||
|
'uploadfolder' => 0,
|
||||||
|
'createDirs' => '',
|
||||||
|
'clearCacheOnLoad' => 0,
|
||||||
|
'author' => 'Daniel Siepmann',
|
||||||
|
'author_email' => 'coding@daniel-siepmann.de',
|
||||||
|
'author_company' => '',
|
||||||
|
'version' => '1.0.0',
|
||||||
|
'constraints' => [
|
||||||
|
'depends' => [
|
||||||
|
'core' => '',
|
||||||
|
],
|
||||||
|
'conflicts' => [],
|
||||||
|
'suggests' => [],
|
||||||
|
],
|
||||||
|
];
|
3
ext_localconf.php
Normal file
3
ext_localconf.php
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_tracking_pageview');
|
4
ext_tables.sql
Normal file
4
ext_tables.sql
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
CREATE TABLE tx_tracking_pageview (
|
||||||
|
url text,
|
||||||
|
type int(11) unsigned DEFAULT '0' NOT NULL,
|
||||||
|
);
|
Loading…
Reference in a new issue