Skip to content

Commit

Permalink
refs #6022 separate goals and ecommerce menu items, added goals manag…
Browse files Browse the repository at this point in the history
…ement menu item
  • Loading branch information
tsteur committed Jan 7, 2015
1 parent f8ef253 commit 6705565
Show file tree
Hide file tree
Showing 16 changed files with 227 additions and 103 deletions.
1 change: 1 addition & 0 deletions config/global.ini.php
Expand Up @@ -722,6 +722,7 @@
Plugins[] = UserSettings
Plugins[] = DevicesDetection
Plugins[] = Goals
Plugins[] = Ecommerce
Plugins[] = SEO
Plugins[] = Events
Plugins[] = UserCountry
Expand Down
2 changes: 1 addition & 1 deletion plugins/CoreHome/javascripts/broadcast.js
Expand Up @@ -197,7 +197,7 @@ var broadcast = {
// if the module is not 'Goals', we specifically unset the 'idGoal' parameter
// this is to ensure that the URLs are clean (and that clicks on graphs work as expected - they are broken with the extra parameter)
var action = broadcast.getParamValue('action', currentHashStr);
if (action != 'goalReport' && action != 'ecommerceReport') {
if (action != 'goalReport' && action != 'ecommerceReport' && action != 'ecommerceProducts') {
currentHashStr = broadcast.updateParamValue('idGoal=', currentHashStr);
}
// unset idDashboard if use doesn't display a dashboard
Expand Down
2 changes: 1 addition & 1 deletion plugins/CoreHome/javascripts/menu.js
Expand Up @@ -100,7 +100,7 @@ menu.prototype =
getSubmenuID: function (module, id, action) {
var $li = '';
// So, if module is Goals, id is present, and action is not Index, must be one of the goals
if (module == 'Goals' && id != '' && (action != 'index')) {
if ((module == 'Goals' || module == 'Ecommerce') && id != '' && (action != 'index')) {
$li = $("#" + module + "_" + action + "_" + id);
// if module is Dashboard and id is present, must be one of the dashboards
} else if (module == 'Dashboard') {
Expand Down
58 changes: 58 additions & 0 deletions plugins/Ecommerce/Controller.php
@@ -0,0 +1,58 @@
<?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\Ecommerce;

use Exception;
use Piwik\DataTable;
use Piwik\FrontController;
use Piwik\Piwik;
use Piwik\View;

class Controller extends \Piwik\Plugins\Goals\Controller
{
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 = false;
$view->showHeadline = true;
return $view->render();
}

public function getEcommerceLog($fetch = false)
{
$saveGET = $_GET;
$_GET['segment'] = urlencode('visitEcommerceStatus!=none');
$_GET['widget'] = 1;
$output = FrontController::getInstance()->dispatch('Live', 'getVisitorLog', array($fetch));
$_GET = $saveGET;
return $output;
}

public function index()
{
return $this->ecommerceReport();
}

public function ecommerceProducts()
{
$viewOverview = $this->getGoalReportView(Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER);
$reportsByDimension = $viewOverview->goalReportsByDimension;

$view = new View('@Ecommerce/ecommerceProducts');
$this->setGeneralVariablesView($view);

$view->goalReportsByDimension = $reportsByDimension;
return $view->render();
}

}
24 changes: 24 additions & 0 deletions plugins/Ecommerce/Ecommerce.php
@@ -0,0 +1,24 @@
<?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\Ecommerce;

use Piwik\Piwik;

class Ecommerce extends \Piwik\Plugin
{
public function getInformation()
{
$suffix = Piwik::translate('SitesManager_PiwikOffersEcommerceAnalytics',
array('<a href="http://piwik.org/docs/ecommerce-analytics/" rel="noreferrer" target="_blank">', '</a>'));
$info = parent::getInformation();
$info['description'] = $suffix;
return $info;
}

}
48 changes: 48 additions & 0 deletions plugins/Ecommerce/Menu.php
@@ -0,0 +1,48 @@
<?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\Ecommerce;

use Piwik\Common;
use Piwik\Menu\MenuReporting;
use Piwik\Menu\MenuUser;
use Piwik\Piwik;
use Piwik\Site;
use Piwik\Translate;

/**
*/
class Menu extends \Piwik\Plugin\Menu
{

public function configureReportingMenu(MenuReporting $menu)
{
$idSite = Common::getRequestVar('idSite', null, 'int');

$site = new Site($idSite);

if ($site->isEcommerceEnabled()) {
$ecommerceParams = array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER);
$ecommerceUrl = $this->urlForAction('ecommerceReport', $ecommerceParams);

$menu->addItem('Goals_Ecommerce', '', $ecommerceUrl, 24);
$menu->addItem('Goals_Ecommerce', 'Goals_EcommerceOverview', $ecommerceUrl, 1);
$menu->addItem('Goals_Ecommerce', 'Goals_EcommerceLog', $this->urlForAction('getEcommerceLog'), 2);
$menu->addItem('Goals_Ecommerce', 'Goals_Products', $this->urlForAction('ecommerceProducts', $ecommerceParams), 3);
}

}
public function configureUserMenu(MenuUser $menu)
{
$idSite = Common::getRequestVar('idSite', null, 'int');

if (Piwik::isUserHasAdminAccess($idSite)) {
$menu->addManageItem('Goals_GoalsManagement', $this->urlForAction('manage'), 15);
}
}
}
3 changes: 3 additions & 0 deletions plugins/Ecommerce/templates/ecommerceProducts.twig
@@ -0,0 +1,3 @@
<h2 piwik-enriched-headline>{{ 'Goals_Products'|translate }}</h2>

{{ goalReportsByDimension|raw }}
50 changes: 25 additions & 25 deletions plugins/Goals/Controller.php
Expand Up @@ -87,27 +87,6 @@ public function goalReport()
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;
$_GET['segment'] = urlencode('visitEcommerceStatus!=none');
$_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');
Expand All @@ -133,6 +112,7 @@ protected function getGoalReportView($idGoal = false)
$view->$name = $value;
}
}
$view->showHeadline = false;
$view->idGoal = $idGoal;
$view->goalName = $goalDefinition['name'];
$view->goalAllowMultipleConversionsPerVisit = $goalDefinition['allow_multiple'];
Expand Down Expand Up @@ -169,12 +149,35 @@ public function index()
}
$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);

