/**
  * @param Piwik_ArchiveProcessing_Day $archiveProcessing
  */
 protected function archiveDayRecordInDatabase($archiveProcessing)
 {
     $tableCountry = $archiveProcessing->getDataTableFromArray($this->interestByCountry);
     $archiveProcessing->insertBlobRecord('UserCountry_country', $tableCountry->getSerialized());
     $archiveProcessing->insertNumericRecord('UserCountry_distinctCountries', $tableCountry->getRowsCount());
     destroy($tableCountry);
     $tableContinent = $archiveProcessing->getDataTableFromArray($this->interestByContinent);
     $archiveProcessing->insertBlobRecord('UserCountry_continent', $tableContinent->getSerialized());
     destroy($tableContinent);
 }
Exemple #2
0
 /**
  * @param Piwik_ArchiveProcessing_Day $archiveProcessing
  */
 protected function archiveDayRecordInDatabase($archiveProcessing)
 {
     $maximumRows = Piwik_Config::getInstance()->General['datatable_archiving_maximum_rows_standard'];
     $tableCountry = Piwik_ArchiveProcessing_Day::getDataTableFromArray($this->interestTables['location_country']);
     $archiveProcessing->insertBlobRecord(self::VISITS_BY_COUNTRY_RECORD_NAME, $tableCountry->getSerialized());
     $archiveProcessing->insertNumericRecord(self::DISTINCT_COUNTRIES_METRIC, $tableCountry->getRowsCount());
     destroy($tableCountry);
     $tableRegion = Piwik_ArchiveProcessing_Day::getDataTableFromArray($this->interestTables['location_region']);
     $serialized = $tableRegion->getSerialized($maximumRows, $maximumRows, Piwik_Archive::INDEX_NB_VISITS);
     $archiveProcessing->insertBlobRecord(self::VISITS_BY_REGION_RECORD_NAME, $serialized);
     destroy($tableRegion);
     $tableCity = Piwik_ArchiveProcessing_Day::getDataTableFromArray($this->interestTables['location_city']);
     $this->setLatitudeLongitude($tableCity);
     $serialized = $tableCity->getSerialized($maximumRows, $maximumRows, Piwik_Archive::INDEX_NB_VISITS);
     $archiveProcessing->insertBlobRecord(self::VISITS_BY_CITY_RECORD_NAME, $serialized);
     destroy($tableCity);
 }
Exemple #3
0
 /**
  * @param Piwik_ArchiveProcessing_Day $archiveProcessing
  */
 function archiveGeneralGoalMetrics($archiveProcessing)
 {
     // extra aggregate selects for the visits to conversion report
     $visitToConvExtraCols = Piwik_ArchiveProcessing_Day::buildReduceByRangeSelect('visitor_count_visits', self::$visitCountRanges, 'log_conversion', 'vcv');
     // extra aggregate selects for the days to conversion report
     $daysToConvExtraCols = Piwik_ArchiveProcessing_Day::buildReduceByRangeSelect('visitor_days_since_first', self::$daysToConvRanges, 'log_conversion', 'vdsf');
     $query = $archiveProcessing->queryConversionsByDimension(array(), '', array_merge($visitToConvExtraCols, $daysToConvExtraCols));
     if ($query === false) {
         return;
     }
     $goals = array();
     $visitsToConvReport = array();
     $daysToConvReport = array();
     // Get a standard empty goal row
     $overall = $archiveProcessing->getNewGoalRow($idGoal = 1);
     while ($row = $query->fetch()) {
         $idgoal = $row['idgoal'];
         if (!isset($goals[$idgoal])) {
             $goals[$idgoal] = $archiveProcessing->getNewGoalRow($idgoal);
             $visitsToConvReport[$idgoal] = new Piwik_DataTable();
             $daysToConvReport[$idgoal] = new Piwik_DataTable();
         }
         $archiveProcessing->updateGoalStats($row, $goals[$idgoal]);
         // We don't want to sum Abandoned cart metrics in the overall revenue/conversions/converted visits
         // since it is a "negative conversion"
         if ($idgoal != Piwik_Tracker_GoalManager::IDGOAL_CART) {
             $archiveProcessing->updateGoalStats($row, $overall);
         }
         // map the goal + visit number of a visitor with the # of conversions that happened on that visit
         $table = $archiveProcessing->getSimpleDataTableFromRow($row, Piwik_Archive::INDEX_NB_CONVERSIONS, 'vcv');
         $visitsToConvReport[$idgoal]->addDataTable($table);
         // map the goal + day number of a visit with the # of conversion that happened on that day
         $table = $archiveProcessing->getSimpleDataTableFromRow($row, Piwik_Archive::INDEX_NB_CONVERSIONS, 'vdsf');
         $daysToConvReport[$idgoal]->addDataTable($table);
     }
     // these data tables hold reports for every goal of a site
     $visitsToConvOverview = new Piwik_DataTable();
     $daysToConvOverview = new Piwik_DataTable();
     // Stats by goal, for all visitors
     foreach ($goals as $idgoal => $values) {
         foreach ($values as $metricId => $value) {
             $metricName = Piwik_Archive::$mappingFromIdToNameGoal[$metricId];
             $recordName = self::getRecordName($metricName, $idgoal);
             $archiveProcessing->insertNumericRecord($recordName, $value);
         }
         $conversion_rate = $this->getConversionRate($values[Piwik_Archive::INDEX_GOAL_NB_VISITS_CONVERTED], $archiveProcessing);
         $recordName = self::getRecordName('conversion_rate', $idgoal);
         $archiveProcessing->insertNumericRecord($recordName, $conversion_rate);
         // if the goal is not a special goal (like ecommerce) add it to the overview report
         if ($idgoal !== Piwik_Tracker_GoalManager::IDGOAL_CART && $idgoal !== Piwik_Tracker_GoalManager::IDGOAL_ORDER) {
             $visitsToConvOverview->addDataTable($visitsToConvReport[$idgoal]);
             $daysToConvOverview->addDataTable($daysToConvReport[$idgoal]);
         }
         // visit count until conversion stats
         $archiveProcessing->insertBlobRecord(self::getRecordName(self::VISITS_UNTIL_RECORD_NAME, $idgoal), $visitsToConvReport[$idgoal]->getSerialized());
         // day count until conversion stats
         $archiveProcessing->insertBlobRecord(self::getRecordName(self::DAYS_UNTIL_CONV_RECORD_NAME, $idgoal), $daysToConvReport[$idgoal]->getSerialized());
     }
     // archive overview reports
     $archiveProcessing->insertBlobRecord(self::getRecordName(self::VISITS_UNTIL_RECORD_NAME), $visitsToConvOverview->getSerialized());
     $archiveProcessing->insertBlobRecord(self::getRecordName(self::DAYS_UNTIL_CONV_RECORD_NAME), $daysToConvOverview->getSerialized());
     // Stats for all goals
     $totalAllGoals = array(self::getRecordName('conversion_rate') => $this->getConversionRate($archiveProcessing->getNumberOfVisitsConverted(), $archiveProcessing), self::getRecordName('nb_conversions') => $overall[Piwik_Archive::INDEX_GOAL_NB_CONVERSIONS], self::getRecordName('nb_visits_converted') => $archiveProcessing->getNumberOfVisitsConverted(), self::getRecordName('revenue') => $overall[Piwik_Archive::INDEX_GOAL_REVENUE]);
     foreach ($totalAllGoals as $recordName => $value) {
         $archiveProcessing->insertNumericRecord($recordName, $value);
     }
 }
