Пример #1
0
 /**
  * Testing with some website specific and some global excluded query parameters
  * @group Core
  * @group Tracker
  * @group Tracker_Action
  * @dataProvider getTestUrls
  */
 public function testExcludeQueryParametersSiteAndGlobalExcluded($url, $filteredUrl)
 {
     // testing also that query parameters are case insensitive
     $excludedQueryParameters = 'P2,var[value][date]';
     $excludedGlobalParameters = 'blabla, P4';
     $this->setUpRootAccess();
     $idSite = Piwik_SitesManager_API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0, $excludedIps = '', $excludedQueryParameters);
     Piwik_SitesManager_API::getInstance()->setGlobalExcludedQueryParameters($excludedGlobalParameters);
     $this->assertEquals($filteredUrl[1], Piwik_Tracker_Action::excludeQueryParametersFromUrl($url, $idSite));
 }
Пример #2
0
 /** Render the area left of the iframe */
 public function renderSidebar()
 {
     $idSite = Piwik_Common::getRequestVar('idSite');
     $period = Piwik_Common::getRequestVar('period');
     $date = Piwik_Common::getRequestVar('date');
     $currentUrl = Piwik_Common::getRequestVar('currentUrl');
     $currentUrl = Piwik_Common::unsanitizeInputValue($currentUrl);
     $normalizedCurrentUrl = Piwik_Tracker_Action::excludeQueryParametersFromUrl($currentUrl, $idSite);
     $normalizedCurrentUrl = Piwik_Common::unsanitizeInputValue($normalizedCurrentUrl);
     // load the appropriate row of the page urls report using the label filter
     Piwik_Actions_ArchivingHelper::reloadConfig();
     $path = Piwik_Actions_ArchivingHelper::getActionExplodedNames($normalizedCurrentUrl, Piwik_Tracker_Action::TYPE_ACTION_URL);
     $path = array_map('urlencode', $path);
     $label = implode('>', $path);
     $request = new Piwik_API_Request('method=Actions.getPageUrls' . '&idSite=' . urlencode($idSite) . '&date=' . urlencode($date) . '&period=' . urlencode($period) . '&label=' . urlencode($label) . '&format=original');
     $dataTable = $request->process();
     $data = array();
     if ($dataTable->getRowsCount() > 0) {
         $row = $dataTable->getFirstRow();
         $translations = Piwik_API_API::getDefaultMetricTranslations();
         $showMetrics = array('nb_hits', 'nb_visits', 'nb_uniq_visitors', 'bounce_rate', 'exit_rate', 'avg_time_on_page');
         foreach ($showMetrics as $metric) {
             $value = $row->getColumn($metric);
             if ($value === false) {
                 // skip unique visitors for period != day
                 continue;
             }
             if ($metric == 'avg_time_on_page') {
                 $value = Piwik::getPrettyTimeFromSeconds($value);
             }
             $data[] = array('name' => $translations[$metric], 'value' => $value);
         }
     }
     // generate page url string
     foreach ($path as &$part) {
         $part = preg_replace(';^/;', '', urldecode($part));
     }
     $page = '/' . implode('/', $path);
     $page = preg_replace(';/index$;', '/', $page);
     if ($page == '/') {
         $page = '/index';
     }
     // render template
     $view = Piwik_View::factory('sidebar');
     $view->data = $data;
     $view->location = $page;
     $view->normalizedUrl = $normalizedCurrentUrl;
     $view->label = $label;
     $view->idSite = $idSite;
     $view->period = $period;
     $view->date = $date;
     echo $view->render();
 }
 function test_excludeQueryParameters_siteAndGlobalExcluded()
 {
     // testing also that query parameters are case insensitive
     $excludedQueryParameters = 'P2';
     $excludedGlobalParameters = 'blabla, P4';
     $expectedUrls = array('http:////wrongurl', 'http://*****:*****@hostname:80/path#anchor', 'http://a.com/index?p1=v1', 'http://a.com/index?p1=v1', 'http://a.com/index?p1=v1&p3=v3', 'http://a.com/index?p1=v1&p3=v3', 'http://a.com/index?p1=v1&p3=v3', 'http://a.com/index?p1&p3=v3', 'http://a.com/index?p1=v1&p3=v3');
     $this->setUpRootAccess();
     $idsite = Piwik_SitesManager_API::getInstance()->addSite("site1", array('http://example.org'), $ecommerce = 0, $excludedIps = '', $excludedQueryParameters);
     Piwik_SitesManager_API::getInstance()->setGlobalExcludedQueryParameters($excludedGlobalParameters);
     $urls = $this->getTestUrls();
     $filteredUrls = array();
     foreach ($urls as $url) {
         $filteredUrls[] = Piwik_Tracker_Action::excludeQueryParametersFromUrl($url, $idsite);
     }
     $this->assertEqual($expectedUrls, $filteredUrls);
 }
Пример #4
0
 /**
  * Get following pages of a url.
  * This is done on the logs - not the archives!
  * 
  * Note: if you use this method via the regular API, the number of results will be limited.
  * Make sure, you set filter_limit=-1 in the request.
  */
 public function getFollowingPages($url, $idSite, $period, $date, $segment = false)
 {
     $this->authenticate($idSite);
     $url = Piwik_Tracker_Action::excludeQueryParametersFromUrl($url, $idSite);
     // we don't unsanitize $url here. it will be done in the Transitions plugin.
     $resultDataTable = new Piwik_DataTable();
     try {
         $limitBeforeGrouping = Piwik_Config::getInstance()->General['overlay_following_pages_limit'];
         $transitionsReport = Piwik_Transitions_API::getInstance()->getTransitionsForAction($url, $type = 'url', $idSite, $period, $date, $segment, $limitBeforeGrouping, $part = 'followingActions', $returnNormalizedUrls = true);
     } catch (Exception $e) {
         return $resultDataTable;
     }
     $reports = array('followingPages', 'outlinks', 'downloads');
     foreach ($reports as $reportName) {
         if (!isset($transitionsReport[$reportName])) {
             continue;
         }
         foreach ($transitionsReport[$reportName]->getRows() as $row) {
             // don't touch the row at all for performance reasons
             $resultDataTable->addRow($row);
         }
     }
     return $resultDataTable;
 }
