update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
namespace Piwik\Plugins\CoreHome\Columns\Metrics;
|
||||
|
||||
use Piwik\DataTable\Row;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Plugin\ProcessedMetric;
|
||||
|
||||
/**
|
||||
* The average number of actions per visit. Calculated as:
|
||||
*
|
||||
* nb_actions / nb_visits
|
||||
*
|
||||
* nb_actions & nb_visits are calculated during archiving.
|
||||
*/
|
||||
class ActionsPerVisit extends ProcessedMetric
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'nb_actions_per_visit';
|
||||
}
|
||||
|
||||
public function compute(Row $row)
|
||||
{
|
||||
$actions = $this->getMetric($row, 'nb_actions');
|
||||
$visits = $this->getMetric($row, 'nb_visits');
|
||||
|
||||
return Piwik::getQuotientSafe($actions, $visits, $precision = 1);
|
||||
}
|
||||
|
||||
public function getTranslatedName()
|
||||
{
|
||||
return Piwik::translate('General_ColumnActionsPerVisit');
|
||||
}
|
||||
|
||||
public function getDependentMetrics()
|
||||
{
|
||||
return array('nb_actions', 'nb_visits');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
namespace Piwik\Plugins\CoreHome\Columns\Metrics;
|
||||
|
||||
use Piwik\DataTable\Row;
|
||||
use Piwik\Metrics\Formatter;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Plugin\ProcessedMetric;
|
||||
|
||||
/**
|
||||
* The average number of seconds spent on the site per visit. Calculated as:
|
||||
*
|
||||
* sum_visit_length / nb_visits
|
||||
*
|
||||
* sum_visit_length & nb_visits are calculated during archiving.
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class AverageTimeOnSite extends ProcessedMetric
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'avg_time_on_site';
|
||||
}
|
||||
|
||||
public function compute(Row $row)
|
||||
{
|
||||
$sumVisitLength = $this->getMetric($row, 'sum_visit_length');
|
||||
$nbVisits = $this->getMetric($row, 'nb_visits');
|
||||
|
||||
return Piwik::getQuotientSafe($sumVisitLength, $nbVisits, $precision = 0);
|
||||
}
|
||||
|
||||
public function format($value, Formatter $formatter)
|
||||
{
|
||||
return $formatter->getPrettyTimeFromSeconds($value);
|
||||
}
|
||||
|
||||
public function getTranslatedName()
|
||||
{
|
||||
return Piwik::translate('General_ColumnAvgTimeOnSite');
|
||||
}
|
||||
|
||||
public function getDependentMetrics()
|
||||
{
|
||||
return array('sum_visit_length', 'nb_visits');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
namespace Piwik\Plugins\CoreHome\Columns\Metrics;
|
||||
|
||||
use Piwik\DataTable\Row;
|
||||
use Piwik\Metrics\Formatter;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Plugin\ProcessedMetric;
|
||||
|
||||
/**
|
||||
* The percentage of visits that leave the site without visiting another page. Calculated
|
||||
* as:
|
||||
*
|
||||
* bounce_count / nb_visits
|
||||
*
|
||||
* bounce_count & nb_visits are calculated by an Archiver.
|
||||
*/
|
||||
class BounceRate extends ProcessedMetric
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'bounce_rate';
|
||||
}
|
||||
|
||||
public function getTranslatedName()
|
||||
{
|
||||
return Piwik::translate('General_ColumnBounceRate');
|
||||
}
|
||||
|
||||
public function getDependentMetrics()
|
||||
{
|
||||
return array('bounce_count', 'nb_visits');
|
||||
}
|
||||
|
||||
public function format($value, Formatter $formatter)
|
||||
{
|
||||
return $formatter->getPrettyPercentFromQuotient($value);
|
||||
}
|
||||
|
||||
public function compute(Row $row)
|
||||
{
|
||||
$bounceCount = $this->getMetric($row, 'bounce_count');
|
||||
$visits = $this->getMetric($row, 'nb_visits');
|
||||
|
||||
return Piwik::getQuotientSafe($bounceCount, $visits, $precision = 2);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
namespace Piwik\Plugins\CoreHome\Columns\Metrics;
|
||||
|
||||
use Piwik\DataTable\Row;
|
||||
use Piwik\Plugin\ProcessedMetric;
|
||||
|
||||
class CallableProcessedMetric extends ProcessedMetric
|
||||
{
|
||||
private $name;
|
||||
private $callback;
|
||||
private $dependentMetrics;
|
||||
|
||||
public function __construct($name, $callback, $dependentMetrics = array())
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->callback = $callback;
|
||||
$this->dependentMetrics = $dependentMetrics;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function compute(Row $row)
|
||||
{
|
||||
if ($this->callback) {
|
||||
return call_user_func($this->callback, $row);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTranslatedName()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getDependentMetrics()
|
||||
{
|
||||
return $this->dependentMetrics;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
namespace Piwik\Plugins\CoreHome\Columns\Metrics;
|
||||
|
||||
use Piwik\DataTable\Row;
|
||||
use Piwik\Metrics\Formatter;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Plugin\ProcessedMetric;
|
||||
|
||||
/**
|
||||
* The percent of visits that result in a conversion. Calculated as:
|
||||
*
|
||||
* nb_visits_converted / nb_visits
|
||||
*
|
||||
* nb_visits_converted & nb_visits are calculated by the archiving process.
|
||||
*/
|
||||
class ConversionRate extends ProcessedMetric
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'conversion_rate';
|
||||
}
|
||||
|
||||
public function getTranslatedName()
|
||||
{
|
||||
return Piwik::translate('General_ColumnConversionRate');
|
||||
}
|
||||
|
||||
public function getDependentMetrics()
|
||||
{
|
||||
return array('nb_visits_converted', 'nb_visits');
|
||||
}
|
||||
|
||||
public function format($value, Formatter $formatter)
|
||||
{
|
||||
return $formatter->getPrettyPercentFromQuotient($value);
|
||||
}
|
||||
|
||||
public function compute(Row $row)
|
||||
{
|
||||
$nbVisitsConverted = $this->getMetric($row, 'nb_visits_converted');
|
||||
$nbVisits = $this->getMetric($row, 'nb_visits');
|
||||
|
||||
return Piwik::getQuotientSafe($nbVisitsConverted, $nbVisits, $precision = 4);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\CoreHome\Columns\Metrics;
|
||||
|
||||
use Piwik\DataTable;
|
||||
use Piwik\DataTable\Row;
|
||||
use Piwik\Metrics\Formatter;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Plugin\Metric;
|
||||
use Piwik\Plugin\ProcessedMetric;
|
||||
|
||||
/**
|
||||
* Calculates evolution values for any other metric. An evolution is the percent change from a
|
||||
* point in the past to the present. They are computed as:
|
||||
*
|
||||
* (current value - value in past) / value in past
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class EvolutionMetric extends ProcessedMetric
|
||||
{
|
||||
/**
|
||||
* @var Metric|string
|
||||
*/
|
||||
private $wrapped;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $evolutionMetricName;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $quotientPrecision;
|
||||
|
||||
/**
|
||||
* @var DataTable
|
||||
*/
|
||||
private $pastData;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string|Metric $wrapped The metric used to calculate the evolution.
|
||||
* @param DataTable $pastData The data in the past to use when calculating evolutions.
|
||||
* @param string|false $evolutionMetricName The name of the evolution processed metric. Defaults to
|
||||
* $wrapped's name with `'_evolution'` appended.
|
||||
* @param int $quotientPrecision The percent's quotient precision.
|
||||
*/
|
||||
public function __construct($wrapped, DataTable $pastData, $evolutionMetricName = false, $quotientPrecision = 0)
|
||||
{
|
||||
$this->wrapped = $wrapped;
|
||||
$this->pastData = $pastData;
|
||||
|
||||
if (empty($evolutionMetricName)) {
|
||||
$wrappedName = $this->getWrappedName();
|
||||
$evolutionMetricName = $wrappedName . '_evolution';
|
||||
}
|
||||
|
||||
$this->evolutionMetricName = $evolutionMetricName;
|
||||
$this->quotientPrecision = $quotientPrecision;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return $this->evolutionMetricName;
|
||||
}
|
||||
|
||||
public function getTranslatedName()
|
||||
{
|
||||
return $this->wrapped instanceof Metric ? $this->wrapped->getTranslatedName() : $this->getName();
|
||||
}
|
||||
|
||||
public function compute(Row $row)
|
||||
{
|
||||
$columnName = $this->getWrappedName();
|
||||
$pastRow = $this->getPastRowFromCurrent($row);
|
||||
|
||||
$currentValue = $this->getMetric($row, $columnName);
|
||||
$pastValue = $pastRow ? $this->getMetric($pastRow, $columnName) : 0;
|
||||
|
||||
$dividend = $currentValue - $pastValue;
|
||||
$divisor = $pastValue;
|
||||
|
||||
if ($dividend == 0) {
|
||||
return 0;
|
||||
} else if ($divisor == 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return Piwik::getQuotientSafe($dividend, $divisor, $this->quotientPrecision + 2);
|
||||
}
|
||||
}
|
||||
|
||||
public function format($value, Formatter $formatter)
|
||||
{
|
||||
return $formatter->getPrettyPercentFromQuotient($value);
|
||||
}
|
||||
|
||||
public function getDependentMetrics()
|
||||
{
|
||||
return array($this->getWrappedName());
|
||||
}
|
||||
|
||||
protected function getWrappedName()
|
||||
{
|
||||
return $this->wrapped instanceof Metric ? $this->wrapped->getName() : $this->wrapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* public for Insights use.
|
||||
*/
|
||||
public function getPastRowFromCurrent(Row $row)
|
||||
{
|
||||
return $this->pastData->getRowFromLabel($row->getColumn('label'));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Plugins\CoreHome\Columns\Metrics;
|
||||
|
||||
use Piwik\DataTable;
|
||||
use Piwik\DataTable\Row;
|
||||
use Piwik\Metrics\Formatter;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Plugin\ProcessedMetric;
|
||||
use Piwik\Plugin\Report;
|
||||
|
||||
/**
|
||||
* Percent of visits in the whole table. Calculated as:
|
||||
*
|
||||
* nb_visits / sum(all nb_visits in table)
|
||||
*
|
||||
* nb_visits is calculated by core archiving process.
|
||||
*/
|
||||
class VisitsPercent extends ProcessedMetric
|
||||
{
|
||||
private $cachedTotalVisits = null;
|
||||
private $forceTotalVisits = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param int|null $totalVisits The forced value of total visits to use.
|
||||
*/
|
||||
public function __construct($totalVisits = null)
|
||||
{
|
||||
$this->forceTotalVisits = $totalVisits;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'nb_visits_percentage';
|
||||
}
|
||||
|
||||
public function getTranslatedName()
|
||||
{
|
||||
return Piwik::translate('General_ColumnPercentageVisits');
|
||||
}
|
||||
|
||||
public function compute(Row $row)
|
||||
{
|
||||
$visits = $this->getMetric($row, 'nb_visits');
|
||||
|
||||
return Piwik::getQuotientSafe($visits, $this->cachedTotalVisits, $precision = 2);
|
||||
}
|
||||
|
||||
public function format($value, Formatter $formatter)
|
||||
{
|
||||
return $formatter->getPrettyPercentFromQuotient($value);
|
||||
}
|
||||
|
||||
public function getDependentMetrics()
|
||||
{
|
||||
return array('nb_visits');
|
||||
}
|
||||
|
||||
public function beforeCompute($report, DataTable $table)
|
||||
{
|
||||
if ($this->forceTotalVisits === null) {
|
||||
$this->cachedTotalVisits = array_sum($this->getMetricValues($table, 'nb_visits'));
|
||||
} else {
|
||||
$this->cachedTotalVisits = $this->forceTotalVisits;
|
||||
}
|
||||
|
||||
return true; // always compute
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue