From add95a5c2dacb3065a850a4b2a76e8d009347518 Mon Sep 17 00:00:00 2001 From: diosmosis Date: Thu, 7 Feb 2013 06:52:31 +0000 Subject: [PATCH] Fixes #3619, add reports by dimension section to Referrers overview. Notes: - fix bug in last #3619 commit that broke referrers overview page. --- lang/en.php | 4 ++ plugins/Goals/Controller.php | 3 +- plugins/Referers/API.php | 49 ++++++++-------- plugins/Referers/Controller.php | 39 +++++++++++++ plugins/Referers/templates/index.tpl | 58 ++++++++++--------- ...iodIsLast__Referers.getRefererType_day.xml | 12 +++- ...odIsLast__Referers.getRefererType_week.xml | 12 +++- 7 files changed, 119 insertions(+), 58 deletions(-) diff --git a/lang/en.php b/lang/en.php index 89c485a12af..7bbbb0af6b4 100644 --- a/lang/en.php +++ b/lang/en.php @@ -363,6 +363,7 @@ 'General_Hide_js' => 'hide', 'General_Donate' => 'Donate', 'General_MoreDetails' => 'More Details', + 'General_Source' => 'Source', 'Actions_PluginDescription' => 'Reports about the page views, the outlinks and downloads. Outlinks and Downloads tracking is automatic! You can also track your internal website\'s Search Engine.', 'Actions_Actions' => 'Actions', 'Actions_SubmenuPages' => 'Pages', @@ -1158,6 +1159,7 @@ 'Referers_PluginDescription' => 'Reports the Referrers data: Search Engines, Keywords, Websites, Campaign Tracking, Direct Entry.', 'Referers_Referrer' => 'Referrer', 'Referers_Referers' => 'Referrers', + 'Referers_ReferrersOverview' => 'Referrers Overview', 'Referers_EvolutionDocumentation' => 'This is an overview of the referrers that led visitors to your website.', 'Referers_EvolutionDocumentationMoreInfo' => 'For more information about the different refferrer types, see the documentation of the %s table.', 'Referers_SearchEngines' => 'Search Engines', @@ -1210,6 +1212,8 @@ 'Referers_WidgetOverview' => 'Overview', 'Referers_SocialFooterMessage' => 'This is a subset of the Websites report to the left. It filters out other websites so you can compare your social network referrers directly.', 'Referers_WidgetGetAll' => 'All Referrers', + 'Referers_ViewReferrersBy' => 'View Referrers by %s', + 'Referers_ViewAllReferrers' => 'View all Referrers', 'SecurityInfo_PluginDescription' => 'Based on PhpSecInfo from the PHP Security Consortium, this plugin provides security information about your PHP environment and offers suggestions for improvement. It is a tool in a multilayered security approach. It does not replace secure development practices nor audit the code/application.', 'SecurityInfo_Security' => 'Security', 'SecurityInfo_SecurityInformation' => 'PHP Security Information', diff --git a/plugins/Goals/Controller.php b/plugins/Goals/Controller.php index 5884f73b020..6cabee1d332 100644 --- a/plugins/Goals/Controller.php +++ b/plugins/Goals/Controller.php @@ -544,8 +544,7 @@ private function getGoalReportsByDimensionTable( $conversions, $ecommerce = fals if ($conversions > 0) { // for non-Goals reports, we show the goals table - $customParams = $ecommerceCustomParams // TODO: not sure if this is necessary. only here to - // replicate logic of old code in table_by_dimension.tpl + $customParams = $ecommerceCustomParams + array('viewDataTable' => 'tableGoals', 'documentationForGoalsPage' => '1'); if (Piwik_Common::getRequestVar('idGoal', '') === '') // if no idGoal, use 0 for overview diff --git a/plugins/Referers/API.php b/plugins/Referers/API.php index 2dfaae895c1..a74f14290c9 100644 --- a/plugins/Referers/API.php +++ b/plugins/Referers/API.php @@ -99,7 +99,11 @@ public function getRefererType($idSite, $period, $date, $segment = false, $typeR } // set subtable IDs for each row to the label (which holds the int referrer type) - $this->setGetReferrerTypeSubtables($dataTable, $idSite, $period, $date, $segment, $expanded); + // NOTE: not yet possible to do this w/ DataTable_Array instances + if (!($dataTable instanceof Piwik_DataTable_Array)) + { + $this->setGetReferrerTypeSubtables($dataTable, $idSite, $period, $date, $segment, $expanded); + } // set referrer type column to readable value $dataTable->queueFilter('ColumnCallbackReplace', array('label', 'Piwik_getRefererTypeLabel')); @@ -114,6 +118,12 @@ public function getAll( $idSite, $period, $date, $segment = false ) { $dataTable = $this->getRefererType($idSite, $period, $date, $segment, $typeReferer = false, $idSubtable = false, $expanded = true); + + if ($dataTable instanceof Piwik_DataTable_Array) + { + throw new Exception("Referrers.getAll with multiple sites or dates is not supported (yet)."); + } + $dataTable = $dataTable->mergeSubtables($labelColumn = 'referrer_type', $useMetadataColumn = true); // presentation filters @@ -483,33 +493,26 @@ private function removeSubtableIds( $table ) */ private function setGetReferrerTypeSubtables( $dataTable, $idSite, $period, $date, $segment, $expanded ) { - if ($dataTable instanceof Piwik_DataTable_Array) // recurse for array datatables + foreach ($dataTable->getRows() as $row) { - throw new Exception("Referrers.getAll with multiple sites or dates is not supported (yet)."); - } - else - { - foreach ($dataTable->getRows() as $row) + $typeReferrer = $row->getColumn('label'); + if ($typeReferrer != Piwik_Common::REFERER_TYPE_DIRECT_ENTRY) { - $typeReferrer = $row->getColumn('label'); - if ($typeReferrer != Piwik_Common::REFERER_TYPE_DIRECT_ENTRY) + if (!$expanded) // if we don't want the expanded datatable, then don't do any extra queries { - if (!$expanded) // if we don't want the expanded datatable, then don't do any extra queries - { - $row->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = $typeReferrer; - } - else // otherwise, we have to get the othe datatables + $row->c[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = $typeReferrer; + } + else // otherwise, we have to get the othe datatables + { + $subtable = $this->getRefererType($idSite, $period, $date, $segment, $type = false, + $idSubtable = $typeReferrer); + + if ($expanded) { - $subtable = $this->getRefererType($idSite, $period, $date, $segment, $type = false, - $idSubtable = $typeReferrer); - - if ($expanded) - { - $subtable->applyQueuedFilters(); - } - - $row->setSubtable($subtable); + $subtable->applyQueuedFilters(); } + + $row->setSubtable($subtable); } } } diff --git a/plugins/Referers/Controller.php b/plugins/Referers/Controller.php index 9c9f6924f02..9561c45cc20 100644 --- a/plugins/Referers/Controller.php +++ b/plugins/Referers/Controller.php @@ -79,8 +79,47 @@ function index() $view->urlSparklineDistinctWebsites = $this->getUrlSparkline('getLastDistinctWebsitesGraph'); $view->urlSparklineDistinctCampaigns = $this->getUrlSparkline('getLastDistinctCampaignsGraph'); + $view->referrersReportsByDimension = $this->getReferrersReportsByDimensionView($totalVisits); + echo $view->render(); } + + /** + * Returns HTML for the Referrers Overview page that categorizes Referrer reports + * & allows the user to switch between them. + * + * @param int $visits The number of visits for this period & site. If <= 0, the + * reports are not shown, since they will have no data. + * @return string The report viewer HTML. + */ + private function getReferrersReportsByDimensionView( $visits ) + { + $result = ''; + + // only display the reports by dimension view if there are visits + if ($visits > 0) + { + $referrersReportsByDimension = new Piwik_View_ReportsByDimension(); + + $referrersReportsByDimension->addReport( + 'Referers_ViewAllReferrers', 'Referers_WidgetGetAll', 'Referers.getAll'); + + $byTypeCategory = Piwik_Translate('Referers_ViewReferrersBy', Piwik_Translate('Live_GoalType')); + $referrersReportsByDimension->addReport( + $byTypeCategory, 'Referers_WidgetKeywords', 'Referers.getKeywords'); + $referrersReportsByDimension->addReport($byTypeCategory, 'SitesManager_Sites', 'Referers.getWebsites'); + $referrersReportsByDimension->addReport($byTypeCategory, 'Referers_Campaigns', 'Referers.getCampaigns'); + + $bySourceCategory = Piwik_Translate('Referers_ViewReferrersBy', Piwik_Translate('General_Source')); + $referrersReportsByDimension->addReport($bySourceCategory, 'Referers_Socials', 'Referers.getSocials'); + $referrersReportsByDimension->addReport( + $bySourceCategory, 'Referers_SearchEngines', 'Referers.getSearchEngines'); + + $result = $referrersReportsByDimension->render(); + } + + return $result; + } function getSearchEnginesAndKeywords() { diff --git a/plugins/Referers/templates/index.tpl b/plugins/Referers/templates/index.tpl index 005f3fab118..9b7b1715a83 100644 --- a/plugins/Referers/templates/index.tpl +++ b/plugins/Referers/templates/index.tpl @@ -24,31 +24,38 @@
-

