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);
}
}
This class defines the following properties:
$ARCHIVE_DEPENDENT
The 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).getDependentSegmentsToArchive()
— Returns a list of segments that should be pre-archived along with the segment currently being archived.doesPluginHaveRecordBuilders()
__construct()
Constructor.
It accepts the following parameter(s):
$processor
(ArchiveProcessor
) —
$pluginName
(string
|null
) —
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.getDependentSegmentsToArchive()
Returns a list of segments that should be pre-archived along with the segment currently being archived.
The segments in this list will be added to the current segment via an AND condition and archiving for the current plugin will be launched. This process will not recurse further.
If your plugin's API appends conditions to the requested segment when fetching data, you will want to use this method to make sure those segments get pre-archived. Otherwise, if browser archiving is disabled, the modified segments will appear to have no data.
To archive another plugin, use an array instead of a string segment, for example:
['plugin' => 'VisitsSummary', 'segment' => '...']
See the Goals and VisitFrequency plugins for examples.
array
value.doesPluginHaveRecordBuilders()
It accepts the following parameter(s):
$pluginName
(string
) —It returns a bool
value.