diff options
Diffstat (limited to 'plugins/Goals')
-rw-r--r-- | plugins/Goals/Columns/DaysToConversion.php | 6 | ||||
-rw-r--r-- | plugins/Goals/Columns/IdGoal.php | 23 | ||||
-rw-r--r-- | plugins/Goals/Columns/Revenue.php | 20 | ||||
-rw-r--r-- | plugins/Goals/Columns/VisitsUntilConversion.php | 7 | ||||
-rw-r--r-- | plugins/Goals/GoalDimension.php | 41 | ||||
-rw-r--r-- | plugins/Goals/Goals.php | 71 | ||||
-rw-r--r-- | plugins/Goals/lang/en.json | 6 |
7 files changed, 153 insertions, 21 deletions
diff --git a/plugins/Goals/Columns/DaysToConversion.php b/plugins/Goals/Columns/DaysToConversion.php index e1bd941d6b..576babb8d7 100644 --- a/plugins/Goals/Columns/DaysToConversion.php +++ b/plugins/Goals/Columns/DaysToConversion.php @@ -13,8 +13,6 @@ use Piwik\Piwik; class DaysToConversion extends Dimension { - public function getName() - { - return Piwik::translate('Goals_DaysToConv'); - } + protected $type = self::TYPE_NUMBER; + protected $nameSingular = 'Goals_DaysToConv'; }
\ No newline at end of file diff --git a/plugins/Goals/Columns/IdGoal.php b/plugins/Goals/Columns/IdGoal.php index 2243dbdb1f..a8ca5ac5b6 100644 --- a/plugins/Goals/Columns/IdGoal.php +++ b/plugins/Goals/Columns/IdGoal.php @@ -8,26 +8,27 @@ */ namespace Piwik\Plugins\Goals\Columns; -use Piwik\Piwik; +use Piwik\Columns\DimensionMetricFactory; +use Piwik\Columns\Join; +use Piwik\Columns\MetricsList; use Piwik\Plugin\Dimension\ConversionDimension; -use Piwik\Plugin\Segment; 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.'; - protected function configureSegments() + public function configureMetrics(MetricsList $metricsList, DimensionMetricFactory $dimensionMetricFactory) { - $segment = new Segment(); - $segment->setCategory('General_Visit'); - $segment->setName('General_VisitConvertedGoalId'); - $segment->setSegment('visitConvertedGoalId'); - $segment->setAcceptedValues('1, 2, 3, etc.'); - $this->addSegment($segment); + // do not create any metrics for this dimension, they don't really make much sense and are rather confusing } - public function getName() + public function getDbColumnJoin() { - return Piwik::translate('General_VisitConvertedGoalId'); + return new Join\GoalNameJoin(); } }
\ No newline at end of file diff --git a/plugins/Goals/Columns/Revenue.php b/plugins/Goals/Columns/Revenue.php new file mode 100644 index 0000000000..d18af2eda9 --- /dev/null +++ b/plugins/Goals/Columns/Revenue.php @@ -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'; + +}
\ No newline at end of file diff --git a/plugins/Goals/Columns/VisitsUntilConversion.php b/plugins/Goals/Columns/VisitsUntilConversion.php index 13f54e9dd7..05c988a479 100644 --- a/plugins/Goals/Columns/VisitsUntilConversion.php +++ b/plugins/Goals/Columns/VisitsUntilConversion.php @@ -13,8 +13,7 @@ use Piwik\Piwik; class VisitsUntilConversion extends Dimension { - public function getName() - { - return Piwik::translate('Goals_VisitsUntilConv'); - } + protected $type = self::TYPE_NUMBER; + protected $nameSingular = 'Goals_VisitsUntilConv'; + }
\ No newline at end of file diff --git a/plugins/Goals/GoalDimension.php b/plugins/Goals/GoalDimension.php new file mode 100644 index 0000000000..91cbde16df --- /dev/null +++ b/plugins/Goals/GoalDimension.php @@ -0,0 +1,41 @@ +<?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; + +use Piwik\Columns\Dimension; +use Piwik\Columns\Discriminator; + +class GoalDimension extends Dimension +{ + protected $type = self::TYPE_TEXT; + private $goal; + private $id; + + public function __construct($goal, $column, $name) + { + $this->goal = $goal; + $this->category = 'Goals_Goals'; + $this->dbTableName = 'log_conversion'; + $this->columnName = $column; + $this->nameSingular = $name; + + $this->id = 'Goals.Goal' . ucfirst($column) . $goal['idgoal']; + } + + public function getId() + { + return $this->id; + } + + public function getDbDiscriminator() + { + return new Discriminator('log_conversion', 'idgoal', $this->goal['idgoal']); + } + +}
\ No newline at end of file diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php index 0700d8aa75..b1d10e16f3 100644 --- a/plugins/Goals/Goals.php +++ b/plugins/Goals/Goals.php @@ -8,8 +8,13 @@ */ namespace Piwik\Plugins\Goals; +use Piwik\Columns\ComputedMetricFactory; +use Piwik\Columns\Dimension; +use Piwik\Columns\MetricsList; use Piwik\Common; use Piwik\Piwik; +use Piwik\Plugin\ArchivedMetric; +use Piwik\Plugin\ComputedMetric; use Piwik\Plugin\ReportsProvider; use Piwik\Tracker\GoalManager; use Piwik\Category\Subcategory; @@ -77,11 +82,74 @@ class Goals extends \Piwik\Plugin 'SitesManager.deleteSite.end' => 'deleteSiteGoals', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', 'Metrics.getDefaultMetricTranslations' => 'addMetricTranslations', - 'Category.addSubcategories' => 'addSubcategories' + 'Category.addSubcategories' => 'addSubcategories', + 'Metric.addMetrics' => 'addMetrics', + 'Metric.addComputedMetrics' => 'addComputedMetrics' ); return $hooks; } + public function addComputedMetrics(MetricsList $list, ComputedMetricFactory $computedMetricFactory) + { + $idSite = Common::getRequestVar('idSite', 0, 'int'); + $goals = API::getInstance()->getGoals($idSite); + + foreach ($goals as $goal) { + $metric = $computedMetricFactory->createComputedMetric('goal_' . $goal['idgoal'] . '_conversion', 'nb_uniq_visitors', ComputedMetric::AGGREGATION_RATE); + $goalName = Piwik::translate('Goals_GoalX', $goal['name']); + $metricName = Piwik::translate('Goals_ConversionRate', $goalName); + $metric->setTranslatedName($metricName); + $list->addMetric($metric); + } + } + + public function addMetrics(MetricsList $metricsList) + { + $idSite = Common::getRequestVar('idSite', 0, 'int'); + $goals = API::getInstance()->getGoals($idSite); + + foreach ($goals as $goal) { + $custom = new GoalDimension($goal, 'idgoal', 'Conversions goal "' . $goal['name'] . '" (ID ' . $goal['idgoal'] .' )'); + $custom->setType(Dimension::TYPE_NUMBER); + $custom->setSqlSegment('count(distinct log_conversion.idvisit, log_conversion.buster)'); + + $metric = new ArchivedMetric($custom, ArchivedMetric::AGGREGATION_SUM); + $metric->setQuery('count(distinct log_conversion.idvisit, log_conversion.buster)'); + $metric->setTranslatedName($custom->getName()); + $metric->setDocumentation('The number of times this goal was converted.'); + $metric->setCategory($custom->getCategoryId()); + $metric->setName('goal_' . $goal['idgoal'] . '_conversion'); + $metricsList->addMetric($metric); + + $custom = new GoalDimension($goal, 'revenue', 'Revenue goal "' . $goal['name'] . '" (ID ' . $goal['idgoal'] .' )'); + $custom->setType(Dimension::TYPE_MONEY); + $metric = new ArchivedMetric($custom, ArchivedMetric::AGGREGATION_SUM); + $metric->setTranslatedName($custom->getName()); + $metric->setName('goal_' . $goal['idgoal'] . '_revenue'); + $metric->setDocumentation('The amount of revenue that was generated by converting this goal.'); + $metric->setCategory($custom->getCategoryId()); + $metricsList->addMetric($metric); + + $custom = new GoalDimension($goal, 'visitor_days_since_first', 'Days to conversion goal "' . $goal['name'] . '" (ID ' . $goal['idgoal'] .' )'); + $custom->setType(Dimension::TYPE_NUMBER); + $metric = new ArchivedMetric($custom, ArchivedMetric::AGGREGATION_SUM); + $metric->setTranslatedName($custom->getName()); + $metric->setCategory($custom->getCategoryId()); + $metric->setDocumentation('The number of days it took a visitor to convert this goal.'); + $metric->setName('goal_' . $goal['idgoal'] . '_daystoconversion'); + $metricsList->addMetric($metric); + + $custom = new GoalDimension($goal, 'visitor_count_visits', 'Visits to conversion goal "' . $goal['name'] . '" (ID ' . $goal['idgoal'] .' )'); + $custom->setType(Dimension::TYPE_NUMBER); + $metric = new ArchivedMetric($custom, ArchivedMetric::AGGREGATION_SUM); + $metric->setTranslatedName($custom->getName()); + $metric->setCategory($custom->getCategoryId()); + $metric->setDocumentation('The number of visits it took a visitor to convert this goal.'); + $metric->setName('goal_' . $goal['idgoal'] . '_visitstoconversion'); + $metricsList->addMetric($metric); + } + } + public function addSubcategories(&$subcategories) { $idSite = Common::getRequestVar('idSite', 0, 'int'); @@ -108,7 +176,6 @@ class Goals extends \Piwik\Plugin } } - public function addMetricTranslations(&$translations) { $metrics = array( diff --git a/plugins/Goals/lang/en.json b/plugins/Goals/lang/en.json index d78a22a276..3b72998105 100644 --- a/plugins/Goals/lang/en.json +++ b/plugins/Goals/lang/en.json @@ -24,6 +24,7 @@ "ColumnConversionRateDocumentation": "The percentage of visits that triggered the goal %s.", "ColumnConversionRateProductDocumentation": "The %s conversion rate is the number of orders containing this product divided by number of visits on the product page.", "ColumnConversions": "Conversions", + "Conversion": "Conversion", "ColumnConversionsDocumentation": "The number of conversions for %s.", "ColumnOrdersDocumentation": "The total number of Ecommerce orders which contained this %s at least once.", "ColumnPurchasedProductsDocumentation": "The number of purchased products is the sum of Product quantities sold in all Ecommerce orders.", @@ -81,14 +82,19 @@ "NeedAccess": "Only an Administrator or a user with Super User access can manage Goals for a given website.", "Optional": "(optional)", "OverallConversionRate": "overall conversion rate (visits with a completed goal)", + "ColumnOverallRevenue": "Overall revenue", "OverallRevenue": "overall revenue", "PageTitle": "Page Title", "Pattern": "Pattern", "PluginDescription": "Create Goals and see detailed reports about your goal conversions: evolution over time, revenue per visit, conversions per referrer, per keyword, and more.", "ProductCategory": "Product Category", "ProductName": "Product Name", + "ProductNames": "Product Names", + "ProductPrice": "Product Price", + "ProductQuantity": "Product Quantity", "Products": "Products", "ProductSKU": "Product SKU", + "ProductSKUs": "Product SKUs", "ReturningVisitorsConversionRateIs": "Returning visitors conversion rate is %s", "SingleGoalOverviewDocumentation": "This is an overview of the conversions for a single goal. %s The sparklines below the graph can be enlarged by clicking on them.", "ThereIsNoGoalToManage": "There is no goal to manage for website %s", |