-

+

+

{'General_MoreDetails'|translate} ({'General_Show_js'|translate})

-

+
+ +

+

{'General_View'|translate} + {'Referers_SubmenuSearchEngines'|translate}, + {'Referers_SubmenuWebsites'|translate}, + {'Referers_SubmenuCampaigns'|translate}.
@@ -59,11 +66,8 @@
-

{'General_View'|translate} - {'Referers_SubmenuSearchEngines'|translate}, - {'Referers_SubmenuWebsites'|translate}, - {'Referers_SubmenuCampaigns'|translate}. -

+

{'Referers_ReferrersOverview'|translate}

+{$referrersReportsByDimension} {include file="CoreHome/templates/sparkline_footer.tpl"} diff --git a/tests/PHPUnit/Integration/expected/test_noVisit_PeriodIsLast__Referers.getRefererType_day.xml b/tests/PHPUnit/Integration/expected/test_noVisit_PeriodIsLast__Referers.getRefererType_day.xml index 2fedab5daa4..106f23f16bb 100644 --- a/tests/PHPUnit/Integration/expected/test_noVisit_PeriodIsLast__Referers.getRefererType_day.xml +++ b/tests/PHPUnit/Integration/expected/test_noVisit_PeriodIsLast__Referers.getRefererType_day.xml @@ -1,4 +1,10 @@ - - - \ No newline at end of file + + + + + + + + + \ No newline at end of file diff --git a/tests/PHPUnit/Integration/expected/test_noVisit_PeriodIsLast__Referers.getRefererType_week.xml b/tests/PHPUnit/Integration/expected/test_noVisit_PeriodIsLast__Referers.getRefererType_week.xml index 2fedab5daa4..5cfb246edc1 100644 --- a/tests/PHPUnit/Integration/expected/test_noVisit_PeriodIsLast__Referers.getRefererType_week.xml +++ b/tests/PHPUnit/Integration/expected/test_noVisit_PeriodIsLast__Referers.getRefererType_week.xml @@ -1,4 +1,10 @@ - - - \ No newline at end of file + + + + + + + + + \ No newline at end of file