قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-22 06:57:53 +00:00

* Add missing metric tooltips to real time report * Add documentation for revenue per visit column * Correctly set available metrics for user location reports * Add metric documentation for nb_visits_converted * Adds metric documentation for nb_visits_percentage * Add missing metric documentations for custom dimensions * Fix bounce rate metric documentation for entry page urls report * Fix visits / unique visitors metric documentation in event reports * Fix visits percentage metric documentation * Adds documentation for conversions metric * Adjust metric documentation for ecommerce product reports * updates expected test files tests * prefer using default documentation for glossary * Change how documentation in metric glossary are computed * use unique ids for xss test metrics * updates expected UI test files * Add metric documentation for conversions in pages reports * Improve conversion metric documentation * updates expected test files * Apply suggestions from code review Co-authored-by: Michal Kleiner <michal@innocraft.com> * updates expected test files * fix cs --------- Co-authored-by: Michal Kleiner <michal@innocraft.com>
89 خطوط
2.1 KiB
PHP
89 خطوط
2.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Matomo - free/libre analytics platform
|
|
*
|
|
* @link https://matomo.org
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
|
*/
|
|
|
|
namespace Piwik\Plugins\CoreHome\Columns\Metrics;
|
|
|
|
use Piwik\Columns\Dimension;
|
|
use Piwik\DataTable;
|
|
use Piwik\DataTable\Row;
|
|
use Piwik\Metrics\Formatter;
|
|
use Piwik\Piwik;
|
|
use Piwik\Plugin\ProcessedMetric;
|
|
|
|
/**
|
|
* 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 getDocumentation()
|
|
{
|
|
return Piwik::translate('General_ColumnPercentageVisitsDocumentation');
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
public function getSemanticType(): ?string
|
|
{
|
|
return Dimension::TYPE_PERCENT;
|
|
}
|
|
}
|