Exemplo n.º 1
0
 /**
  * General method to get transitions for an action
  * 
  * @param $actionName
  * @param $actionType "url"|"title"
  * @param $idSite
  * @param $period
  * @param $date
  * @param bool $segment
  * @param bool $limitBeforeGrouping
  * @param string $parts
  * @param bool $returnNormalizedUrls
  * @return array
  * @throws Exception
  */
 public function getTransitionsForAction($actionName, $actionType, $idSite, $period, $date, $segment = false, $limitBeforeGrouping = false, $parts = 'all', $returnNormalizedUrls = false)
 {
     Piwik::checkUserHasViewAccess($idSite);
     // get idaction of the requested action
     $idaction = $this->deriveIdAction($actionName, $actionType);
     if ($idaction < 0) {
         throw new Exception('NoDataForAction');
     }
     // prepare archive processing that can be used by the archiving code
     $archiveProcessing = new Piwik_ArchiveProcessing_Day();
     $archiveProcessing->setSite(new Piwik_Site($idSite));
     $archiveProcessing->setPeriod(Piwik_Period::advancedFactory($period, $date));
     $archiveProcessing->setSegment(new Piwik_Segment($segment, $idSite));
     $archiveProcessing->initForLiveUsage();
     // prepare the report
     $report = array('date' => Piwik_Period_Day::advancedFactory($period, $date)->getLocalizedShortString());
     // add data to the report
     $transitionsArchiving = new Piwik_Transitions();
     if ($returnNormalizedUrls) {
         $transitionsArchiving->returnNormalizedUrls();
     }
     $partsArray = explode(',', $parts);
     if ($parts == 'all' || in_array('internalReferrers', $partsArray)) {
         $this->addInternalReferrers($transitionsArchiving, $archiveProcessing, $report, $idaction, $actionType, $limitBeforeGrouping);
     }
     if ($parts == 'all' || in_array('followingActions', $partsArray)) {
         $includeLoops = $parts != 'all' && !in_array('internalReferrers', $partsArray);
         $this->addFollowingActions($transitionsArchiving, $archiveProcessing, $report, $idaction, $actionType, $limitBeforeGrouping, $includeLoops);
     }
     if ($parts == 'all' || in_array('externalReferrers', $partsArray)) {
         $this->addExternalReferrers($transitionsArchiving, $archiveProcessing, $report, $idaction, $actionType, $limitBeforeGrouping);
     }
     // derive the number of exits from the other metrics
     if ($parts == 'all') {
         $report['pageMetrics']['exits'] = $report['pageMetrics']['pageviews'] - $transitionsArchiving->getTotalTransitionsToFollowingActions() - $report['pageMetrics']['loops'];
     }
     // replace column names in the data tables
     $reportNames = array('previousPages' => true, 'previousSiteSearches' => false, 'followingPages' => true, 'followingSiteSearches' => false, 'outlinks' => true, 'downloads' => true);
     foreach ($reportNames as $reportName => $replaceLabel) {
         if (isset($report[$reportName])) {
             $columnNames = array(Piwik_Archive::INDEX_NB_ACTIONS => 'referrals');
             if ($replaceLabel) {
                 $columnNames[Piwik_Archive::INDEX_NB_ACTIONS] = 'referrals';
             }
             $report[$reportName]->filter('ReplaceColumnNames', array($columnNames));
         }
     }
     return $report;
 }
Exemplo n.º 2
0
 /**
  * Add transitions data to the report.
  * Fake ArchiveProcessing to do the queries live.
  */
 private function addLiveTransitionsDataToReport(&$report, $pageUrl, $idSite, $period, $date, $segment, $limitBeforeGrouping)
 {
     // get idaction of page url
     $actionsPlugin = new Piwik_Actions();
     $idaction = $actionsPlugin->getIdActionFromSegment($pageUrl, 'idaction');
     // prepare archive processing that can be reused by the archiving code
     $archiveProcessing = new Piwik_ArchiveProcessing_Day();
     $archiveProcessing->setSite(new Piwik_Site($idSite));
     $archiveProcessing->setPeriod(Piwik_Period::advancedFactory($period, $date));
     $archiveProcessing->setSegment(new Piwik_Segment($segment, $idSite));
     $archiveProcessing->initForLiveUsage();
     // launch the archiving code - but live
     $transitionsArchiving = new Piwik_Transitions();
     $data = $transitionsArchiving->queryInternalReferrers($idaction, $archiveProcessing, $limitBeforeGrouping);
     $report['previousPages'] =& $data['previousPages'];
     $report['pageMetrics']['loops'] = intval($data['loops']);
     $data = $transitionsArchiving->queryFollowingActions($idaction, $archiveProcessing, $limitBeforeGrouping);
     foreach ($data as $tableName => $table) {
         $report[$tableName] = $table;
     }
     $data = $transitionsArchiving->queryExternalReferrers($idaction, $archiveProcessing, $limitBeforeGrouping);
     $report['pageMetrics']['entries'] = 0;
     $report['referrers'] = array();
     foreach ($data->getRows() as $row) {
         $referrerId = $row->getColumn('label');
         $visits = $row->getColumn(Piwik_Archive::INDEX_NB_VISITS);
         if ($visits) {
             // load details (i.e. subtables)
             $details = array();
             if ($idSubTable = $row->getIdSubDataTable()) {
                 $subTable = Piwik_DataTable_Manager::getInstance()->getTable($idSubTable);
                 foreach ($subTable->getRows() as $subRow) {
                     $details[] = array('label' => $subRow->getColumn('label'), 'referrals' => $subRow->getColumn(Piwik_Archive::INDEX_NB_VISITS));
                 }
             }
             $report['referrers'][] = array('label' => $this->getReferrerLabel($referrerId), 'shortName' => Piwik_getRefererTypeFromShortName($referrerId), 'visits' => $visits, 'details' => $details);
             $report['pageMetrics']['entries'] += $visits;
         }
     }
     // if there's no data for referrers, Piwik_API_ResponseBuilder::handleMultiDimensionalArray
     // does not detect the multi dimensional array and the data is rendered differently, which
     // causes an exception.
     if (count($report['referrers']) == 0) {
         $report['referrers'][] = array('label' => $this->getReferrerLabel(Piwik_Common::REFERER_TYPE_DIRECT_ENTRY), 'shortName' => Piwik_getRefererTypeLabel(Piwik_Common::REFERER_TYPE_DIRECT_ENTRY), 'visits' => 0);
     }
 }