Piwik\Plugin\

Archiver

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().

Examples

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);
    }
}

Methods

The abstract class defines the following methods:

__construct()

Constructor.

Signature

  • It accepts the following parameter(s):
    • $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.

Signature

  • It does not return anything or a mixed result.

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.

Signature

  • It does not return anything or a mixed result.

getProcessor()

Returns a ArchiveProcessor instance that can be used to insert archive data for the period, segment and site we are archiving data for.

Signature

getLogAggregator()

Returns a LogAggregator instance that can be used to aggregate log table rows for this period, segment and site.

Signature

disable()

Signature

  • It does not return anything or a mixed result.

isEnabled()

Whether this Archiver should be used or not.

Signature

  • It returns a 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).

Signature

  • It returns a bool value.