Esempio n. 1
0
 /**
  * Daily Goal archiving:  processes reports of Goal conversions by Keyword,
  * Goal conversions by Referer Websites, etc.
  *
  * @param Piwik_ArchiveProcessing $archiveProcessing
  * @return void
  */
 protected function archiveDayAggregateGoals($archiveProcessing)
 {
     $query = $archiveProcessing->queryConversionsByDimension(array("referer_type", "referer_name", "referer_keyword"));
     if ($query === false) {
         return;
     }
     while ($row = $query->fetch()) {
         if (empty($row['referer_type'])) {
             $row['referer_type'] = Piwik_Common::REFERER_TYPE_DIRECT_ENTRY;
         } else {
             switch ($row['referer_type']) {
                 case Piwik_Common::REFERER_TYPE_SEARCH_ENGINE:
                     if (empty($row['referer_keyword'])) {
                         $row['referer_keyword'] = self::LABEL_KEYWORD_NOT_DEFINED;
                     }
                     if (!isset($this->interestBySearchEngine[$row['referer_name']][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) {
                         $this->interestBySearchEngine[$row['referer_name']][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow($row['idgoal']);
                     }
                     if (!isset($this->interestByKeyword[$row['referer_keyword']][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) {
                         $this->interestByKeyword[$row['referer_keyword']][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow($row['idgoal']);
                     }
                     $archiveProcessing->updateGoalStats($row, $this->interestBySearchEngine[$row['referer_name']][Piwik_Archive::INDEX_GOALS][$row['idgoal']]);
                     $archiveProcessing->updateGoalStats($row, $this->interestByKeyword[$row['referer_keyword']][Piwik_Archive::INDEX_GOALS][$row['idgoal']]);
                     break;
                 case Piwik_Common::REFERER_TYPE_WEBSITE:
                     if (!isset($this->interestByWebsite[$row['referer_name']][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) {
                         $this->interestByWebsite[$row['referer_name']][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow($row['idgoal']);
                     }
                     $archiveProcessing->updateGoalStats($row, $this->interestByWebsite[$row['referer_name']][Piwik_Archive::INDEX_GOALS][$row['idgoal']]);
                     break;
                 case Piwik_Common::REFERER_TYPE_CAMPAIGN:
                     if (!empty($row['referer_keyword'])) {
                         if (!isset($this->interestByCampaignAndKeyword[$row['referer_name']][$row['referer_keyword']][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) {
                             $this->interestByCampaignAndKeyword[$row['referer_name']][$row['referer_keyword']][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow($row['idgoal']);
                         }
                         $archiveProcessing->updateGoalStats($row, $this->interestByCampaignAndKeyword[$row['referer_name']][$row['referer_keyword']][Piwik_Archive::INDEX_GOALS][$row['idgoal']]);
                     }
                     if (!isset($this->interestByCampaign[$row['referer_name']][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) {
                         $this->interestByCampaign[$row['referer_name']][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow($row['idgoal']);
                     }
                     $archiveProcessing->updateGoalStats($row, $this->interestByCampaign[$row['referer_name']][Piwik_Archive::INDEX_GOALS][$row['idgoal']]);
                     break;
                 case Piwik_Common::REFERER_TYPE_DIRECT_ENTRY:
                     // Direct entry, no sub dimension
                     break;
                 default:
                     // The referer type is user submitted for goal conversions, we ignore any malformed value
                     // Continue to the next while iteration
                     continue 2;
                     break;
             }
         }
         if (!isset($this->interestByType[$row['referer_type']][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) {
             $this->interestByType[$row['referer_type']][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow($row['idgoal']);
         }
         $archiveProcessing->updateGoalStats($row, $this->interestByType[$row['referer_type']][Piwik_Archive::INDEX_GOALS][$row['idgoal']]);
     }
     $archiveProcessing->enrichConversionsByLabelArray($this->interestByType);
     $archiveProcessing->enrichConversionsByLabelArray($this->interestBySearchEngine);
     $archiveProcessing->enrichConversionsByLabelArray($this->interestByKeyword);
     $archiveProcessing->enrichConversionsByLabelArray($this->interestByWebsite);
     $archiveProcessing->enrichConversionsByLabelArray($this->interestByCampaign);
     $archiveProcessing->enrichConversionsByLabelArrayHasTwoLevels($this->interestByCampaignAndKeyword);
 }
Esempio n. 2
0
 /**
  * @param Piwik_ArchiveProcessing $archiveProcessing
  * @return void
  */
 protected function archiveDayAggregate(Piwik_ArchiveProcessing $archiveProcessing)
 {
     for ($i = 1; $i <= Piwik_Tracker::MAX_CUSTOM_VARIABLES; $i++) {
         $keyField = "custom_var_k" . $i;
         $valueField = "custom_var_v" . $i;
         $dimensions = array($keyField, $valueField);
         $where = "{$keyField} != '' AND {$valueField} != ''";
         // Custom Vars names and values metrics for visits
         $query = $archiveProcessing->queryVisitsByDimension($dimensions, $where);
         while ($row = $query->fetch()) {
             if (!isset($this->interestByCustomVariables[$row[$keyField]])) {
                 $this->interestByCustomVariables[$row[$keyField]] = $archiveProcessing->getNewInterestRow();
             }
             if (!isset($this->interestByCustomVariablesAndValue[$row[$keyField]][$row[$valueField]])) {
                 $this->interestByCustomVariablesAndValue[$row[$keyField]][$row[$valueField]] = $archiveProcessing->getNewInterestRow();
             }
             $archiveProcessing->updateInterestStats($row, $this->interestByCustomVariables[$row[$keyField]]);
             $archiveProcessing->updateInterestStats($row, $this->interestByCustomVariablesAndValue[$row[$keyField]][$row[$valueField]]);
         }
         // Custom Vars names and values metrics for Goals
         $query = $archiveProcessing->queryConversionsByDimension($dimensions, $where);
         if ($query !== false) {
             while ($row = $query->fetch()) {
                 if (!isset($this->interestByCustomVariables[$row[$keyField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) {
                     $this->interestByCustomVariables[$row[$keyField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow();
                 }
                 if (!isset($this->interestByCustomVariablesAndValue[$row[$keyField]][$row[$valueField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']])) {
                     $this->interestByCustomVariablesAndValue[$row[$keyField]][$row[$valueField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']] = $archiveProcessing->getNewGoalRow();
                 }
                 $archiveProcessing->updateGoalStats($row, $this->interestByCustomVariables[$row[$keyField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']]);
                 $archiveProcessing->updateGoalStats($row, $this->interestByCustomVariablesAndValue[$row[$keyField]][$row[$valueField]][Piwik_Archive::INDEX_GOALS][$row['idgoal']]);
             }
         }
         $archiveProcessing->enrichConversionsByLabelArrayHasTwoLevels($this->interestByCustomVariablesAndValue);
     }
 }