/** * 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); } }
/** * Derive the action ID from the request action name and type. */ private function deriveIdAction($actionName, $actionType) { $actionsPlugin = new Piwik_Actions(); switch ($actionType) { case 'url': $originalActionName = $actionName; $actionName = Piwik_Common::unsanitizeInputValue($actionName); $id = $actionsPlugin->getIdActionFromSegment($actionName, 'idaction_url'); if ($id < 0) { // an example where this is needed is urls containing < or > $actionName = $originalActionName; $id = $actionsPlugin->getIdActionFromSegment($actionName, 'idaction_url'); } return $id; case 'title': $id = $actionsPlugin->getIdActionFromSegment($actionName, 'idaction_name'); if ($id < 0) { $unkown = Piwik_Actions_ArchivingHelper::getUnknownActionName(Piwik_Tracker_Action::TYPE_ACTION_NAME); if (trim($actionName) == trim($unkown)) { $id = $actionsPlugin->getIdActionFromSegment('', 'idaction_name'); } } return $id; default: throw new Exception('Unknown action type'); } }