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

Properties

This class defines the following properties:

$ARCHIVE_DEPENDENT

Signature

  • Its type is not specified.

Methods

The class defines the following methods:

__construct()

Constructor.

Signature

  • It accepts the following parameter(s):

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.

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.

Signature

  • It returns a array value.

doesPluginHaveRecordBuilders()

Signature

  • It accepts the following parameter(s):

    • $pluginName (string) —
  • It returns a bool value.