Exemple #4
0
	/**
	 * @param Piwik_ArchiveProcessing_Day $archiveProcessing
	 */
	function archiveGeneralGoalMetrics($archiveProcessing)
	{
		$query = $archiveProcessing->queryConversionsByDimension('');
		
		if($query === false) { return; }
		
		$goals = array();
		// Get a standard empty goal row
		$overall = $archiveProcessing->getNewGoalRow( $idGoal = 1);
		while($row = $query->fetch() )
		{
			if(!isset($goals[$row['idgoal']])) $goals[$row['idgoal']] = $archiveProcessing->getNewGoalRow($row['idgoal']);
			$archiveProcessing->updateGoalStats($row, $goals[$row['idgoal']]);
			
			// We don't want to sum Abandoned cart metrics in the overall revenue/conversions/converted visits 
			// since it is a "negative conversion"
			if($row['idgoal'] != Piwik_Tracker_GoalManager::IDGOAL_CART)
			{
				$archiveProcessing->updateGoalStats($row, $overall);
			}
		}
		// Stats by goal, for all visitors
		foreach($goals as $idgoal => $values)
		{
			foreach($values as $metricId => $value)
			{
				$metricName = Piwik_Archive::$mappingFromIdToNameGoal[$metricId];
				$recordName = self::getRecordName($metricName, $idgoal);
				$archiveProcessing->insertNumericRecord($recordName, $value);
			}
			$conversion_rate = $this->getConversionRate($values[Piwik_Archive::INDEX_GOAL_NB_VISITS_CONVERTED], $archiveProcessing);
			$recordName = self::getRecordName('conversion_rate', $idgoal);
			$archiveProcessing->insertNumericRecord($recordName, $conversion_rate);
		}
		
		
		// Stats for all goals
		$totalAllGoals = array(
			self::getRecordName('conversion_rate')	=> $this->getConversionRate($archiveProcessing->getNumberOfVisitsConverted(), $archiveProcessing),
			self::getRecordName('nb_conversions')	=> $overall[Piwik_Archive::INDEX_GOAL_NB_CONVERSIONS],
			self::getRecordName('nb_visits_converted')	=> $archiveProcessing->getNumberOfVisitsConverted(),
			self::getRecordName('revenue') 			=> $overall[Piwik_Archive::INDEX_GOAL_REVENUE],
		);
		foreach($totalAllGoals as $recordName => $value)
		{
			$archiveProcessing->insertNumericRecord($recordName, $value);
		}
	}