'VisitorInterest', 'description' => 'Several stats related to the visitor interest', 'author' => 'Piwik', 'homepage' => 'http://piwik.org/', 'version' => '0.1', ); return $info; } function getListHooksRegistered() { $hooks = array( 'ArchiveProcessing_Day.compute' => 'archiveDay', 'ArchiveProcessing_Period.compute' => 'archiveMonth', ); return $hooks; } function archiveMonth( $notification ) { $archiveProcessing = $notification->getNotificationObject(); $dataTableToSum = array( 'VisitorInterest_timeGap', 'VisitorInterest_pageGap', ); $archiveProcessing->archiveDataTable($dataTableToSum); } public function archiveDay( $notification ) { // used in protected methods $this->archiveProcessing = $notification->getNotificationObject(); $recordName = 'VisitorInterest_timeGap'; $tableTimegap = $this->getTableTimeGap(); $record = new Piwik_ArchiveProcessing_Record_BlobArray($recordName, $tableTimegap->getSerialized()); $recordName = 'VisitorInterest_pageGap'; $tablePagegap = $this->getTablePageGap(); $record = new Piwik_ArchiveProcessing_Record_BlobArray($recordName, $tablePagegap->getSerialized()); // echo $tableTimegap; // echo $tablePagegap; } protected function getTablePageGap() { $select = array(); foreach($this->pageGap as $gap) { if(count($gap) == 2) { $minGap = $gap[0]; $maxGap = $gap[1]; $gapName = "'$minGap-$maxGap'"; $select[] = "sum(case when visit_total_actions between $minGap and $maxGap then 1 else 0 end) as $gapName "; } else { $minGap = $gap[0]; $plusEncoded = urlencode('+'); $gapName = "'".$minGap.$plusEncoded."'"; $select[] = "sum(case when visit_total_actions > $minGap then 1 else 0 end) as $gapName "; } } $toSelect = implode(" , ", $select); return $this->archiveProcessing->getSimpleDataTableFromSelect($toSelect, Piwik_Archive::INDEX_NB_VISITS); } protected function getTableTimeGap() { $select = array(); foreach($this->timeGap as $gap) { if(count($gap) == 2) { $minGap = $gap[0] * 60; $maxGap = $gap[1] * 60; $gapName = "'".$minGap."-".$maxGap."'"; $select[] = "sum(case when visit_total_time between $minGap and $maxGap then 1 else 0 end) as $gapName "; } else { $minGap = $gap[0] * 60; $gapName = "'$minGap'"; $select[] = "sum(case when visit_total_time > $minGap then 1 else 0 end) as $gapName "; } } $toSelect = implode(" , ", $select); $table = $this->archiveProcessing->getSimpleDataTableFromSelect($toSelect, Piwik_Archive::INDEX_NB_VISITS); // echo $table; return $table; } public function headerVisitsFrequency($notification) { $out =& $notification->getNotificationObject(); $out = '
'; } public function footerVisitsFrequency($notification) { $out =& $notification->getNotificationObject(); $out = '
'; $out .= Piwik_FrontController::getInstance()->fetchDispatch('VisitorInterest','index'); $out .= '
'; } } Piwik_AddWidget( 'VisitorInterest', 'getNumberOfVisitsPerVisitDuration', 'Visits lengths'); Piwik_AddWidget( 'VisitorInterest', 'getNumberOfVisitsPerPage', 'Pages per visit'); Piwik_RenameMenuEntry('Visitors', 'Frequency', 'Visitors', 'Frequency & Loyalty' ); Piwik_AddAction('template_headerVisitsFrequency', array('Piwik_VisitorInterest','headerVisitsFrequency')); Piwik_AddAction('template_footerVisitsFrequency', array('Piwik_VisitorInterest','footerVisitsFrequency'));