PDF rausgenommen

This commit is contained in:
aschwarz
2023-01-23 11:03:31 +01:00
parent 82d562a322
commit a6523903eb
28078 changed files with 4247552 additions and 2 deletions

View File

@ -0,0 +1,18 @@
<?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\Goals\Columns;
use Piwik\Columns\Dimension;
use Piwik\Piwik;
class DaysToConversion extends Dimension
{
protected $type = self::TYPE_NUMBER;
protected $nameSingular = 'Goals_DaysToConv';
}

View File

@ -0,0 +1,34 @@
<?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\Goals\Columns;
use Piwik\Columns\DimensionMetricFactory;
use Piwik\Columns\Join;
use Piwik\Columns\MetricsList;
use Piwik\Plugin\Dimension\ConversionDimension;
class IdGoal extends ConversionDimension
{
protected $columnName = 'idgoal';
protected $type = self::TYPE_TEXT;
protected $category = 'General_Visitors'; // todo move into goal category?
protected $nameSingular = 'General_VisitConvertedGoalId';
protected $segmentName = 'visitConvertedGoalId';
protected $acceptValues = '1, 2, 3, etc.';
public function configureMetrics(MetricsList $metricsList, DimensionMetricFactory $dimensionMetricFactory)
{
// do not create any metrics for this dimension, they don't really make much sense and are rather confusing
}
public function getDbColumnJoin()
{
return new Join\GoalNameJoin();
}
}

View File

@ -0,0 +1,61 @@
<?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\Goals\Columns\Metrics;
use Piwik\Archive\DataTableFactory;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugin\ProcessedMetric;
/**
* The average value for each order. Calculated as:
*
* revenue / nb_conversions
*
* revenue & nb_conversions are calculated by the Goals archiver.
*/
class AverageOrderRevenue extends ProcessedMetric
{
private $idSite;
public function getName()
{
return 'avg_order_revenue';
}
public function compute(Row $row)
{
$revenue = $this->getMetric($row, 'revenue');
$conversions = $this->getMetric($row, 'nb_conversions');
return Piwik::getQuotientSafe($revenue, $conversions, $precision = 2);
}
public function getTranslatedName()
{
return Piwik::translate('General_AverageOrderValue');
}
public function getDependentMetrics()
{
return array('revenue', 'nb_conversions');
}
public function format($value, Formatter $formatter)
{
return $formatter->getPrettyMoney($value, $this->idSite);
}
public function beforeFormat($report, DataTable $table)
{
$this->idSite = DataTableFactory::getSiteIdFromMetadata($table);
return !empty($this->idSite); // skip formatting if there is no site to get currency info from
}
}

View File

@ -0,0 +1,64 @@
<?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\Goals\Columns\Metrics;
use Piwik\Archive\DataTableFactory;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugin\ProcessedMetric;
use Piwik\Tracker\GoalManager;
/**
* The average price for each ecommerce order or abandoned cart. Calculated as:
*
* price / (orders or abandoned_carts)
*
* price, orders and abandoned_carts are calculated by the Goals archiver.
*/
class AveragePrice extends ProcessedMetric
{
private $idSite;
public function getName()
{
return 'avg_price';
}
public function getTranslatedName()
{
return Piwik::translate('General_AveragePrice');
}
public function compute(Row $row)
{
$price = $this->getMetric($row, 'price');
$orders = $this->getMetric($row, 'orders');
$abandonedCarts = $this->getMetric($row, 'abandoned_carts');
return Piwik::getQuotientSafe($price, $orders === false ? $abandonedCarts : $orders, GoalManager::REVENUE_PRECISION);
}
public function getDependentMetrics()
{
return array('price', 'orders', 'abandoned_carts');
}
public function format($value, Formatter $formatter)
{
return $formatter->getPrettyMoney($value, $this->idSite);
}
public function beforeFormat($report, DataTable $table)
{
$this->idSite = DataTableFactory::getSiteIdFromMetadata($table);
return !empty($this->idSite); // skip formatting if there is no site to get currency info from
}
}

View File

