Piwik\Plugin\
The base class that should be extended by plugins that compute their own analytics data.
Descendants should implement the aggregateDayReport() and aggregateMultipleReports() methods.
Both of these methods should persist analytics data using the ArchiveProcessor instance returned by getProcessor(). The aggregateDayReport() method should compute analytics data using the LogAggregator instance returned by getLogAggregator().
Extending Archiver
class MyArchiver extends Archiver
{
public function aggregateDayReport()
{
$logAggregator = $this->getLogAggregator();
$data = $logAggregator->queryVisitsByDimension(...);
$dataTable = new DataTable();
$dataTable->addRowsFromSimpleArray($data);
$archiveProcessor = $this->getProcessor();
$archiveProcessor->insertBlobRecords('MyPlugin_myReport', $dataTable->getSerialized(500));
}
public function aggregateMultipleReports()
{
$archiveProcessor = $this->getProcessor();
$archiveProcessor->aggregateDataTableRecords('MyPlugin_myReport', 500);
}
}
The abstract class defines the following methods:
__construct()
— Constructor.aggregateDayReport()
— Archives data for a day period.aggregateMultipleReports()
— Archives data for a non-day period.getProcessor()
ash; Returns a ArchiveProcessor instance that can be used to insert archive data for the period, segment and site we are archiving data for.getLogAggregator()
ash; Returns a LogAggregator instance that can be used to aggregate log table rows for this period, segment and site.disable()
isEnabled()
— Whether this Archiver should be used or not.shouldRunEvenWhenNoVisits()
— By overwriting this method and returning true, a plugin archiver can force the archiving to run even when there was no visit for the website/date/period/segment combination (by default, archivers are skipped when there is no visit).__construct()
Constructor.
$processor
(ArchiveProcessor
) —
The ArchiveProcessor instance to use when persisting archive data.aggregateDayReport()
Archives data for a day period.
Implementations of this method should do more computation intensive activities such as aggregating data across log tables. Since this method only deals w/ data logged for a day, aggregating individual log table rows isn't a problem. Doing this for any larger period, however, would cause performance degradation.
Aggregate log table rows using a LogAggregator instance. Get a LogAggregator instance using the getLogAggregator() method.
aggregateMultipleReports()
Archives data for a non-day period.
Implementations of this method should only aggregate existing reports of subperiods of the current period. For example, it is more efficient to aggregate reports for each day of a week than to aggregate each log entry of the week.
Use ArchiveProcessor::aggregateNumericMetrics() and ArchiveProcessor::aggregateDataTableRecords() to aggregate archived reports. Get the ArchiveProcessor instance using the getProcessor() method.
getProcessor()
Returns a ArchiveProcessor instance that can be used to insert archive data for the period, segment and site we are archiving data for.
ArchiveProcessor
value.getLogAggregator()
Returns a LogAggregator instance that can be used to aggregate log table rows for this period, segment and site.
LogAggregator
value.disable()
isEnabled()
Whether this Archiver should be used or not.
bool
value.shouldRunEvenWhenNoVisits()
By overwriting this method and returning true, a plugin archiver can force the archiving to run even when there was no visit for the website/date/period/segment combination (by default, archivers are skipped when there is no visit).
bool
value.