|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Matomo - free/libre analytics platform |
| 5 | + * |
| 6 | + * @link https://matomo.org |
| 7 | + * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | + */ |
| 9 | + |
| 10 | +declare(strict_types=1); |
| 11 | + |
| 12 | +namespace Piwik\Plugins\BotTracking; |
| 13 | + |
| 14 | +use Piwik\Archive; |
| 15 | +use Piwik\DataTable; |
| 16 | +use Piwik\DataTable\DataTableInterface; |
| 17 | +use Piwik\Piwik; |
| 18 | + |
| 19 | +class API extends \Piwik\Plugin\API |
| 20 | +{ |
| 21 | + /** |
| 22 | + * Returns a report about AI assistants crawling your site and how many hits each one generates. Depending on the provided secondary dimension |
| 23 | + * the subtable will either contain all requested page urls or document urls. |
| 24 | + * |
| 25 | + * @param string|int|int[] $idSite |
| 26 | + * @param null|'pages'|'documents' $secondaryDimension can be either `pages` (default) or `documents` |
| 27 | + * @return DataTable|DataTable\Map |
| 28 | + */ |
| 29 | + public function getAIAssistantRequests($idSite, string $period, string $date, bool $expanded = false, bool $flat = false, ?string $secondaryDimension = null): DataTableInterface |
| 30 | + { |
| 31 | + Piwik::checkUserHasViewAccess($idSite); |
| 32 | + |
| 33 | + $archiveName = Archiver::AI_ASSISTANTS_PAGES_RECORD; |
| 34 | + |
| 35 | + if ($secondaryDimension === 'documents') { |
| 36 | + $archiveName = Archiver::AI_ASSISTANTS_DOCUMENTS_RECORD; |
| 37 | + } |
| 38 | + |
| 39 | + $dataTable = Archive::createDataTableFromArchive($archiveName, $idSite, $period, $date, '', $expanded, $flat); |
| 40 | + |
| 41 | + // When flattening a report, remove all main table rows, where no subtable exists |
| 42 | + if ($flat) { |
| 43 | + $dataTable->filter(function (DataTable $table) { |
| 44 | + foreach ($table->getRows() as $key => $row) { |
| 45 | + if (!$row->getIdSubDataTable()) { |
| 46 | + $table->deleteRow($key); |
| 47 | + } |
| 48 | + } |
| 49 | + }); |
| 50 | + } |
| 51 | + |
| 52 | + return $dataTable; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @param string|int|int[] $idSite |
| 57 | + * @return DataTable|DataTable\Map |
| 58 | + */ |
| 59 | + public function getPageUrlsForAIAssistant($idSite, string $period, string $date, int $idSubtable): DataTableInterface |
| 60 | + { |
| 61 | + Piwik::checkUserHasViewAccess($idSite); |
| 62 | + |
| 63 | + return Archive::createDataTableFromArchive(Archiver::AI_ASSISTANTS_PAGES_RECORD, $idSite, $period, $date, '', false, false, $idSubtable); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @param string|int|int[] $idSite |
| 68 | + * @return DataTable|DataTable\Map |
| 69 | + */ |
| 70 | + public function getDocumentUrlsForAIAssistant($idSite, string $period, string $date, int $idSubtable): DataTableInterface |
| 71 | + { |
| 72 | + Piwik::checkUserHasViewAccess($idSite); |
| 73 | + |
| 74 | + return Archive::createDataTableFromArchive(Archiver::AI_ASSISTANTS_DOCUMENTS_RECORD, $idSite, $period, $date, '', false, false, $idSubtable); |
| 75 | + } |
| 76 | +} |
0 commit comments