Ejemplo n.º 1
0
 public function getCompetitionDatatable()
 {
     $dataTable = new Piwik_DataTable();
     $row1 = new Piwik_DataTable_Row();
     $row1->setColumns(array('name' => 'piwik', 'license' => 'GPL'));
     $dataTable->addRow($row1);
     $dataTable->addRowFromSimpleArray(array('name' => 'google analytics', 'license' => 'commercial'));
     return $dataTable;
 }
Ejemplo n.º 2
0
 /**
  * Returns a custom data table.
  * This data table will be converted to all available formats 
  * when requested in the API request.
  * 
  * @return Piwik_DataTable
  */
 public function getCompetitionDatatable()
 {
     $dataTable = new Piwik_DataTable();
     $row1 = new Piwik_DataTable_Row();
     $row1->setColumns(array('name' => 'piwik', 'license' => 'GPL'));
     // Rows Metadata is useful to store non stats data for example (logos, urls, etc.)
     // When printed out, they are simply merged with columns
     $row1->setMetadata('logo', 'logo.png');
     $dataTable->addRow($row1);
     $dataTable->addRowFromSimpleArray(array('name' => 'google analytics', 'license' => 'commercial'));
     return $dataTable;
 }
Ejemplo n.º 3
0
 function archiveDay($notification)
 {
     /**
      * @var Piwik_ArchiveProcessing_Day 
      */
     $archiveProcessing = $notification->getNotificationObject();
     $funnelDefinitions = Piwik_Funnels_API::getInstance()->getFunnels($archiveProcessing->idsite);
     $funnelDefinitions = $this->initializeStepData($funnelDefinitions);
     list($funnelDefinitions, $total) = $this->storeRefAndNextUrls($funnelDefinitions, $archiveProcessing);
     // Add the calculations of dropout
     foreach ($funnelDefinitions as $funnelDefinition) {
         $last_index = count($funnelDefinition['steps']) - 1;
         $idFunnel = $funnelDefinition['idfunnel'];
         $idGoal = $funnelDefinition['idgoal'];
         // get the goal conversions grouped by the converting action
         $goal_query = $archiveProcessing->queryConversionsBySegment('idaction_url');
         $goalConversions = array();
         while ($row = $goal_query->fetch()) {
             if ($row['idgoal'] == $idGoal) {
                 $goalConversions[$row['idaction_url']] = $row['nb_conversions'];
             }
         }
         for ($i = 0; $i <= $last_index; $i++) {
             $current_step =& $funnelDefinition['steps'][$i];
             $idStep = $current_step['idstep'];
             // record number of actions for the step
             $recordName = Piwik_Funnels::getRecordName('nb_actions', $idFunnel, $idStep);
             $archiveProcessing->insertNumericRecord($recordName, $current_step['nb_actions']);
             # Remove the previous step urls from the idaction_url_ref array and add their actions to the
             # count of actions moving from the previous step to this one
             if ($i > 0) {
                 $previous_step = $funnelDefinition['steps'][$i - 1];
                 $nb_prev_step_actions = 0;
                 foreach ($previous_step['idaction_url'] as $key => $value) {
                     if (isset($current_step['idaction_url_ref'][$key])) {
                         $nb_prev_step_actions += $current_step['idaction_url_ref'][$key]['value'];
                         unset($current_step['idaction_url_ref'][$key]);
                     }
                 }
                 $recordName = Piwik_Funnels::getRecordName('nb_next_step_actions', $idFunnel, $previous_step['idstep']);
                 $archiveProcessing->insertNumericRecord($recordName, $nb_prev_step_actions);
                 // calculate a percent of people continuing from the previous step to this
                 $recordName = Piwik_Funnels::getRecordName('percent_next_step_actions', $idFunnel, $previous_step['idstep']);
                 $archiveProcessing->insertNumericRecord($recordName, $this->percent($nb_prev_step_actions, $previous_step['nb_actions']));
             }
             if ($i < $last_index) {
                 $next_step = $funnelDefinition['steps'][$i + 1];
                 # Remove this step's next actions that are actions for the next funnel step
                 foreach ($current_step['idaction_url_next'] as $key => $value) {
                     if (isset($next_step['idaction_url'][$key])) {
                         unset($current_step['idaction_url_next'][$key]);
                     }
                 }
                 # Archive the next urls that aren't funnel steps
                 $idActionNext = new Piwik_DataTable();
                 $exitCount = 0;
                 foreach ($current_step['idaction_url_next'] as $id => $data) {
                     $idActionNext->addRowFromSimpleArray($data);
                     $exitCount += $data['value'];
                 }
                 $recordName = Piwik_Funnels::getRecordName('idaction_url_next', $idFunnel, $idStep);
                 $archiveProcessing->insertBlobRecord($recordName, $idActionNext->getSerialized());
                 destroy($idActionNext);
                 # and a sum of exit actions
                 $recordName = Piwik_Funnels::getRecordName('nb_exit', $idFunnel, $idStep);
                 $archiveProcessing->insertNumericRecord($recordName, $exitCount);
             }
             // Archive the referring urls that aren't funnel steps
             $idActionRef = new Piwik_DataTable();
             $entryCount = 0;
             foreach ($current_step['idaction_url_ref'] as $id => $data) {
                 $idActionRef->addRowFromSimpleArray($data);
                 $entryCount += $data['value'];
             }
             $recordName = Piwik_Funnels::getRecordName('idaction_url_ref', $idFunnel, $idStep);
             $archiveProcessing->insertBlobRecord($recordName, $idActionRef->getSerialized());
             destroy($idActionRef);
             # and a sum of entry actions
             $recordName = Piwik_Funnels::getRecordName('nb_entry', $idFunnel, $idStep);
             $archiveProcessing->insertNumericRecord($recordName, $entryCount);
         }
         // For the last step, the comparison is the goal itself
         $last_step = $funnelDefinition['steps'][$last_index];
         $idStep = $last_step['idstep'];
         $recordName = Piwik_Funnels::getRecordName('nb_next_step_actions', $idFunnel, $idStep);
         $nb_goal_actions = 0;
         foreach ($goalConversions as $key => $value) {
             if (isset($last_step['idaction_url_next'][$key])) {
                 $nb_goal_actions += $last_step['idaction_url_next'][$key]['value'];
                 unset($last_step['idaction_url_next'][$key]);
             }
         }
         $archiveProcessing->insertNumericRecord($recordName, $nb_goal_actions);
         $recordName = Piwik_Funnels::getRecordName('percent_next_step_actions', $idFunnel, $idStep);
         $archiveProcessing->insertNumericRecord($recordName, $this->percent($nb_goal_actions, $last_step['nb_actions']));
         # Archive the next urls that aren't funnel steps
         $idActionNext = new Piwik_DataTable();
         $exitCount = 0;
         foreach ($last_step['idaction_url_next'] as $id => $data) {
             $idActionNext->addRowFromSimpleArray($data);
             $exitCount += $data['value'];
         }
         $recordName = Piwik_Funnels::getRecordName('idaction_url_next', $idFunnel, $idStep);
         $archiveProcessing->insertBlobRecord($recordName, $idActionNext->getSerialized());
         destroy($idActionNext);
         # and a sum of exit actions
         $recordName = Piwik_Funnels::getRecordName('nb_exit', $idFunnel, $idStep);
         $archiveProcessing->insertNumericRecord($recordName, $exitCount);
         // Archive the total funnel actions
         $recordName = Piwik_Funnels::getRecordName('nb_actions', $idFunnel, false);
         $archiveProcessing->insertNumericRecord($recordName, $total);
         // What percent of people who visited the first funnel step converted at the end of the funnel?
         $recordName = Piwik_Funnels::getRecordName('conversion_rate', $idFunnel, false);
         $archiveProcessing->insertNumericRecord($recordName, $this->percent($nb_goal_actions, $funnelDefinition['steps'][0]['nb_actions']));
     }
 }
Ejemplo n.º 4
0
 /**
  * Returns a datatable representation of a set of table statuses.
  * 
  * @param array $statuses The table statuses to summarize.
  * @return Piwik_DataTable
  */
 private function getTablesSummary($statuses)
 {
     $dataTable = new Piwik_DataTable();
     foreach ($statuses as $status) {
         $dataTable->addRowFromSimpleArray(array('label' => $status['Name'], 'data_size' => $status['Data_length'], 'index_size' => $status['Index_length'], 'row_count' => $status['Rows']));
     }
     return $dataTable;
 }