Пример #5
0
 function detectGoalId($idSite)
 {
     if (!Piwik_Common::isGoalPluginEnabled()) {
         return false;
     }
     $goals = $this->getGoalDefinitions($idSite);
     if (!isset($goals[$this->idGoal])) {
         return false;
     }
     $goal = $goals[$this->idGoal];
     $url = Piwik_Common::getRequestVar('url', '', 'string', $this->request);
     $goal['url'] = Piwik_Tracker_Action::excludeQueryParametersFromUrl($url, $idSite);
     $goal['revenue'] = $this->getRevenue(Piwik_Common::getRequestVar('revenue', $goal['revenue'], 'float', $this->request));
     $this->convertedGoals[] = $goal;
     return true;
 }
Пример #6
0
 /**
  * Will search in the DataTable for a Label matching the searched string
  * and return only the matching row, or an empty datatable
  */
 protected function getFilterPageDatatableSearch($callBackParameters, $search, $actionType, $table = false, $searchTree = false)
 {
     if ($searchTree === false) {
         // build the query parts that are searched inside the tree
         if ($actionType == Piwik_Tracker_Action::TYPE_ACTION_NAME) {
             $searchedString = Piwik_Common::unsanitizeInputValue($search);
         } else {
             $idSite = $callBackParameters[1];
             try {
                 $searchedString = Piwik_Tracker_Action::excludeQueryParametersFromUrl($search, $idSite);
             } catch (Exception $e) {
                 $searchedString = $search;
             }
         }
         $searchTree = Piwik_Actions::getActionExplodedNames($searchedString, $actionType);
     }
     if ($table === false) {
         // fetch the data table
         $table = call_user_func_array(array('Piwik_Archive', 'getDataTableFromArchive'), $callBackParameters);
         if ($table instanceof Piwik_DataTable_Array) {
             // search an array of tables, e.g. when using date=last30
             // note that if the root is an array, we filter all children
             // if an array occurs inside the nested table, we only look for the first match (see below)
             $newTableArray = new Piwik_DataTable_Array();
             $newTableArray->metadata = $table->metadata;
             $newTableArray->setKeyName($table->getKeyName());
             foreach ($table->getArray() as $label => $subTable) {
                 $subTable = $this->doFilterPageDatatableSearch($callBackParameters, $subTable, $searchTree);
                 $newTableArray->addTable($subTable, $label);
             }
             return $newTableArray;
         }
     }
     return $this->doFilterPageDatatableSearch($callBackParameters, $table, $searchTree);
 }
Пример #7
0
	/**
	 * Will search in the DataTable for a Label matching the searched string
	 * and return only the matching row, or an empty datatable
	 */
	protected function getFilterPageDatatableSearch( $callBackParameters, $search, $actionType, $table = false, $searchTree = false, $searchCurrentLevel = 0 )
	{
		if($table === false)
		{
			$table = call_user_func_array(array('Piwik_Archive', 'getDataTableFromArchive'), $callBackParameters);
		}
		if($searchTree === false)
		{
    		if($actionType == Piwik_Tracker_Action::TYPE_ACTION_NAME)
    		{
    			$searchedString = Piwik_Common::unsanitizeInputValue($search);
    		}
    		else
    		{
    			$searchedString = Piwik_Tracker_Action::excludeQueryParametersFromUrl($search, $idSite = $callBackParameters[1]);
    		}
			$searchTree = Piwik_Actions::getActionExplodedNames($searchedString, $actionType);
		}
		if(!($table instanceof Piwik_DataTable))
		{
			throw new Exception("For this API function, date=lastN or date=previousM is not supported");
		}
		$rows = $table->getRows();
		$labelSearch = $searchTree[$searchCurrentLevel];
		$isEndSearch = ((count($searchTree)-1) == $searchCurrentLevel);
		foreach($rows as $key => $row)
		{
			$found = false;
			// Found a match at this level
			$label = $row->getColumn('label');
			if($label === $labelSearch)
			{
				// Is this the end of the search tree? then we found the requested row
				if($isEndSearch)
				{
//					var_dump($label); var_dump($labelSearch); exit;
					$table = new Piwik_DataTable();
					$table->addRow($row);
					return $table;
				}
				
				// If we still need to search deeper, call search 
				$idSubTable = $row->getIdSubDataTable();
				// Update the idSubtable in the callback parameter list, to fetch this subtable from the archive
				$callBackParameters[6] = $idSubTable;
				$subTable = call_user_func_array(array('Piwik_Archive', 'getDataTableFromArchive'), $callBackParameters);
				$found = $this->getFilterPageDatatableSearch($callBackParameters, $search, $actionType, $subTable, $searchTree, $searchCurrentLevel+1);
				if($found)
				{
					return $found;
				}
			}
			if(!$found)
			{
				$table->deleteRow($key);
			}
		}
		// Case the DataTable was searched but nothing was found, @see getFilterPageDatatableSearch()
		if($searchCurrentLevel == 0)
		{
			return new Piwik_DataTable;
		}
		return false;
	}