diff options
author | Stefan Giehl <stefan@matomo.org> | 2019-03-11 16:26:37 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-11 16:26:37 +0300 |
commit | e1c1f12593034ae1fc0bfcbd17bf2cf908cac3bf (patch) | |
tree | 0b36ab8f848acc8b8281b10be8cde9507440d7bb /plugins | |
parent | ef48b1b97b00cec4540106fff49feaefaa1bf059 (diff) |
Make it possible to define joins for log tables using `getWaysToJoinToOtherLogTables` (#14062)
* Make it possible to define joins for log tables using getWaysToJoinToOtherLogTables
* Adds some tests for custom log table joins
* add missing log tables joined using getWaysToJoinToOtherLogTables
* automatically add log tables up the hierarchy
* code improvements
* Adds new ExampleLogTables plugin giving a showcase for custom log tables
* specifiy table name in userid archiver to fix query if custom log table joins on user_id column
* fix tests
* Adds log table that does only indirectly join with log_visit
* Allow defining joins on visit and action
* update ui files
Diffstat (limited to 'plugins')
23 files changed, 766 insertions, 1 deletions
diff --git a/plugins/ExampleLogTables/Columns/GroupAttributeAdmin.php b/plugins/ExampleLogTables/Columns/GroupAttributeAdmin.php new file mode 100644 index 0000000000..3c11627058 --- /dev/null +++ b/plugins/ExampleLogTables/Columns/GroupAttributeAdmin.php @@ -0,0 +1,14 @@ +<?php +namespace Piwik\Plugins\ExampleLogTables\Columns; + +use Piwik\Columns\Dimension; + +class GroupAttributeAdmin extends Dimension +{ + protected $dbTableName = 'log_group'; + protected $category = 'General_Visitors'; + protected $type = self::TYPE_BOOL; + protected $columnName = 'is_admin'; + protected $segmentName = 'isadmin'; + protected $nameSingular = 'Admin privileges'; +} diff --git a/plugins/ExampleLogTables/Columns/UserAttributeGender.php b/plugins/ExampleLogTables/Columns/UserAttributeGender.php new file mode 100644 index 0000000000..4a5ef0ab2c --- /dev/null +++ b/plugins/ExampleLogTables/Columns/UserAttributeGender.php @@ -0,0 +1,14 @@ +<?php +namespace Piwik\Plugins\ExampleLogTables\Columns; + +use Piwik\Columns\Dimension; + +class UserAttributeGender extends Dimension +{ + protected $dbTableName = 'log_custom'; + protected $category = 'General_Visitors'; + protected $type = self::TYPE_TEXT; + protected $columnName = 'gender'; + protected $segmentName = 'attrgender'; + protected $nameSingular = 'Gender'; +} diff --git a/plugins/ExampleLogTables/Dao/CustomGroupLog.php b/plugins/ExampleLogTables/Dao/CustomGroupLog.php new file mode 100644 index 0000000000..2b71ff33e6 --- /dev/null +++ b/plugins/ExampleLogTables/Dao/CustomGroupLog.php @@ -0,0 +1,66 @@ +<?php +/** + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\ExampleLogTables\Dao; + +use Piwik\Common; +use Piwik\Db; +use Piwik\DbHelper; + +class CustomGroupLog +{ + private $table = 'log_group'; + private $tablePrefixed = ''; + + public function __construct() + { + $this->tablePrefixed = Common::prefixTable($this->table); + } + + public function install() + { + DbHelper::createTable($this->table, " + `group` VARCHAR(30) NOT NULL, + `is_admin` TINYINT(1) NOT NULL, + PRIMARY KEY (`group`)"); + } + + public function uninstall() + { + Db::query(sprintf('DROP TABLE IF EXISTS `%s`', $this->tablePrefixed)); + } + + private function getDb() + { + return Db::get(); + } + + public function getAllRecords() + { + return $this->getDb()->fetchAll('SELECT * FROM ' . $this->tablePrefixed); + } + + public function addGroupInformation($group, $isAdmin) + { + $columns = array( + 'group' => $group, + 'is_admin' => $isAdmin + ); + + $bind = array_values($columns); + $placeholder = Common::getSqlStringFieldsArray($columns); + + $sql = sprintf('INSERT INTO %s (`%s`) VALUES(%s)', + $this->tablePrefixed, implode('`,`', array_keys($columns)), $placeholder); + + $db = $this->getDb(); + + $db->query($sql, $bind); + } +} + diff --git a/plugins/ExampleLogTables/Dao/CustomUserLog.php b/plugins/ExampleLogTables/Dao/CustomUserLog.php new file mode 100644 index 0000000000..50f3016301 --- /dev/null +++ b/plugins/ExampleLogTables/Dao/CustomUserLog.php @@ -0,0 +1,68 @@ +<?php +/** + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\ExampleLogTables\Dao; + +use Piwik\Common; +use Piwik\Db; +use Piwik\DbHelper; + +class CustomUserLog +{ + private $table = 'log_custom'; + private $tablePrefixed = ''; + + public function __construct() + { + $this->tablePrefixed = Common::prefixTable($this->table); + } + + public function install() + { + DbHelper::createTable($this->table, " + `user_id` VARCHAR(200) NOT NULL, + `gender` VARCHAR(30) NOT NULL, + `group` VARCHAR(30) NOT NULL, + PRIMARY KEY (user_id)"); + } + + public function uninstall() + { + Db::query(sprintf('DROP TABLE IF EXISTS `%s`', $this->tablePrefixed)); + } + + private function getDb() + { + return Db::get(); + } + + public function getAllRecords() + { + return $this->getDb()->fetchAll('SELECT * FROM ' . $this->tablePrefixed); + } + + public function addUserInformation($userId, $group, $gender) + { + $columns = array( + 'user_id' => $userId, + 'group' => $group, + 'gender' => $gender + ); + + $bind = array_values($columns); + $placeholder = Common::getSqlStringFieldsArray($columns); + + $sql = sprintf('INSERT INTO %s (`%s`) VALUES(%s)', + $this->tablePrefixed, implode('`,`', array_keys($columns)), $placeholder); + + $db = $this->getDb(); + + $db->query($sql, $bind); + } +} + diff --git a/plugins/ExampleLogTables/ExampleLogTables.php b/plugins/ExampleLogTables/ExampleLogTables.php new file mode 100644 index 0000000000..caf83d594b --- /dev/null +++ b/plugins/ExampleLogTables/ExampleLogTables.php @@ -0,0 +1,26 @@ +<?php +/** + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\ExampleLogTables; + +use Piwik\Plugins\ExampleLogTables\Dao\CustomUserLog; +use Piwik\Plugins\ExampleLogTables\Dao\CustomGroupLog; + +class ExampleLogTables extends \Piwik\Plugin +{ + public function install() + { + // Install custom log table [disabled as example only] + + // $userLog = new CustomUserLog(); + // $userLog->install(); + + // $userLog = new CustomGroupLog(); + // $userLog->install(); + } +}
\ No newline at end of file diff --git a/plugins/ExampleLogTables/Tracker/LogTable/CustomGroupLog.php b/plugins/ExampleLogTables/Tracker/LogTable/CustomGroupLog.php new file mode 100644 index 0000000000..7ee199bc11 --- /dev/null +++ b/plugins/ExampleLogTables/Tracker/LogTable/CustomGroupLog.php @@ -0,0 +1,34 @@ +<?php +/** + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\ExampleLogTables\Tracker\LogTable; + +use Piwik\Tracker\LogTable; + +class CustomGroupLog extends LogTable +{ + public function getName() + { + return 'log_group'; + } + + public function getIdColumn() + { + return 'group'; + } + + public function getPrimaryKey() + { + return ['group']; + } + + public function getWaysToJoinToOtherLogTables() + { + return ['log_custom' => 'group']; + } +} diff --git a/plugins/ExampleLogTables/Tracker/LogTable/CustomUserLog.php b/plugins/ExampleLogTables/Tracker/LogTable/CustomUserLog.php new file mode 100644 index 0000000000..5cbc20d83a --- /dev/null +++ b/plugins/ExampleLogTables/Tracker/LogTable/CustomUserLog.php @@ -0,0 +1,34 @@ +<?php +/** + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + */ +namespace Piwik\Plugins\ExampleLogTables\Tracker\LogTable; + +use Piwik\Tracker\LogTable; + +class CustomUserLog extends LogTable +{ + public function getName() + { + return 'log_custom'; + } + + public function getIdColumn() + { + return 'user_id'; + } + + public function getPrimaryKey() + { + return ['user_id']; + } + + public function getWaysToJoinToOtherLogTables() + { + return ['log_visit' => 'user_id']; + } +} diff --git a/plugins/ExampleLogTables/plugin.json b/plugins/ExampleLogTables/plugin.json new file mode 100644 index 0000000000..3e6442de06 --- /dev/null +++ b/plugins/ExampleLogTables/plugin.json @@ -0,0 +1,29 @@ +{ + "name": "ExampleLogTables", + "description": "Matomo Platform showcase: how to create custom log tables.", + "version": "0.1.0", + "theme": false, + "require": { + "piwik": ">=3.0.0-b1,<4.0.0-b1" + }, + "authors": [ + { + "name": "Matomo", + "email": "", + "homepage": "" + } + ], + "support": { + "email": "", + "issues": "", + "forum": "", + "irc": "", + "wiki": "", + "source": "", + "docs": "", + "rss": "" + }, + "homepage": "", + "license": "GPL v3+", + "keywords": [] +} diff --git a/plugins/ExampleLogTables/tests/Fixtures/VisitsWithUserIdAndCustomData.php b/plugins/ExampleLogTables/tests/Fixtures/VisitsWithUserIdAndCustomData.php new file mode 100644 index 0000000000..4324e58d54 --- /dev/null +++ b/plugins/ExampleLogTables/tests/Fixtures/VisitsWithUserIdAndCustomData.php @@ -0,0 +1,110 @@ +<?php +/** + * Matomo - free/libre analytics platform + * + * @link https://matomo.org + * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ +namespace Piwik\Plugins\ExampleLogTables\tests\Fixtures; + +use Piwik\Date; +use Piwik\Plugins\ExampleLogTables\Dao\CustomGroupLog; +use Piwik\Plugins\ExampleLogTables\Dao\CustomUserLog; +use Piwik\Tests\Framework\Fixture; + +class VisitsWithUserIdAndCustomData extends Fixture +{ + public $dateTime = '2018-02-01 11:22:33'; + public $idSite = 1; + + private static $countryCodes = ['CA', 'CN', 'DE', 'ES', 'FR', 'IE', 'IN', 'IT', 'MX', 'PT', 'RU', 'GB', 'US']; + + public function setUp() + { + if (!self::siteCreated($idSite = 1)) { + self::createWebsite($this->dateTime); + } + + // set up database tables + $userLog = new CustomUserLog(); + $userLog->install(); + $groupLog = new CustomGroupLog(); + $groupLog->install(); + + $this->trackVisits(); + $this->insertCustomUserLogData(); + $this->insertCustomGroupLogData(); + } + + private function trackVisits() + { + $t = self::getTracker($this->idSite, $this->dateTime, $defaultInit = true); + $t->setTokenAuth(self::getTokenAuth()); + $t->enableBulkTracking(); + + foreach (array('user1', 'user2', 'user3', 'user4', false) as $key => $userId) { + for ($numVisits = 0; $numVisits < ($key+1) * 10; $numVisits++) { + $t->setUserId($userId); + $t->setPlugins($numVisits % 3 == 0, $numVisits % 5 == 0, $numVisits % 7 == 0); + $t->setBrowserHasCookies($numVisits % 3 == 0); + $t->setCountry(self::$countryCodes[$numVisits % count(self::$countryCodes)]); + + if ($numVisits % 5 == 0) { + $t->doTrackSiteSearch('some search term' . $numVisits); + } + + if ($numVisits % 4 == 0) { + $t->doTrackEvent('Event action ' . $numVisits, 'event cat ' . $numVisits); + } + + if ($numVisits % 7 == 0) { + $t->doTrackContentInteraction('click', 'slider ' . $numVisits%4); + } + + if ($numVisits % 7 == 4) { + $t->doTrackAction('http://out.link', 'outlink'); + } + + if ($numVisits % 5 == 3) { + $t->setEcommerceView('SKU VERY nice indeed ' . ($numVisits%3), 'PRODUCT name ' . ($numVisits%4), 'category ' . ($numVisits%5), $numVisits*2.79); + } + + $t->setForceNewVisit(); + $t->setUrl('http://example.org/my/dir/page' . ($numVisits % 4)); + + $visitDateTime = Date::factory($this->dateTime)->addHour($numVisits*6)->getDatetime(); + $t->setForceVisitDateTime($visitDateTime); + + if ($numVisits % 7 == 0) { + $t->doTrackAction('http://example.org/download.pdf', 'download'); + } + + self::assertTrue($t->doTrackPageView('incredible title ' . ($numVisits % 3))); + + if ($numVisits % 9 == 0) { + $t->setForceVisitDateTime(Date::factory($this->dateTime)->addHour($numVisits*6.1)->getDatetime()); + $t->addEcommerceItem('SKU VERY nice indeed ' . ($numVisits%3), 'PRODUCT name ' . ($numVisits%4), 'category ' . ($numVisits%5), $numVisits*2.79); + self::assertTrue($t->doTrackEcommerceCartUpdate($numVisits*17)); + } + } + } + + self::checkBulkTrackingResponse($t->doBulkTrack()); + } + + private function insertCustomUserLogData() + { + $customLog = new CustomUserLog(); + $customLog->addUserInformation('user1', 'admin', 'men'); + $customLog->addUserInformation('user2', 'user', 'women'); + $customLog->addUserInformation('user3', 'admin', 'women'); + $customLog->addUserInformation('user4', '', 'men'); + } + + private function insertCustomGroupLogData() + { + $customGroup = new CustomGroupLog(); + $customGroup->addGroupInformation('admin', 1); + $customGroup->addGroupInformation('user', 0); + } +}
\ No newline at end of file diff --git a/plugins/ExampleLogTables/tests/System/CustomLogTablesTest.php b/plugins/ExampleLogTables/tests/System/CustomLogTablesTest.php new file mode 100644 index 0000000000..1cf254f3dc --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/CustomLogTablesTest.php @@ -0,0 +1,138 @@ +<?php +namespace Piwik\Plugins\ExampleLogTables\tests\System; + +use Piwik\Plugins\ExampleLogTables\tests\Fixtures\VisitsWithUserIdAndCustomData; +use Piwik\Tests\Framework\TestCase\SystemTestCase; +use Piwik\Tests\Framework\TestRequest\ApiTestConfig; +use Piwik\Tests\Framework\TestRequest\Response; + +/** + * Testing Custom Log Tables + * + * @group ExampleLogTables + * @group Plugins + */ +class CustomLogTablesTest extends SystemTestCase +{ + /** + * @var VisitsWithUserIdAndCustomData + */ + public static $fixture = null; // initialized below class definition + + /** + * @dataProvider getApiForTesting + */ + public function testApi($api, $params) + { + $this->runApiTests($api, $params); + } + + /** + * @dataProvider getSegmentsToTest + */ + public function testNoApiReturnsError($segment) + { + $dateTime = self::$fixture->dateTime; + $idSite1 = self::$fixture->idSite; + + $params = [ + 'idSite' => $idSite1, + 'date' => $dateTime, + 'periods' => 'month', + 'setDateLastN' => false, + 'format' => 'JSON', + 'segment' => $segment, + 'testSuffix' => '' + ]; + + $testConfig = new ApiTestConfig($params); + $testRequests = $this->getTestRequestsCollection('all', $testConfig, 'all'); + + foreach ($testRequests->getRequestUrls() as $apiId => $requestUrl) { + $response = Response::loadFromApi($params, $requestUrl, false); + $decoded = json_decode($response->getResponseText(), true); + + if (is_array($decoded) && isset($decoded['result']) && $decoded['result'] == 'error') { + $this->fail('API returned an error when requesting ' . http_build_query($requestUrl) . "\nMessage: " . $decoded['message']); + } + } + } + + public function getSegmentsToTest() + { + return [ + ['attrgender==men'], + ['isadmin==1'], + ]; + } + + public function getApiForTesting() + { + $dateTime = self::$fixture->dateTime; + $idSite1 = self::$fixture->idSite; + + $result = [ + [[ + 'Actions.get', + 'UserId.getUsers', + 'VisitsSummary.get' + ], [ + 'idSite' => $idSite1, + 'date' => $dateTime, + 'periods' => 'month', + 'setDateLastN' => false, + 'segment' => 'attrgender==men', + 'testSuffix' => '_men'] + ], + [[ + 'Actions.get', + 'UserId.getUsers', + 'VisitsSummary.get' + ], [ + 'idSite' => $idSite1, + 'date' => $dateTime, + 'periods' => 'month', + 'setDateLastN' => false, + 'segment' => 'attrgender==women', + 'testSuffix' => '_women'] + ], + [[ + 'Actions.get', + 'UserId.getUsers', + 'VisitsSummary.get' + ], [ + 'idSite' => $idSite1, + 'date' => $dateTime, + 'periods' => 'month', + 'setDateLastN' => false, + 'segment' => 'isadmin==1', + 'testSuffix' => '_admin'] + ], + [[ + 'Actions.get', + 'UserId.getUsers', + 'VisitsSummary.get' + ], [ + 'idSite' => $idSite1, + 'date' => $dateTime, + 'periods' => 'month', + 'setDateLastN' => false, + 'testSuffix' => '_all'] + ], + ]; + + return $result; + } + + public static function getOutputPrefix() + { + return 'ExampleLogTables'; + } + + public static function getPathToTestDirectory() + { + return dirname(__FILE__); + } +} + +CustomLogTablesTest::$fixture = new VisitsWithUserIdAndCustomData(); diff --git a/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_admin__Actions.get_month.xml b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_admin__Actions.get_month.xml new file mode 100644 index 0000000000..d73153a828 --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_admin__Actions.get_month.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <nb_pageviews>45</nb_pageviews> + <nb_uniq_pageviews>40</nb_uniq_pageviews> + <nb_downloads>7</nb_downloads> + <nb_uniq_downloads>7</nb_uniq_downloads> + <nb_outlinks>0</nb_outlinks> + <nb_uniq_outlinks>0</nb_uniq_outlinks> + <nb_searches>8</nb_searches> + <nb_keywords>6</nb_keywords> +</result>
\ No newline at end of file diff --git a/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_admin__UserId.getUsers_month.xml b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_admin__UserId.getUsers_month.xml new file mode 100644 index 0000000000..e9d5ed7b27 --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_admin__UserId.getUsers_month.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>user3</label> + <nb_visits>34</nb_visits> + <nb_actions>53</nb_actions> + <max_actions>3</max_actions> + <sum_visit_length>20</sum_visit_length> + <bounce_count>19</bounce_count> + <nb_visits_converted>0</nb_visits_converted> + <sum_daily_nb_uniq_visitors>8</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>8</sum_daily_nb_users> + + </row> + <row> + <label>user1</label> + <nb_visits>12</nb_visits> + <nb_actions>18</nb_actions> + <max_actions>3</max_actions> + <sum_visit_length>6</sum_visit_length> + <bounce_count>7</bounce_count> + <nb_visits_converted>0</nb_visits_converted> + <sum_daily_nb_uniq_visitors>3</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>3</sum_daily_nb_users> + + </row> +</result>
\ No newline at end of file diff --git a/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_admin__VisitsSummary.get_month.xml b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_admin__VisitsSummary.get_month.xml new file mode 100644 index 0000000000..eeeb691530 --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_admin__VisitsSummary.get_month.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <nb_uniq_visitors>2</nb_uniq_visitors> + <nb_users>2</nb_users> + <nb_visits>46</nb_visits> + <nb_actions>71</nb_actions> + <nb_visits_converted>0</nb_visits_converted> + <bounce_count>26</bounce_count> + <sum_visit_length>26</sum_visit_length> + <max_actions>3</max_actions> + <bounce_rate>57%</bounce_rate> + <nb_actions_per_visit>1.5</nb_actions_per_visit> + <avg_time_on_site>1</avg_time_on_site> +</result>
\ No newline at end of file diff --git a/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_all__Actions.get_month.xml b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_all__Actions.get_month.xml new file mode 100644 index 0000000000..951eb7a039 --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_all__Actions.get_month.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <nb_pageviews>171</nb_pageviews> + <nb_uniq_pageviews>156</nb_uniq_pageviews> + <nb_downloads>24</nb_downloads> + <nb_uniq_downloads>24</nb_uniq_downloads> + <nb_outlinks>0</nb_outlinks> + <nb_uniq_outlinks>0</nb_uniq_outlinks> + <nb_searches>30</nb_searches> + <nb_keywords>10</nb_keywords> +</result>
\ No newline at end of file diff --git a/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_all__UserId.getUsers_month.xml b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_all__UserId.getUsers_month.xml new file mode 100644 index 0000000000..537029b08e --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_all__UserId.getUsers_month.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>user4</label> + <nb_visits>45</nb_visits> + <nb_actions>70</nb_actions> + <max_actions>3</max_actions> + <sum_visit_length>25</sum_visit_length> + <bounce_count>25</bounce_count> + <nb_visits_converted>0</nb_visits_converted> + <sum_daily_nb_uniq_visitors>11</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>11</sum_daily_nb_users> + + </row> + <row> + <label>user3</label> + <nb_visits>34</nb_visits> + <nb_actions>53</nb_actions> + <max_actions>3</max_actions> + <sum_visit_length>20</sum_visit_length> + <bounce_count>19</bounce_count> + <nb_visits_converted>0</nb_visits_converted> + <sum_daily_nb_uniq_visitors>8</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>8</sum_daily_nb_users> + + </row> + <row> + <label>user2</label> + <nb_visits>22</nb_visits> + <nb_actions>35</nb_actions> + <max_actions>3</max_actions> + <sum_visit_length>12</sum_visit_length> + <bounce_count>12</bounce_count> + <nb_visits_converted>0</nb_visits_converted> + <sum_daily_nb_uniq_visitors>6</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>6</sum_daily_nb_users> + + </row> + <row> + <label>user1</label> + <nb_visits>12</nb_visits> + <nb_actions>18</nb_actions> + <max_actions>3</max_actions> + <sum_visit_length>6</sum_visit_length> + <bounce_count>7</bounce_count> + <nb_visits_converted>0</nb_visits_converted> + <sum_daily_nb_uniq_visitors>3</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>3</sum_daily_nb_users> + + </row> +</result>
\ No newline at end of file diff --git a/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_all__VisitsSummary.get_month.xml b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_all__VisitsSummary.get_month.xml new file mode 100644 index 0000000000..f22cfae43b --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_all__VisitsSummary.get_month.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <nb_uniq_visitors>54</nb_uniq_visitors> + <nb_users>4</nb_users> + <nb_visits>195</nb_visits> + <nb_actions>264</nb_actions> + <nb_visits_converted>0</nb_visits_converted> + <bounce_count>130</bounce_count> + <sum_visit_length>80</sum_visit_length> + <max_actions>3</max_actions> + <bounce_rate>67%</bounce_rate> + <nb_actions_per_visit>1.4</nb_actions_per_visit> + <avg_time_on_site>0</avg_time_on_site> +</result>
\ No newline at end of file diff --git a/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_men__Actions.get_month.xml b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_men__Actions.get_month.xml new file mode 100644 index 0000000000..052c729dda --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_men__Actions.get_month.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <nb_pageviews>57</nb_pageviews> + <nb_uniq_pageviews>50</nb_uniq_pageviews> + <nb_downloads>8</nb_downloads> + <nb_uniq_downloads>8</nb_uniq_downloads> + <nb_outlinks>0</nb_outlinks> + <nb_uniq_outlinks>0</nb_uniq_outlinks> + <nb_searches>10</nb_searches> + <nb_keywords>8</nb_keywords> +</result>
\ No newline at end of file diff --git a/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_men__UserId.getUsers_month.xml b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_men__UserId.getUsers_month.xml new file mode 100644 index 0000000000..f88f48454a --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_men__UserId.getUsers_month.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>user4</label> + <nb_visits>45</nb_visits> + <nb_actions>70</nb_actions> + <max_actions>3</max_actions> + <sum_visit_length>25</sum_visit_length> + <bounce_count>25</bounce_count> + <nb_visits_converted>0</nb_visits_converted> + <sum_daily_nb_uniq_visitors>11</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>11</sum_daily_nb_users> + + </row> + <row> + <label>user1</label> + <nb_visits>12</nb_visits> + <nb_actions>18</nb_actions> + <max_actions>3</max_actions> + <sum_visit_length>6</sum_visit_length> + <bounce_count>7</bounce_count> + <nb_visits_converted>0</nb_visits_converted> + <sum_daily_nb_uniq_visitors>3</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>3</sum_daily_nb_users> + + </row> +</result>
\ No newline at end of file diff --git a/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_men__VisitsSummary.get_month.xml b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_men__VisitsSummary.get_month.xml new file mode 100644 index 0000000000..4e9a3bd824 --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_men__VisitsSummary.get_month.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <nb_uniq_visitors>2</nb_uniq_visitors> + <nb_users>2</nb_users> + <nb_visits>57</nb_visits> + <nb_actions>88</nb_actions> + <nb_visits_converted>0</nb_visits_converted> + <bounce_count>32</bounce_count> + <sum_visit_length>31</sum_visit_length> + <max_actions>3</max_actions> + <bounce_rate>56%</bounce_rate> + <nb_actions_per_visit>1.5</nb_actions_per_visit> + <avg_time_on_site>1</avg_time_on_site> +</result>
\ No newline at end of file diff --git a/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_women__Actions.get_month.xml b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_women__Actions.get_month.xml new file mode 100644 index 0000000000..4269b53424 --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_women__Actions.get_month.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <nb_pageviews>57</nb_pageviews> + <nb_uniq_pageviews>50</nb_uniq_pageviews> + <nb_downloads>8</nb_downloads> + <nb_uniq_downloads>8</nb_uniq_downloads> + <nb_outlinks>0</nb_outlinks> + <nb_uniq_outlinks>0</nb_uniq_outlinks> + <nb_searches>10</nb_searches> + <nb_keywords>6</nb_keywords> +</result>
\ No newline at end of file diff --git a/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_women__UserId.getUsers_month.xml b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_women__UserId.getUsers_month.xml new file mode 100644 index 0000000000..d9abec4587 --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_women__UserId.getUsers_month.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <row> + <label>user3</label> + <nb_visits>34</nb_visits> + <nb_actions>53</nb_actions> + <max_actions>3</max_actions> + <sum_visit_length>20</sum_visit_length> + <bounce_count>19</bounce_count> + <nb_visits_converted>0</nb_visits_converted> + <sum_daily_nb_uniq_visitors>8</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>8</sum_daily_nb_users> + + </row> + <row> + <label>user2</label> + <nb_visits>22</nb_visits> + <nb_actions>35</nb_actions> + <max_actions>3</max_actions> + <sum_visit_length>12</sum_visit_length> + <bounce_count>12</bounce_count> + <nb_visits_converted>0</nb_visits_converted> + <sum_daily_nb_uniq_visitors>6</sum_daily_nb_uniq_visitors> + <sum_daily_nb_users>6</sum_daily_nb_users> + + </row> +</result>
\ No newline at end of file diff --git a/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_women__VisitsSummary.get_month.xml b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_women__VisitsSummary.get_month.xml new file mode 100644 index 0000000000..9c82720353 --- /dev/null +++ b/plugins/ExampleLogTables/tests/System/expected/test_ExampleLogTables_women__VisitsSummary.get_month.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8" ?> +<result> + <nb_uniq_visitors>2</nb_uniq_visitors> + <nb_users>2</nb_users> + <nb_visits>56</nb_visits> + <nb_actions>88</nb_actions> + <nb_visits_converted>0</nb_visits_converted> + <bounce_count>31</bounce_count> + <sum_visit_length>32</sum_visit_length> + <max_actions>3</max_actions> + <bounce_rate>55%</bounce_rate> + <nb_actions_per_visit>1.6</nb_actions_per_visit> + <avg_time_on_site>1</avg_time_on_site> +</result>
\ No newline at end of file diff --git a/plugins/UserId/Archiver.php b/plugins/UserId/Archiver.php index 28c32bf3c6..584f364d3c 100644 --- a/plugins/UserId/Archiver.php +++ b/plugins/UserId/Archiver.php @@ -80,7 +80,7 @@ class Archiver extends \Piwik\Plugin\Archiver /** @var \Zend_Db_Statement $query */ $query = $this->getLogAggregator()->queryVisitsByDimension( array(self::USER_ID_FIELD), - "$userIdFieldName IS NOT NULL AND $userIdFieldName != ''", + "log_visit.$userIdFieldName IS NOT NULL AND log_visit.$userIdFieldName != ''", array("LOWER(HEX($visitorIdFieldName)) as $visitorIdFieldName") ); |