@ -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\Goals\Columns\Metrics;
use Piwik\DataTable\Row;
use Piwik\Piwik;
use Piwik\Plugin\ProcessedMetric;
/**
* The average amount of products in each order or abandoned cart. Calculated as:
*
* quantity / (orders or abandoned_carts)
*
* quantity, orders and abandoned_carts are calculated by the Goals archiver.
*/
class AverageQuantity extends ProcessedMetric
{
public function getName()
{
return 'avg_quantity';
}
public function getTranslatedName()
{
return Piwik::translate('General_AverageQuantity');
}
public function compute(Row $row)
{
$quantity = $this->getMetric($row, 'quantity');
$orders = $this->getMetric($row, 'orders');
$abandonedCarts = $this->getMetric($row, 'abandoned_carts');
return Piwik::getQuotientSafe($quantity, $orders === false ? $abandonedCarts : $orders, $precision = 1);
}
public function getDependentMetrics()
{
return array('quantity', 'orders', 'abandoned_carts');
}
}

View File

@ -0,0 +1,59 @@
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\Goals\Columns\Metrics;
use Piwik\DataTable\Row;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugins\Goals\Goals;
use Piwik\Tracker\GoalManager;
/**
* The conversion rate for a specific goal. Calculated as:
*
* goal's nb_conversions / nb_visits
*
* The goal's nb_conversions is calculated by the Goal archiver and nb_visits
* by the core archiving process.
*/
class GoalConversionRate extends GoalSpecificProcessedMetric
{
public function getName()
{
return Goals::makeGoalColumn($this->idGoal, 'conversion_rate');
}
public function getTranslatedName()
{
return Piwik::translate('Goals_ConversionRate', $this->getGoalName());
}
public function getDocumentation()
{
return Piwik::translate('Goals_ColumnConversionRateDocumentation', $this->getGoalNameForDocs());
}
public function getDependentMetrics()
{
return array('nb_visits', Goals::makeGoalColumn($this->idGoal, 'nb_conversions'));
}
public function format($value, Formatter $formatter)
{
return $formatter->getPrettyPercentFromQuotient($value);
}
public function compute(Row $row)
{
$nbVisits = $this->getMetric($row, 'nb_visits');
$conversions = $this->getMetric($row, Goals::makeGoalColumn($this->idGoal, 'nb_visits_converted'));
return Piwik::getQuotientSafe($conversions, $nbVisits, GoalManager::REVENUE_PRECISION + 2);
}
}

View File

@ -0,0 +1,69 @@
<?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\Goals\Columns\Metrics\GoalSpecific;
use Piwik\Archive\DataTableFactory;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Metrics;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecificProcessedMetric;
use Piwik\Plugins\Goals\Goals;
use Piwik\Tracker\GoalManager;
/**
* The average order revenue for a specific goal. Calculated as:
*
* goals' revenue / goal's nb_conversions
*/
class AverageOrderRevenue extends GoalSpecificProcessedMetric
{
public function getName()
{
return Goals::makeGoalColumn($this->idGoal, 'avg_order_revenue', false);
}
public function getTranslatedName()
{
return Piwik::translate('General_AverageOrderValue');
}
public function getDocumentation()
{
return Piwik::translate('Goals_ColumnAverageOrderRevenueDocumentation', $this->getGoalNameForDocs());
}
public function getDependentMetrics()
{
return array('goals');
}
public function compute(Row $row)
{
$mappingFromNameToIdGoal = Metrics::getMappingFromNameToIdGoal();
$goalMetrics = $this->getGoalMetrics($row);
$goalRevenue = $this->getMetric($goalMetrics, 'revenue', $mappingFromNameToIdGoal);
$conversions = $this->getMetric($goalMetrics, 'nb_conversions', $mappingFromNameToIdGoal);
return Piwik::getQuotientSafe($goalRevenue, $conversions, GoalManager::REVENUE_PRECISION);
}
public function format($value, Formatter $formatter)
{
return $formatter->getPrettyMoney($value, $this->idSite);
}
public function beforeFormat($report, DataTable $table)
{
$this->idSite = DataTableFactory::getSiteIdFromMetadata($table);
return !empty($this->idSite); // skip formatting if there is no site to get currency info from
}
}

View File

