-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add possibility to manage and view Intranet websites (#13473)
* Add possibility to manage and view Intranet websites #7724 * more tweaks * ui tests * fix some tests * added missing name * remove intranet setting, added test for tracking * fix various tests * remove test * Update RequestProcessor.php * Update en.json * fix some tests * do not throw exception if site does not exist * seeing just now it is fine to trigger exception * debug error * log only certain requests * Update piwik.php * Update JsProxyTest.php * trying to fix tests * remove debug code * trying to fix tests
- Loading branch information
Showing
41 changed files
with
734 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
plugins/Dashboard/tests/UI/expected-screenshots/DashboardManager_removed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
plugins/Dashboard/tests/UI/expected-screenshots/Dashboard_loaded_token_auth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tests/System/processed/*xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
namespace Piwik\Plugins\IntranetMeasurable; | ||
|
||
class IntranetMeasurable extends \Piwik\Plugin | ||
{ | ||
public function isTrackerPlugin() | ||
{ | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
namespace Piwik\Plugins\IntranetMeasurable; | ||
|
||
use Piwik\Settings\Setting; | ||
|
||
class MeasurableSettings extends \Piwik\Plugins\WebsiteMeasurable\MeasurableSettings | ||
{ | ||
/** @var Setting */ | ||
public $trustvisitorcookies; | ||
|
||
protected function shouldShowSettingsForType($type) | ||
{ | ||
return $type === Type::ID; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
*/ | ||
|
||
namespace Piwik\Plugins\IntranetMeasurable\Tracker; | ||
|
||
use Piwik\Container\StaticContainer; | ||
use Piwik\Exception\UnexpectedWebsiteFoundException; | ||
use Piwik\Plugins\IntranetMeasurable\Type; | ||
use Piwik\Tracker\Cache; | ||
use Piwik\Tracker\Request; | ||
|
||
class RequestProcessor extends \Piwik\Tracker\RequestProcessor | ||
{ | ||
private $didEnableSetting = false; | ||
private $settingName = 'ini.Tracker.trust_visitors_cookies'; | ||
|
||
public function manipulateRequest(Request $request) | ||
{ | ||
try { | ||
$site = Cache::getCacheWebsiteAttributes($request->getIdSite()); | ||
} catch (UnexpectedWebsiteFoundException $e) { | ||
return; | ||
} | ||
$isIntranetSite = !empty($site['type']) && $site['type'] === Type::ID; | ||
|
||
if ($isIntranetSite && !StaticContainer::get($this->settingName)) { | ||
$this->setTrustCookiesSetting(1); | ||
$this->didEnableSetting = true; | ||
} elseif ($this->didEnableSetting) { | ||
// we reset it in case of bulk tracking with different sites etc | ||
$this->setTrustCookiesSetting(0); | ||
$this->didEnableSetting = false; | ||
} | ||
} | ||
|
||
private function setTrustCookiesSetting($value) | ||
{ | ||
StaticContainer::get('Piwik\Tracker\VisitorRecognizer')->setTrustCookiesOnly($value); | ||
StaticContainer::getContainer()->set($this->settingName, $value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
/** | ||
* Matomo - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
* | ||
*/ | ||
namespace Piwik\Plugins\IntranetMeasurable; | ||
|
||
class Type extends \Piwik\Measurable\Type | ||
{ | ||
const ID = 'intranet'; | ||
protected $name = 'IntranetMeasurable_Intranet'; | ||
protected $namePlural = 'IntranetMeasurable_Intranets'; | ||
protected $description = 'IntranetMeasurable_IntranetDescription'; | ||
protected $howToSetupUrl = '?module=CoreAdminHome&action=trackingCodeGenerator'; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"IntranetMeasurable": { | ||
"Intranet": "Intranet Website", | ||
"Intranets": "Intranet Websites", | ||
"IntranetDescription": "An intranet measurable is just like a website but hosted on an internal network." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "IntranetMeasurable", | ||
"description": "Analytics for the web: lets you measure and analyze intranet websites." | ||
} |
94 changes: 94 additions & 0 deletions
94
plugins/IntranetMeasurable/tests/Fixtures/IntranetSitesWithVisits.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?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\IntranetMeasurable\tests\Fixtures; | ||
|
||
use Piwik\Date; | ||
use Piwik\Plugins\IntranetMeasurable\Type; | ||
use Piwik\Tests\Framework\Fixture; | ||
|
||
/** | ||
* Generates tracker testing data for our TrackingTest | ||
* | ||
* This Simple fixture adds one website and tracks one visit with couple pageviews and an ecommerce conversion | ||
*/ | ||
class IntranetSitesWithVisits extends Fixture | ||
{ | ||
public $dateTime = '2013-01-23 01:23:45'; | ||
public $idSite = 1; | ||
public $idSiteNotIntranet = 2; | ||
|
||
public function setUp() | ||
{ | ||
$this->setUpWebsites(); | ||
$this->trackVisits($this->idSite); | ||
$this->trackVisits($this->idSiteNotIntranet); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
// empty | ||
} | ||
|
||
private function setUpWebsites() | ||
{ | ||
if (!self::siteCreated($this->idSite)) { | ||
Fixture::createWebsite( | ||
'2014-01-02 03:04:05', $ecommerce = 0, $siteName = false, $siteUrl = false, | ||
$siteSearch = 1, $searchKeywordParameters = null, | ||
$searchCategoryParameters = null, $timezone = null, Type::ID | ||
); | ||
} | ||
|
||
if (!self::siteCreated($this->idSiteNotIntranet)) { | ||
Fixture::createWebsite('2014-01-02 03:04:05'); | ||
} | ||
} | ||
|
||
private function configureSameDevice(\PiwikTracker $t) | ||
{ | ||
// to make purpose of test more clear we configure the device partially... | ||
$t->setIp('56.11.55.70'); | ||
$t->setResolution(500, 200); | ||
$t->setPlugins(true, false, true, false, true); | ||
$t->setUserAgent('Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1'); | ||
|
||
return $t; | ||
} | ||
|
||
protected function trackVisits($idSite) | ||
{ | ||
// two visits... intranet will trust visitorId and generate two visits | ||
// regular website will only generate one visit and prefer configId | ||
$t = self::getTracker($idSite, $this->dateTime, $defaultInit = true); | ||
$this->configureSameDevice($t); | ||
$t->randomVisitorId = '1234567890123456'; | ||
|
||
$t->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(0.1)->getDatetime()); | ||
$t->setUrl('http://example.com/'); | ||
self::checkResponse($t->doTrackPageView('Viewing homepage')); | ||
|
||
$t->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(0.2)->getDatetime()); | ||
$t->setUrl('http://example.com/sub/page'); | ||
self::checkResponse($t->doTrackPageView('Second page view')); | ||
|
||
// different IP and different device but same visitor id... should still match this as unique visitor for intranet site | ||
// but not the other site | ||
$t = self::getTracker($idSite, $this->dateTime, $defaultInit = true); | ||
$this->configureSameDevice($t); | ||
$t->randomVisitorId = '1234567890123457'; | ||
|
||
$t->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(0.1)->getDatetime()); | ||
$t->setUrl('http://example.com/sub/page'); | ||
self::checkResponse($t->doTrackPageView('Viewing homepage')); | ||
|
||
$t->setForceVisitDateTime(Date::factory($this->dateTime)->addHour(0.2)->getDatetime()); | ||
$t->setUrl('http://example.com/?search=this is a site search query'); | ||
self::checkResponse($t->doTrackPageView('Site search query')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?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\IntranetMeasurable\tests\System; | ||
|
||
use Piwik\Plugins\IntranetMeasurable\tests\Fixtures\IntranetSitesWithVisits; | ||
use Piwik\Tests\Framework\TestCase\SystemTestCase; | ||
|
||
/** | ||
* @group IntranetMeasurable | ||
* @group TrackingTest | ||
* @group Plugins | ||
*/ | ||
class TrackingTest extends SystemTestCase | ||
{ | ||
/** | ||
* @var IntranetSitesWithVisits | ||
*/ | ||
public static $fixture = null; // initialized below class definition | ||
|
||
/** | ||
* @dataProvider getApiForTesting | ||
*/ | ||
public function testApi($api, $params) | ||
{ | ||
$this->runApiTests($api, $params); | ||
} | ||
|
||
public function getApiForTesting() | ||
{ | ||
$api = array( | ||
'API.get', | ||
); | ||
|
||
$apiToTest = array(); | ||
$apiToTest[] = array($api, | ||
array( | ||
'idSite' => self::$fixture->idSite, | ||
'date' => self::$fixture->dateTime, | ||
'periods' => array('day'), | ||
'testSuffix' => '_intranet' | ||
) | ||
); | ||
$apiToTest[] = array($api, | ||
array( | ||
'idSite' => self::$fixture->idSiteNotIntranet, | ||
'date' => self::$fixture->dateTime, | ||
'periods' => array('day'), | ||
'testSuffix' => '_notIntranet' | ||
) | ||
); | ||
|
||
return $apiToTest; | ||
} | ||
|
||
public static function getOutputPrefix() | ||
{ | ||
return ''; | ||
} | ||
|
||
public static function getPathToTestDirectory() | ||
{ | ||
return dirname(__FILE__); | ||
} | ||
|
||
} | ||
|
||
TrackingTest::$fixture = new IntranetSitesWithVisits(); |
Oops, something went wrong.