$goals = $this->goals;
$view->goals = $goals;

// 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();
return $view->render();
}

public function widgetGoalsOverview()
{
$view = $this->getOverviewView();
Expand Down Expand Up @@ -441,9 +444,6 @@ private function getGoalReportsByDimensionTable($conversions, $ecommerce = false
'Goals_EcommerceReports', 'Goals_ProductName', 'Goals.getItemsName', $ecommerceCustomParams);
$goalReportsByDimension->addReport(
'Goals_EcommerceReports', 'Goals_ProductCategory', 'Goals.getItemsCategory', $ecommerceCustomParams);

$goalReportsByDimension->addReport(
'Goals_EcommerceReports', 'Goals_EcommerceLog', 'Goals.getEcommerceLog', array());
}

if ($conversions > 0) {
Expand Down
9 changes: 0 additions & 9 deletions plugins/Goals/Goals.php
Expand Up @@ -21,15 +21,6 @@
*/
class Goals extends \Piwik\Plugin
{
public function getInformation()
{
$suffix = Piwik::translate('SitesManager_PiwikOffersEcommerceAnalytics',
array('<a href="http://piwik.org/docs/ecommerce-analytics/" rel="noreferrer" target="_blank">', '</a>'));
$info = parent::getInformation();
$info['description'] .= ' ' . $suffix;
return $info;
}

public static function getReportsWithGoalMetrics()
{
$dimensions = self::getAllReportsWithGoalMetrics();
Expand Down
37 changes: 11 additions & 26 deletions plugins/Goals/Menu.php
Expand Up @@ -12,47 +12,32 @@
use Piwik\Menu\Group;
use Piwik\Menu\MenuReporting;
use Piwik\Piwik;
use Piwik\Site;
use Piwik\Translate;

/**
*/
class Menu extends \Piwik\Plugin\Menu
{

public function configureReportingMenu(MenuReporting $menu)
{
$idSite = Common::getRequestVar('idSite', null, 'int');
$goals = API::getInstance()->getGoals($idSite);
$mainGoalMenu = $this->getGoalCategoryName($idSite);

$site = new Site($idSite);
$mainGoalMenu = 'Goals_Goals';

if (count($goals) == 0) {
$action = $site->isEcommerceEnabled() ? 'ecommerceReport' : 'addNewGoal';
$action = 'addNewGoal';
$url = $this->urlForAction($action, array(
'idGoal' => ($site->isEcommerceEnabled() ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER : null
)));
'idGoal' => null
));

$menu->addItem($mainGoalMenu, '', $url, 25);

if ($site->isEcommerceEnabled()) {
$menu->addItem($mainGoalMenu, 'Goals_Ecommerce', $this->urlForAction('ecommerceReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER)), 1);
}

$menu->addItem($mainGoalMenu, 'Goals_AddNewGoal', $this->urlForAction('addNewGoal'));

} else {

$action = $site->isEcommerceEnabled() ? 'ecommerceReport' : 'index';
$url = $this->urlForAction($action, array('idGoal' => ($site->isEcommerceEnabled() ? Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER : null)));
$action = 'index';
$url = $this->urlForAction($action, array('idGoal' => null));

$menu->addItem($mainGoalMenu, '', $url, 25);

if ($site->isEcommerceEnabled()) {
$menu->addItem($mainGoalMenu, 'Goals_Ecommerce', $this->urlForAction('ecommerceReport', array('idGoal' => Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER)), 1);
}

$menu->addItem($mainGoalMenu, 'Goals_GoalsOverview', array('module' => 'Goals', 'action' => 'index'), 2);

$group = new Group();
Expand All @@ -72,11 +57,11 @@ public function configureReportingMenu(MenuReporting $menu)
$menu->addGroup($mainGoalMenu, 'Goals_ChooseGoal', $group, $orderId = 50, $tooltip = false);
}
}
}

private function getGoalCategoryName($idSite)
{
$site = new Site($idSite);
return $site->isEcommerceEnabled() ? 'Goals_EcommerceAndGoalsMenu' : 'Goals_Goals';
if (0 !== count($goals) && Piwik::isUserHasAdminAccess($idSite)) {
$menu->addItem($mainGoalMenu, 'Goals_GoalsManagement', $this->urlForAction('manage'), 1);
}

}

}
16 changes: 14 additions & 2 deletions plugins/Goals/javascripts/goalsForm.js
Expand Up @@ -9,14 +9,15 @@ function showAddNewGoal() {
hideForms();
$(".entityAddContainer").show();
showCancel();
hideCreateGoal();
piwikHelper.lazyScrollTo(".entityContainer", 400);
return false;
}

function showEditGoals() {
hideForms();
showCreateGoal();
$("#entityEditContainer").show();
showCancel();
piwikHelper.lazyScrollTo(".entityContainer", 400);
return false;
}
Expand All @@ -31,9 +32,18 @@ function showCancel() {
$('.entityCancelLink').click(function () {
hideForms();
$(".entityCancel").hide();
showEditGoals();
});
}

function showCreateGoal() {
$("a[name=linkAddNewGoal]").show();
}

function hideCreateGoal() {
$("a[name=linkAddNewGoal]").hide();
}

function onMatchAttributeChange(matchAttribute)
{
if ('event' === matchAttribute) {
Expand Down Expand Up @@ -173,7 +183,9 @@ function ajaxAddGoal() {
var ajaxRequest = new ajaxHelper();
ajaxRequest.addParams(parameters, 'get');
ajaxRequest.setLoadingElement('#goalAjaxLoading');
ajaxRequest.setCallback(function () { location.reload(); });
ajaxRequest.setCallback(function () {
location.reload();
});
ajaxRequest.send(true);
}

Expand Down

0 comments on commit 6705565

Please sign in to comment.