@ -0,0 +1,64 @@
<?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\Goals\Columns\Metrics\GoalSpecific;
use Piwik\DataTable\Row;
use Piwik\Metrics;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecificProcessedMetric;
use Piwik\Plugins\Goals\Goals;
use Piwik\Tracker\GoalManager;
/**
* The conversion rate for a specific goal. Calculated as:
*
* goal's nb_conversions / nb_visits
*
* The goal's nb_conversions is calculated by the Goal archiver and nb_visits
* by the core archiving process.
*/
class ConversionRate extends GoalSpecificProcessedMetric
{
public function getName()
{
return Goals::makeGoalColumn($this->idGoal, 'conversion_rate', false);
}
public function getTranslatedName()
{
return Piwik::translate('Goals_ConversionRate', $this->getGoalName());
}
public function getDocumentation()
{
return Piwik::translate('Goals_ColumnConversionRateDocumentation', $this->getGoalNameForDocs());
}
public function getDependentMetrics()
{
return array('goals');
}
public function format($value, Formatter $formatter)
{
return $formatter->getPrettyPercentFromQuotient($value);
}
public function compute(Row $row)
{
$mappingFromNameToIdGoal = Metrics::getMappingFromNameToIdGoal();
$goalMetrics = $this->getGoalMetrics($row);
$nbVisits = $this->getMetric($row, 'nb_visits');
$conversions = $this->getMetric($goalMetrics, 'nb_conversions', $mappingFromNameToIdGoal);
return Piwik::getQuotientSafe($conversions, $nbVisits, GoalManager::REVENUE_PRECISION + 2);
}
}

View File

@ -0,0 +1,44 @@
<?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\Goals\Columns\Metrics\GoalSpecific;
use Piwik\DataTable\Row;
use Piwik\Metrics;
use Piwik\Piwik;
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecificProcessedMetric;
use Piwik\Plugins\Goals\Goals;
/**
* The conversions for a specific goal. Returns the conversions for a single goal which
* is then treated as a new column.
*/
class Conversions extends GoalSpecificProcessedMetric
{
public function getName()
{
return Goals::makeGoalColumn($this->idGoal, 'nb_conversions', false);
}
public function getTranslatedName()
{
return Piwik::translate('Goals_Conversions', $this->getGoalNameForDocs());
}
public function getDependentMetrics()
{
return array('goals');
}
public function compute(Row $row)
{
$mappingFromNameToIdGoal = Metrics::getMappingFromNameToIdGoal();
$goalMetrics = $this->getGoalMetrics($row);
return (int) $this->getMetric($goalMetrics, 'nb_conversions', $mappingFromNameToIdGoal);
}
}

View File

@ -0,0 +1,49 @@
<?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\Goals\Columns\Metrics\GoalSpecific;
use Piwik\DataTable\Row;
use Piwik\Metrics;
use Piwik\Piwik;
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecificProcessedMetric;
use Piwik\Plugins\Goals\Goals;
/**
* The number of ecommerce order items for conversions of a goal. Returns the 'items'
* goal specific metric.
*/
class ItemsCount extends GoalSpecificProcessedMetric
{
public function getName()
{
return Goals::makeGoalColumn($this->idGoal, 'items', false);
}
public function getTranslatedName()
{
return Piwik::translate('General_PurchasedProducts');
}
public function getDocumentation()
{
return Piwik::translate('Goals_ColumnPurchasedProductsDocumentation', $this->getGoalNameForDocs());
}
public function getDependentMetrics()
{
return array('goals');
}
public function compute(Row $row)
{
$mappingFromNameToIdGoal = Metrics::getMappingFromNameToIdGoal();
$goalMetrics = $this->getGoalMetrics($row);
return (int) $this->getMetric($goalMetrics, 'items', $mappingFromNameToIdGoal);
}
}

View File

@ -0,0 +1,62 @@
<?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\Goals\Columns\Metrics\GoalSpecific;
use Piwik\Archive\DataTableFactory;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Metrics;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecificProcessedMetric;
use Piwik\Plugins\Goals\Goals;
/**
* Revenue for a specific goal.
*/
class Revenue extends GoalSpecificProcessedMetric
{
public function getName()
{
return Goals::makeGoalColumn($this->idGoal, 'revenue', false);
}
public function getTranslatedName()
{
return Piwik::translate('%s ' . Piwik::translate('General_ColumnRevenue'), $this->getGoalName());
}
public function getDocumentation()
{
return Piwik::translate('Goals_ColumnRevenueDocumentation', $this->getGoalNameForDocs());
}
public function getDependentMetrics()
{
return array('goals');
}
public function compute(Row $row)
{
$mappingFromNameToIdGoal = Metrics::getMappingFromNameToIdGoal();
$goalMetrics = $this->getGoalMetrics($row);
return (float) $this->getMetric($goalMetrics, 'revenue', $mappingFromNameToIdGoal);
}
public function format($value, Formatter $formatter)
{
return $formatter->getPrettyMoney($value, $this->idSite);
}
public function beforeFormat($report, DataTable $table)
{
$this->idSite = DataTableFactory::getSiteIdFromMetadata($table);
return !empty($this->idSite); // skip formatting if there is no site to get currency info from
}
}

View File

