Ejemplo n.º 1
0
 function archivePeriod($notification)
 {
     $archiveProcessing = $notification->getNotificationObject();
     $metricsToSum = array('nb_conversions', 'revenue');
     $goalIdsToSum = Piwik_Tracker_GoalManager::getGoalIds($archiveProcessing->idsite);
     $fieldsToSum = array();
     foreach ($metricsToSum as $metricName) {
         foreach ($goalIdsToSum as $goalId) {
             $fieldsToSum[] = self::getRecordName($metricName, $goalId);
             $fieldsToSum[] = self::getRecordName($metricName, $goalId, 0);
             $fieldsToSum[] = self::getRecordName($metricName, $goalId, 1);
         }
         $fieldsToSum[] = self::getRecordName($metricName);
     }
     $records = $archiveProcessing->archiveNumericValuesSum($fieldsToSum);
     // also recording conversion_rate for each goal
     foreach ($goalIdsToSum as $goalId) {
         $nb_conversions = $records[self::getRecordName('nb_conversions', $goalId)]->value;
         $conversion_rate = $this->getConversionRate($nb_conversions, $archiveProcessing);
         $archiveProcessing->insertNumericRecord(self::getRecordName('conversion_rate', $goalId), $conversion_rate);
     }
     // global conversion rate
     $nb_conversions = $records[self::getRecordName('nb_conversions')]->value;
     $conversion_rate = $this->getConversionRate($nb_conversions, $archiveProcessing);
     $archiveProcessing->insertNumericRecord(self::getRecordName('conversion_rate'), $conversion_rate);
 }
Ejemplo n.º 2
0
 /**
  * Hooks on Period archiving.
  * Sums up Goal conversions stats, and processes overall conversion rate
  *
  * @param Piwik_Event_Notification $notification
  * @return void
  */
 function archivePeriod($notification)
 {
     /**
      * @var Piwik_ArchiveProcessing 
      */
     $archiveProcessing = $notification->getNotificationObject();
     if (!$archiveProcessing->shouldProcessReportsForPlugin($this->getPluginName())) {
         return;
     }
     /*
      * Archive Ecommerce Items
      */
     if ($this->shouldArchiveEcommerceItems($archiveProcessing)) {
         $dataTableToSum = $this->dimensions;
         foreach ($this->dimensions as $recordName) {
             $dataTableToSum[] = self::getItemRecordNameAbandonedCart($recordName);
         }
         $archiveProcessing->archiveDataTable($dataTableToSum);
     }
     /*
      *  Archive General Goal metrics
      */
     $goalIdsToSum = Piwik_Tracker_GoalManager::getGoalIds($archiveProcessing->idsite);
     //Ecommerce
     $goalIdsToSum[] = Piwik_Tracker_GoalManager::IDGOAL_ORDER;
     $goalIdsToSum[] = Piwik_Tracker_GoalManager::IDGOAL_CART;
     //bug here if idgoal=1
     // Overall goal metrics
     $goalIdsToSum[] = false;
     $fieldsToSum = array();
     foreach ($goalIdsToSum as $goalId) {
         $metricsToSum = Piwik_Goals::getGoalColumns($goalId);
         unset($metricsToSum[array_search('conversion_rate', $metricsToSum)]);
         foreach ($metricsToSum as $metricName) {
             $fieldsToSum[] = self::getRecordName($metricName, $goalId);
         }
     }
     $records = $archiveProcessing->archiveNumericValuesSum($fieldsToSum);
     // also recording conversion_rate for each goal
     foreach ($goalIdsToSum as $goalId) {
         $nb_conversions = $records[self::getRecordName('nb_visits_converted', $goalId)];
         $conversion_rate = $this->getConversionRate($nb_conversions, $archiveProcessing);
         $archiveProcessing->insertNumericRecord(self::getRecordName('conversion_rate', $goalId), $conversion_rate);
         // sum up the visits to conversion data table & the days to conversion data table
         $archiveProcessing->archiveDataTable(array(self::getRecordName(self::VISITS_UNTIL_RECORD_NAME, $goalId), self::getRecordName(self::DAYS_UNTIL_CONV_RECORD_NAME, $goalId)));
     }
     // sum up goal overview reports
     $archiveProcessing->archiveDataTable(array(self::getRecordName(self::VISITS_UNTIL_RECORD_NAME), self::getRecordName(self::DAYS_UNTIL_CONV_RECORD_NAME)));
 }