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
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -8,17 +8,15 @@
|
|||
*/
|
||||
namespace Piwik\Plugins\Goals;
|
||||
|
||||
use Exception;
|
||||
use Piwik\API\Request;
|
||||
use Piwik\Common;
|
||||
use Piwik\DataTable\Filter\AddColumnsProcessedMetricsGoal;
|
||||
use Piwik\DataTable;
|
||||
use Piwik\FrontController;
|
||||
use Piwik\DataTable\Filter\AddColumnsProcessedMetricsGoal;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\Plugins\Referrers\API as APIReferrers;
|
||||
use Piwik\View\ReportsByDimension;
|
||||
use Piwik\Translation\Translator;
|
||||
use Piwik\View;
|
||||
use Piwik\ViewDataTable\Factory;
|
||||
use Piwik\View\ReportsByDimension;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -44,30 +42,42 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
'items' => 'General_PurchasedProducts',
|
||||
);
|
||||
|
||||
private function formatConversionRate($conversionRate)
|
||||
/**
|
||||
* @var Translator
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* @var TranslationHelper
|
||||
*/
|
||||
private $translationHelper;
|
||||
|
||||
private function formatConversionRate($conversionRate, $columnName = 'conversion_rate')
|
||||
{
|
||||
if ($conversionRate instanceof DataTable) {
|
||||
if ($conversionRate->getRowsCount() == 0) {
|
||||
$conversionRate = 0;
|
||||
} else {
|
||||
$columns = $conversionRate->getFirstRow()->getColumns();
|
||||
$conversionRate = (float)reset($columns);
|
||||
$conversionRate = $conversionRate->getFirstRow()->getColumn($columnName);
|
||||
}
|
||||
}
|
||||
return sprintf('%.' . self::CONVERSION_RATE_PRECISION . 'f%%', $conversionRate);
|
||||
|
||||
if (!is_numeric($conversionRate)) {
|
||||
$conversionRate = sprintf('%.' . self::CONVERSION_RATE_PRECISION . 'f%%', $conversionRate);
|
||||
}
|
||||
|
||||
return $conversionRate;
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
public function __construct(Translator $translator, TranslationHelper $translationHelper)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->translator = $translator;
|
||||
$this->translationHelper = $translationHelper;
|
||||
|
||||
$this->idSite = Common::getRequestVar('idSite', null, 'int');
|
||||
$this->goals = API::getInstance()->getGoals($this->idSite);
|
||||
foreach ($this->goals as &$goal) {
|
||||
$goal['name'] = Common::sanitizeInputValue($goal['name']);
|
||||
if (isset($goal['pattern'])) {
|
||||
$goal['pattern'] = Common::sanitizeInputValue($goal['pattern']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function widgetGoalReport()
|
||||
|
|
@ -84,39 +94,11 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
return $view->render();
|
||||
}
|
||||
|
||||
public function ecommerceReport()
|
||||
{
|
||||
if (!\Piwik\Plugin\Manager::getInstance()->isPluginActivated('CustomVariables')) {
|
||||
throw new Exception("Ecommerce Tracking requires that the plugin Custom Variables is enabled. Please enable the plugin CustomVariables (or ask your admin).");
|
||||
}
|
||||
|
||||
$view = $this->getGoalReportView($idGoal = Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER);
|
||||
$view->displayFullReport = true;
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function getEcommerceLog($fetch = false)
|
||||
{
|
||||
$saveGET = $_GET;
|
||||
$filterEcommerce = Common::getRequestVar('filterEcommerce', self::ECOMMERCE_LOG_SHOW_ORDERS, 'int');
|
||||
if($filterEcommerce == self::ECOMMERCE_LOG_SHOW_ORDERS) {
|
||||
$segment = urlencode('visitEcommerceStatus==ordered,visitEcommerceStatus==orderedThenAbandonedCart');
|
||||
} else {
|
||||
$segment = urlencode('visitEcommerceStatus==abandonedCart,visitEcommerceStatus==orderedThenAbandonedCart');
|
||||
}
|
||||
$_GET['segment'] = $segment;
|
||||
$_GET['filterEcommerce'] = $filterEcommerce;
|
||||
$_GET['widget'] = 1;
|
||||
$output = FrontController::getInstance()->dispatch('Live', 'getVisitorLog', array($fetch));
|
||||
$_GET = $saveGET;
|
||||
return $output;
|
||||
}
|
||||
|
||||
protected function getGoalReportView($idGoal = false)
|
||||
{
|
||||
$view = new View('@Goals/getGoalReportView');
|
||||
if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) {
|
||||
$goalDefinition['name'] = Piwik::translate('Goals_Ecommerce');
|
||||
$goalDefinition['name'] = $this->translator->translate('Goals_Ecommerce');
|
||||
$goalDefinition['allow_multiple'] = true;
|
||||
$ecommerce = $view->ecommerce = true;
|
||||
} else {
|
||||
|
|
@ -137,20 +119,20 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
$view->$name = $value;
|
||||
}
|
||||
}
|
||||
$view->showHeadline = false;
|
||||
$view->idGoal = $idGoal;
|
||||
$view->goalName = $goalDefinition['name'];
|
||||
$view->goalAllowMultipleConversionsPerVisit = $goalDefinition['allow_multiple'];
|
||||
$view->graphEvolution = $this->getEvolutionGraph(array('nb_conversions'), $idGoal);
|
||||
$view->graphEvolution = $this->getEvolutionGraph(array(), $idGoal, array('nb_conversions'));
|
||||
$view->nameGraphEvolution = 'Goals.getEvolutionGraph' . $idGoal;
|
||||
$view->topDimensions = $this->getTopDimensions($idGoal);
|
||||
|
||||
$goalMetrics = Request::processRequest('Goals.get', array('idGoal' => $idGoal));
|
||||
|
||||
// conversion rate for new and returning visitors
|
||||
$segment = urldecode(\Piwik\Plugins\VisitFrequency\API::RETURNING_VISITOR_SEGMENT);
|
||||
$conversionRateReturning = API::getInstance()->getConversionRate($this->idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), $segment, $idGoal);
|
||||
$view->conversion_rate_returning = $this->formatConversionRate($conversionRateReturning);
|
||||
$segment = 'visitorType==new';
|
||||
$conversionRateNew = API::getInstance()->getConversionRate($this->idSite, Common::getRequestVar('period'), Common::getRequestVar('date'), $segment, $idGoal);
|
||||
$view->conversion_rate_new = $this->formatConversionRate($conversionRateNew);
|
||||
$view->conversion_rate_returning = $this->formatConversionRate($goalMetrics, 'conversion_rate_returning_visit');
|
||||
$view->conversion_rate_new = $this->formatConversionRate($goalMetrics, 'conversion_rate_new_visit');
|
||||
|
||||
$view->goalReportsByDimension = $this->getGoalReportsByDimensionTable(
|
||||
$view->nb_conversions, isset($ecommerce), !empty($view->cart_nb_conversions));
|
||||
return $view;
|
||||
|
|
@ -163,20 +145,24 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
// unsanitize goal names and other text data (not done in API so as not to break
|
||||
// any other code/cause security issues)
|
||||
$goals = $this->goals;
|
||||
foreach ($goals as &$goal) {
|
||||
$goal['name'] = Common::unsanitizeInputValue($goal['name']);
|
||||
if (isset($goal['pattern'])) {
|
||||
$goal['pattern'] = Common::unsanitizeInputValue($goal['pattern']);
|
||||
}
|
||||
}
|
||||
$view->goalsJSON = Common::json_encode($goals);
|
||||
$view->goalsJSON = json_encode($goals);
|
||||
|
||||
$view->userCanEditGoals = Piwik::isUserHasAdminAccess($this->idSite);
|
||||
$view->ecommerceEnabled = $this->site->isEcommerceEnabled();
|
||||
$view->displayFullReport = true;
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function manage()
|
||||
{
|
||||
Piwik::checkUserHasAdminAccess($this->idSite);
|
||||
|
||||
$view = new View('@Goals/manageGoals');
|
||||
$this->setGeneralVariablesView($view);
|
||||
$this->setEditGoalsViewVariables($view);
|
||||
$this->setUserCanEditGoals($view);
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function widgetGoalsOverview()
|
||||
{
|
||||
$view = $this->getOverviewView();
|
||||
|
|
@ -189,7 +175,7 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
$view = new View('@Goals/getOverviewView');
|
||||
$this->setGeneralVariablesView($view);
|
||||
|
||||
$view->graphEvolution = $this->getEvolutionGraph(array('nb_conversions'));
|
||||
$view->graphEvolution = $this->getEvolutionGraph(array(), false, array('nb_conversions'));
|
||||
$view->nameGraphEvolution = 'GoalsgetEvolutionGraph';
|
||||
|
||||
// sparkline for the historical data of the above values
|
||||
|
|
@ -201,6 +187,7 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
$request = new Request("method=Goals.get&format=original&idGoal=");
|
||||
$datatable = $request->process();
|
||||
$dataRow = $datatable->getFirstRow();
|
||||
|
||||
$view->nb_conversions = $dataRow->getColumn('nb_conversions');
|
||||
$view->nb_visits_converted = $dataRow->getColumn('nb_visits_converted');
|
||||
$view->conversion_rate = $this->formatConversionRate($dataRow->getColumn('conversion_rate'));
|
||||
|
|
@ -242,19 +229,32 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
{
|
||||
$view = new View('@Goals/addNewGoal');
|
||||
$this->setGeneralVariablesView($view);
|
||||
$view->userCanEditGoals = Piwik::isUserHasAdminAccess($this->idSite);
|
||||
$this->setUserCanEditGoals($view);
|
||||
$view->onlyShowAddNewGoal = true;
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function getEvolutionGraph(array $columns = array(), $idGoal = false)
|
||||
public function editGoals()
|
||||
{
|
||||
$view = new View('@Goals/editGoals');
|
||||
$this->setGeneralVariablesView($view);
|
||||
$this->setEditGoalsViewVariables($view);
|
||||
$this->setUserCanEditGoals($view);
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
public function getEvolutionGraph(array $columns = array(), $idGoal = false, array $defaultColumns = array())
|
||||
{
|
||||
if (empty($columns)) {
|
||||
$columns = Common::getRequestVar('columns');
|
||||
$columns = Piwik::getArrayFromApiParameter($columns);
|
||||
$columns = Common::getRequestVar('columns', false);
|
||||
if (false !== $columns) {
|
||||
$columns = Piwik::getArrayFromApiParameter($columns);
|
||||
}
|
||||
}
|
||||
|
||||
$columns = !is_array($columns) ? array($columns) : $columns;
|
||||
if (false !== $columns) {
|
||||
$columns = !is_array($columns) ? array($columns) : $columns;
|
||||
}
|
||||
|
||||
if (empty($idGoal)) {
|
||||
$idGoal = Common::getRequestVar('idGoal', false, 'string');
|
||||
|
|
@ -266,10 +266,10 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) {
|
||||
$nameToLabel['nb_conversions'] = 'General_EcommerceOrders';
|
||||
} elseif ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART) {
|
||||
$nameToLabel['nb_conversions'] = Piwik::translate('General_VisitsWith', Piwik::translate('Goals_AbandonedCart'));
|
||||
$nameToLabel['nb_conversions'] = $this->translator->translate('General_VisitsWith', $this->translator->translate('Goals_AbandonedCart'));
|
||||
$nameToLabel['conversion_rate'] = $nameToLabel['nb_conversions'];
|
||||
$nameToLabel['revenue'] = Piwik::translate('Goals_LeftInCart', Piwik::translate('General_ColumnRevenue'));
|
||||
$nameToLabel['items'] = Piwik::translate('Goals_LeftInCart', Piwik::translate('Goals_Products'));
|
||||
$nameToLabel['revenue'] = $this->translator->translate('Goals_LeftInCart', $this->translator->translate('General_ColumnRevenue'));
|
||||
$nameToLabel['items'] = $this->translator->translate('Goals_LeftInCart', $this->translator->translate('Goals_Products'));
|
||||
}
|
||||
|
||||
$selectableColumns = array('nb_conversions', 'conversion_rate', 'revenue');
|
||||
|
|
@ -278,27 +278,33 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
$selectableColumns[] = 'avg_order_revenue';
|
||||
}
|
||||
|
||||
foreach (array_merge($columns, $selectableColumns) as $columnName) {
|
||||
foreach (array_merge($columns ? $columns : array(), $selectableColumns) as $columnName) {
|
||||
$columnTranslation = '';
|
||||
// find the right translation for this column, eg. find 'revenue' if column is Goal_1_revenue
|
||||
foreach ($nameToLabel as $metric => $metricTranslation) {
|
||||
if (strpos($columnName, $metric) !== false) {
|
||||
$columnTranslation = Piwik::translate($metricTranslation);
|
||||
$columnTranslation = $this->translator->translate($metricTranslation);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($idGoal) && isset($this->goals[$idGoal])) {
|
||||
$goalName = $this->goals[$idGoal]['name'];
|
||||
$columnTranslation = "$columnTranslation (" . Piwik::translate('Goals_GoalX', "$goalName") . ")";
|
||||
$columnTranslation = "$columnTranslation (" . $this->translator->translate('Goals_GoalX', "$goalName") . ")";
|
||||
}
|
||||
$view->config->translations[$columnName] = $columnTranslation;
|
||||
}
|
||||
$view->config->columns_to_display = $columns;
|
||||
|
||||
if (!empty($columns)) {
|
||||
$view->config->columns_to_display = $columns;
|
||||
} elseif (empty($view->config->columns_to_display) && !empty($defaultColumns)) {
|
||||
$view->config->columns_to_display = $defaultColumns;
|
||||
}
|
||||
|
||||
$view->config->selectable_columns = $selectableColumns;
|
||||
|
||||
$langString = $idGoal ? 'Goals_SingleGoalOverviewDocumentation' : 'Goals_GoalsOverviewDocumentation';
|
||||
$view->config->documentation = Piwik::translate($langString, '<br />');
|
||||
$view->config->documentation = $this->translator->translate($langString, '<br />');
|
||||
|
||||
return $this->renderView($view);
|
||||
}
|
||||
|
|
@ -327,11 +333,11 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
$topDimensions = array();
|
||||
foreach ($topDimensionsToLoad as $dimensionName => $apiMethod) {
|
||||
$request = new Request("method=$apiMethod
|
||||
&format=original
|
||||
&filter_update_columns_when_show_all_goals=1
|
||||
&idGoal=" . AddColumnsProcessedMetricsGoal::GOALS_FULL_TABLE . "
|
||||
&filter_sort_order=desc
|
||||
&filter_sort_column=$columnNbConversions" .
|
||||
&format=original
|
||||
&filter_update_columns_when_show_all_goals=1
|
||||
&idGoal=" . AddColumnsProcessedMetricsGoal::GOALS_FULL_TABLE . "
|
||||
&filter_sort_order=desc
|
||||
&filter_sort_column=$columnNbConversions" .
|
||||
// select a couple more in case some are not valid (ie. conversions==0 or they are "Keyword not defined")
|
||||
"&filter_limit=" . (self::COUNT_TOP_ROWS_TO_DISPLAY + 2));
|
||||
$datatable = $request->process();
|
||||
|
|
@ -421,22 +427,13 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
$ecommerceCustomParams = array();
|
||||
if ($ecommerce) {
|
||||
if ($preloadAbandonedCart) {
|
||||
$ecommerceCustomParams['viewDataTable'] = 'ecommerceAbandonedCart';
|
||||
$ecommerceCustomParams['filterEcommerce'] = self::ECOMMERCE_LOG_SHOW_ABANDONED_CARTS;
|
||||
$ecommerceCustomParams['abandonedCarts'] = '1';
|
||||
} else {
|
||||
$ecommerceCustomParams['abandonedCarts'] = '0';
|
||||
}
|
||||
|
||||
$goalReportsByDimension->addReport(
|
||||
'Goals_EcommerceReports', 'Goals_ProductSKU', 'Goals.getItemsSku', $ecommerceCustomParams);
|
||||
$goalReportsByDimension->addReport(
|
||||
'Goals_EcommerceReports', 'Goals_ProductName', 'Goals.getItemsName', $ecommerceCustomParams);
|
||||
$goalReportsByDimension->addReport(
|
||||
'Goals_EcommerceReports', 'Goals_ProductCategory', 'Goals.getItemsCategory', $ecommerceCustomParams);
|
||||
|
||||
$goalReportsByDimension->addReport(
|
||||
'Goals_EcommerceReports', 'Goals_EcommerceLog', 'Goals.getEcommerceLog', $ecommerceCustomParams);
|
||||
}
|
||||
|
||||
if ($conversions > 0) {
|
||||
if ($conversions > 0 || $ecommerce) {
|
||||
// for non-Goals reports, we show the goals table
|
||||
$customParams = $ecommerceCustomParams + array('documentationForGoalsPage' => '1');
|
||||
|
||||
|
|
@ -447,15 +444,28 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
|
||||
$allReports = Goals::getReportsWithGoalMetrics();
|
||||
foreach ($allReports as $category => $reports) {
|
||||
$categoryText = Piwik::translate('Goals_ViewGoalsBy', $category);
|
||||
if ($ecommerce) {
|
||||
$categoryText = $this->translationHelper->translateEcommerceMetricCategory($category);
|
||||
} else {
|
||||
$categoryText = $this->translationHelper->translateGoalMetricCategory($category);
|
||||
}
|
||||
|
||||
foreach ($reports as $report) {
|
||||
if(empty($report['viewDataTable'])) {
|
||||
if (empty($report['viewDataTable'])
|
||||
&& empty($report['abandonedCarts'])
|
||||
) {
|
||||
$report['viewDataTable'] = 'tableGoals';
|
||||
}
|
||||
$customParams['viewDataTable'] = $report['viewDataTable'];
|
||||
|
||||
if (!empty($report['parameters'])) {
|
||||
$params = array_merge($customParams, $report['parameters']);
|
||||
} else {
|
||||
$params = $customParams;
|
||||
}
|
||||
|
||||
$goalReportsByDimension->addReport(
|
||||
$categoryText, $report['name'], $report['module'] . '.' . $report['action'], $customParams);
|
||||
$categoryText, $report['name'], $report['module'] . '.' . $report['action'], $params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -463,32 +473,32 @@ class Controller extends \Piwik\Plugin\Controller
|
|||
return $goalReportsByDimension->render();
|
||||
}
|
||||
|
||||
//
|
||||
// Report rendering actions
|
||||
//
|
||||
|
||||
public function getItemsSku()
|
||||
private function setEditGoalsViewVariables($view)
|
||||
{
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
$goals = $this->goals;
|
||||
$view->goals = $goals;
|
||||
|
||||
$idGoal = Common::getRequestVar('idGoal', 0, 'int');
|
||||
$view->idGoal = 0;
|
||||
if ($idGoal && array_key_exists($idGoal, $goals)) {
|
||||
$view->idGoal = $idGoal;
|
||||
}
|
||||
|
||||
// unsanitize goal names and other text data (not done in API so as not to break
|
||||
// any other code/cause security issues)
|
||||
|
||||
foreach ($goals as &$goal) {
|
||||
$goal['name'] = Common::unsanitizeInputValue($goal['name']);
|
||||
if (isset($goal['pattern'])) {
|
||||
$goal['pattern'] = Common::unsanitizeInputValue($goal['pattern']);
|
||||
}
|
||||
}
|
||||
$view->goalsJSON = json_encode($goals);
|
||||
$view->ecommerceEnabled = $this->site->isEcommerceEnabled();
|
||||
}
|
||||
|
||||
public function getItemsName()
|
||||
private function setUserCanEditGoals(View $view)
|
||||
{
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function getItemsCategory()
|
||||
{
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function getVisitsUntilConversion()
|
||||
{
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
}
|
||||
|
||||
public function getDaysToConversion()
|
||||
{
|
||||
return $this->renderReport(__FUNCTION__);
|
||||
$view->userCanEditGoals = Piwik::isUserHasAdminAccess($this->idSite);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue