diff options
author | Matthieu Aubry <matt@piwik.org> | 2015-03-12 06:50:01 +0300 |
---|---|---|
committer | Matthieu Aubry <matt@piwik.org> | 2015-03-12 06:50:01 +0300 |
commit | ceff420236aa5d009d6f86dd6a676277eb13572b (patch) | |
tree | 9a38558eda81790647c1a9f26b8dd030c6db611e /plugins | |
parent | 1b8320facfdf0c72990a96cadeba28c84eea65e5 (diff) | |
parent | 06f3a4f8cbc0aaf0fb33269ba65947ff2e819d28 (diff) |
Merge pull request #7365 from piwik/no-data-welcome
Show the JS tracking code instead of the dashboard while no visit is tracked
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/SitesManager/Controller.php | 17 | ||||
-rw-r--r-- | plugins/SitesManager/SitesManager.php | 25 | ||||
-rw-r--r-- | plugins/SitesManager/lang/en.json | 3 | ||||
-rw-r--r-- | plugins/SitesManager/stylesheets/SitesManager.less | 19 | ||||
-rw-r--r-- | plugins/SitesManager/templates/siteWithoutData.twig | 25 | ||||
-rw-r--r-- | plugins/SitesManager/tests/UI/.gitignore | 2 | ||||
-rw-r--r-- | plugins/SitesManager/tests/UI/EmptySite_spec.js | 22 | ||||
-rw-r--r-- | plugins/SitesManager/tests/UI/expected-ui-screenshots/SitesManager_emptySiteDashboard.png | bin | 0 -> 103875 bytes |
8 files changed, 111 insertions, 2 deletions
diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php index e7299ab03e..bf810bf5bf 100644 --- a/plugins/SitesManager/Controller.php +++ b/plugins/SitesManager/Controller.php @@ -15,6 +15,7 @@ use Piwik\Piwik; use Piwik\SettingsPiwik; use Piwik\Site; use Piwik\Tracker\TrackerCodeGenerator; +use Piwik\Url; use Piwik\View; /** @@ -118,4 +119,20 @@ class Controller extends \Piwik\Plugin\ControllerAdmin header('Content-Disposition: attachment; filename="' . $filename . '"'); return file_get_contents($path . $filename); } + + public function siteWithoutData() + { + $javascriptGenerator = new TrackerCodeGenerator(); + $piwikUrl = Url::getCurrentUrlWithoutFileName(); + + return $this->renderTemplate('siteWithoutData', array( + 'siteName' => $this->site->getName(), + 'trackingHelp' => $this->renderTemplate('_displayJavascriptCode', array( + 'displaySiteName' => $this->site->getName(), + 'jsTag' => $javascriptGenerator->generate($this->idSite, $piwikUrl), + 'idSite' => $this->idSite, + 'piwikUrl' => $piwikUrl, + )), + )); + } } diff --git a/plugins/SitesManager/SitesManager.php b/plugins/SitesManager/SitesManager.php index f06ff69948..b9c5fa0736 100644 --- a/plugins/SitesManager/SitesManager.php +++ b/plugins/SitesManager/SitesManager.php @@ -7,8 +7,12 @@ * */ namespace Piwik\Plugins\SitesManager; + +use Piwik\Common; use Piwik\DataAccess\ArchiveInvalidator; +use Piwik\Db; use Piwik\Tracker\Cache; +use Piwik\Tracker\Model as TrackerModel; /** * @@ -29,10 +33,29 @@ class SitesManager extends \Piwik\Plugin 'AssetManager.getStylesheetFiles' => 'getStylesheetFiles', 'Tracker.Cache.getSiteAttributes' => 'recordWebsiteDataInCache', 'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys', - 'SitesManager.deleteSite.end' => 'onSiteDeleted' + 'SitesManager.deleteSite.end' => 'onSiteDeleted', + 'Request.dispatch' => 'redirectDashboardToWelcomePage', ); } + public function redirectDashboardToWelcomePage(&$module, &$action) + { + if ($module !== 'CoreHome' || $action !== 'index') { + return; + } + + $siteId = Common::getRequestVar('idSite', false, 'int'); + if (!$siteId) { + return; + } + + $trackerModel = new TrackerModel(); + if ($trackerModel->isSiteEmpty($siteId)) { + $module = 'SitesManager'; + $action = 'siteWithoutData'; + } + } + public function onSiteDeleted($idSite) { // we do not delete logs here on purpose (you can run these queries on the log_ tables to delete all data) diff --git a/plugins/SitesManager/lang/en.json b/plugins/SitesManager/lang/en.json index 072921ef48..7ee253b445 100644 --- a/plugins/SitesManager/lang/en.json +++ b/plugins/SitesManager/lang/en.json @@ -64,6 +64,9 @@ "ShowTrackingTag": "View Tracking code", "Sites": "Websites", "SiteSearchUse": "You can use Piwik to track and report what visitors are searching in your website's internal search engine.", + "SiteWithoutDataTitle": "No data has been recorded yet", + "SiteWithoutDataDescription": "No analytics data has been tracked for this website yet.", + "SiteWithoutDataSetupTracking": "Please set up the %1$sJavaScript tracking code%2$s on your website and refresh the page.", "SuperUserAccessCan": "A user with Super User access can also %s specify global settings%s for new websites.", "Timezone": "Time zone", "TrackingSiteSearch": "Tracking Internal Site Search", diff --git a/plugins/SitesManager/stylesheets/SitesManager.less b/plugins/SitesManager/stylesheets/SitesManager.less index de6c74f990..d847d0e8a7 100644 --- a/plugins/SitesManager/stylesheets/SitesManager.less +++ b/plugins/SitesManager/stylesheets/SitesManager.less @@ -35,4 +35,21 @@ td.editable-site-field:hover { .link_but:hover > span { text-decoration: underline; -}
\ No newline at end of file +} + +.site-without-data { + padding: 15px; + h2 { + border-bottom: 1px solid #ccc; + margin: 25px 0; + padding: 0 0 5px 0; + font-size: 24px; + } + h3 { + margin: 15px 0; + font-size: 18px; + line-height: 24px; + font-weight: normal; + color: black; + } +} diff --git a/plugins/SitesManager/templates/siteWithoutData.twig b/plugins/SitesManager/templates/siteWithoutData.twig new file mode 100644 index 0000000000..20b6326644 --- /dev/null +++ b/plugins/SitesManager/templates/siteWithoutData.twig @@ -0,0 +1,25 @@ +{% extends "dashboard.twig" %} + +{% block notification %}{% endblock %} + +{% block content %} + + {% include "@CoreHome/_siteSelectHeader.twig" %} + + <div class="site-without-data"> + + <h2>{{ 'SitesManager_SiteWithoutDataTitle'|translate }}</h2> + + <p> + {{ 'SitesManager_SiteWithoutDataDescription'|translate }} + {{ 'SitesManager_SiteWithoutDataSetupTracking'|translate('<a href="' ~ linkTo({ + 'module': 'CoreAdminHome', + 'action': 'trackingCodeGenerator', + }) ~ '">', '</a>')|raw }} + </p> + + {{ trackingHelp|raw }} + + </div> + +{% endblock %} diff --git a/plugins/SitesManager/tests/UI/.gitignore b/plugins/SitesManager/tests/UI/.gitignore new file mode 100644 index 0000000000..f39be478e7 --- /dev/null +++ b/plugins/SitesManager/tests/UI/.gitignore @@ -0,0 +1,2 @@ +/processed-ui-screenshots +/screenshot-diffs
\ No newline at end of file diff --git a/plugins/SitesManager/tests/UI/EmptySite_spec.js b/plugins/SitesManager/tests/UI/EmptySite_spec.js new file mode 100644 index 0000000000..704bda8721 --- /dev/null +++ b/plugins/SitesManager/tests/UI/EmptySite_spec.js @@ -0,0 +1,22 @@ +/*! + * Piwik - free/libre analytics platform + * + * Screenshot integration tests. + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +describe("EmptySite", function () { + this.timeout(0); + + var generalParams = 'idSite=4&period=day&date=2010-01-03'; + + it('should show the tracking code if the website has no recorded data', function (done) { + var urlToTest = "?" + generalParams + "&module=CoreHome&action=index"; + + expect.screenshot('emptySiteDashboard').to.be.captureSelector('.site-without-data', function (page) { + page.load(urlToTest); + }, done); + }); +}); diff --git a/plugins/SitesManager/tests/UI/expected-ui-screenshots/SitesManager_emptySiteDashboard.png b/plugins/SitesManager/tests/UI/expected-ui-screenshots/SitesManager_emptySiteDashboard.png Binary files differnew file mode 100644 index 0000000000..6834766331 --- /dev/null +++ b/plugins/SitesManager/tests/UI/expected-ui-screenshots/SitesManager_emptySiteDashboard.png |