@ -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\Goals\Columns\Metrics\GoalSpecific;
use Piwik\Archive\DataTableFactory;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Metrics;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugins\Goals\Columns\Metrics\GoalSpecificProcessedMetric;
use Piwik\Plugins\Goals\Goals;
use Piwik\Tracker\GoalManager;
/**
* Revenue per visit for a specific goal. Calculated as:
*
* goal's revenue / (nb_visits or goal's nb_conversions depending on what is present in data)
*
* Goal revenue & nb_conversion are calculated by the Goals archiver.
*/
class RevenuePerVisit extends GoalSpecificProcessedMetric
{
public function getName()
{
return Goals::makeGoalColumn($this->idGoal, 'revenue_per_visit', false);
}
public function getTranslatedName()
{
return $this->getGoalName() . ' ' . Piwik::translate('General_ColumnValuePerVisit');
}
public function getDocumentation()
{
if ($this->idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) {
return Piwik::translate('Goals_ColumnAverageOrderRevenueDocumentation', $this->getGoalNameForDocs());
} else {
return Piwik::translate('Goals_ColumnRevenuePerVisitDocumentation', Piwik::translate('Goals_EcommerceAndGoalsMenu'));
}
}
public function getDependentMetrics()
{
return array('goals', 'nb_visits');
}
public function compute(Row $row)
{
$mappingFromNameToIdGoal = Metrics::getMappingFromNameToIdGoal();
$goalMetrics = $this->getGoalMetrics($row);
$nbVisits = $this->getMetric($row, 'nb_visits');
$conversions = $this->getMetric($goalMetrics, 'nb_conversions', $mappingFromNameToIdGoal);
$goalRevenue = (float) $this->getMetric($goalMetrics, 'revenue', $mappingFromNameToIdGoal);
return Piwik::getQuotientSafe($goalRevenue, $nbVisits == 0 ? $conversions : $nbVisits, GoalManager::REVENUE_PRECISION);
}
public function format($value, Formatter $formatter)
{
return $formatter->getPrettyMoney($value, $this->idSite);
}
public function beforeFormat($report, DataTable $table)
{
$this->idSite = DataTableFactory::getSiteIdFromMetadata($table);
return !empty($this->idSite); // skip formatting if there is no site to get currency info from
}
}

View File

@ -0,0 +1,100 @@
<?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\Goals\Columns\Metrics;
use Piwik\API\Request;
use Piwik\Common;
use Piwik\DataTable\Row;
use Piwik\Piwik;
use Piwik\Plugin\ProcessedMetric;
use Piwik\Tracker\GoalManager;
/**
* Base class for processed metrics that are calculated using metrics that are
* specific to certain goals.
*/
abstract class GoalSpecificProcessedMetric extends ProcessedMetric
{
/**
* The ID of the goal to calculate metrics for.
*
* @var int
*/
protected $idGoal;
/**
* The ID of the site the goal belongs to.
*
* @var int
*/
protected $idSite;
/**
* Constructor.
*
* @param int|null $idSite The ID of the site the goal belongs to. If supplied, affects the formatting
* and translated name of the metric.
* @param int $idGoal The ID of the goal to calculate metrics for.
*/
public function __construct($idSite, $idGoal)
{
$this->idSite = $idSite;
$this->idGoal = $idGoal;
}
protected function getGoalMetrics(Row $row)
{
$allGoalMetrics = $this->getMetric($row, 'goals');
if (isset($allGoalMetrics[$this->idGoal])) {
return $allGoalMetrics[$this->idGoal];
} else {
$alternateKey = 'idgoal=' . $this->idGoal;
if (isset($allGoalMetrics[$alternateKey])) {
return $allGoalMetrics[$alternateKey];
} elseif ($this->idGoal === Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) {
$alternateKey = GoalManager::IDGOAL_ORDER;
if (isset($allGoalMetrics[$alternateKey])) {
return $allGoalMetrics[$alternateKey];
}
} elseif ($this->idGoal === Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART) {
$alternateKey = GoalManager::IDGOAL_CART;
if (isset($allGoalMetrics[$alternateKey])) {
return $allGoalMetrics[$alternateKey];
}
} else {
return array();
}
}
}
protected function getGoalName()
{
if ($this->idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) {
return Piwik::translate('Goals_EcommerceOrder');
} else if ($this->idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART) {
return Piwik::translate('Goals_AbandonedCart');
}
if (isset($this->idSite)) {
$allGoals = Request::processRequest('Goals.getGoals', ['idSite' => $this->idSite, 'filter_limit' => '-1'], $default = []);
$goalName = @$allGoals[$this->idGoal]['name'];
return Common::sanitizeInputValue($goalName);
} else {
return "";
}
}
protected function getGoalNameForDocs()
{
$goalName = $this->getGoalName();
if ($goalName == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) {
$goalName = '"' . $goalName . '"';
}
return $goalName;
}
}

View File

@ -0,0 +1,54 @@
<?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\Goals\Columns\Metrics;
use Piwik\DataTable\Row;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugin\ProcessedMetric;
use Piwik\Tracker\GoalManager;
/**
* The conversion rate for ecommerce orders. Calculated as:
*
* (orders or abandoned_carts) / nb_visits
*
* orders and abandoned_carts are calculated by the Goals archiver.
*/
class ProductConversionRate extends ProcessedMetric
{
public function getName()
{
return 'conversion_rate';
}
public function getTranslatedName()
{
return Piwik::translate('General_ProductConversionRate');
}
public function format($value, Formatter $formatter)
{
return $formatter->getPrettyPercentFromQuotient($value);
}
public function compute(Row $row)
{
$orders = $this->getMetric($row, 'orders');
$abandonedCarts = $this->getMetric($row, 'abandoned_carts');
$visits = $this->getMetric($row, 'nb_visits');
return Piwik::getQuotientSafe($orders === false ? $abandonedCarts : $orders, $visits, GoalManager::REVENUE_PRECISION + 2);
}
public function getDependentMetrics()
{
return array('orders', 'abandoned_carts', 'nb_visits');
}
}

View File

@ -0,0 +1,84 @@
<?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\Goals\Columns\Metrics;
use Piwik\Archive\DataTableFactory;
use Piwik\DataTable;
use Piwik\DataTable\Row;
use Piwik\Metrics;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugin\ProcessedMetric;
use Piwik\Tracker\GoalManager;
/**
* The amount of revenue per visit (or per conversion if there are no visits). Calculated as:
*
* sum(revenue for all goals) / (nb_visits or nb_conversions if no visits)
*
* Goal revenue and nb_visits & nb_conversions are calculated by the archiving process.
*/
class RevenuePerVisit extends ProcessedMetric
{
private $idSite;
public function getName()
{
return 'revenue_per_visit';
}
public function getTranslatedName()
{
return Piwik::translate('General_ColumnValuePerVisit');
}
public function getDependentMetrics()
{
return array('revenue', 'nb_visits', 'nb_conversions','goals');
}
public function compute(Row $row)
{
$mappingFromNameToIdGoal = Metrics::getMappingFromNameToIdGoal();
$goals = $this->getMetric($row, 'goals') ?: array();
$revenue = 0;
foreach ($goals as $goalId => $goalMetrics) {
if ($goalId == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART) {
continue;
}
if ($goalId >= GoalManager::IDGOAL_ORDER
|| $goalId == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER
) {
$revenue += (int) $this->getMetric($goalMetrics, 'revenue', $mappingFromNameToIdGoal);
}
}
if ($revenue == 0) {
$revenue = (int) $this->getMetric($row, 'revenue');
}
$nbVisits = (int) $this->getMetric($row, 'nb_visits');
$conversions = (int) $this->getMetric($row, 'nb_conversions');
// If no visit for this metric, but some conversions, we still want to display some kind of "revenue per visit"
// even though it will actually be in this edge case "Revenue per conversion"
return Piwik::getQuotientSafe($revenue, $nbVisits == 0 ? $conversions : $nbVisits, GoalManager::REVENUE_PRECISION);
}
public function format($value, Formatter $formatter)
{
return $formatter->getPrettyMoney($value, $this->idSite);
}
public function beforeFormat($report, DataTable $table)
{
$this->idSite = DataTableFactory::getSiteIdFromMetadata($table);
return !empty($this->idSite); // skip formatting if there is no site to get currency info from
}
}

View File

@ -0,0 +1,20 @@
<?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\Goals\Columns;
use Piwik\Plugin\Dimension\ConversionDimension;
class Revenue extends ConversionDimension
{
protected $columnName = 'revenue';
protected $type = self::TYPE_MONEY;
protected $category = 'Goals_Goals';
protected $nameSingular = 'Goals_ColumnOverallRevenue';
}

View File

@ -0,0 +1,19 @@
<?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\Goals\Columns;
use Piwik\Columns\Dimension;
use Piwik\Piwik;
class VisitsUntilConversion extends Dimension
{
protected $type = self::TYPE_NUMBER;
protected $nameSingular = 'Goals_VisitsUntilConv';
}