/** * get the extra data for an overview, can be overridden * * @return array */ protected function getExtra(AnalyticsOverview $overview) { $extra = array(); // add segment if ($overview->getSegment()) { $extra['segment'] = $overview->getSegment()->getQuery(); } return $extra; }
/** * get extra data * * @return array */ protected function getExtra(AnalyticsOverview $overview) { $timespan = $overview->getTimespan() - $overview->getStartOffset(); $extra = parent::getExtra($overview); if ($timespan <= 1) { $extra['dimensions'] = 'ga:date,ga:hour'; } else { if ($timespan <= 7) { $extra['dimensions'] = 'ga:date,ga:hour'; } else { if ($timespan <= 31) { $extra['dimensions'] = 'ga:week,ga:day,ga:date'; } else { $extra['dimensions'] = 'ga:isoYearIsoWeek'; } } } return $extra; }
/** * Add overviews for a config and optionally a segment * * @param AnalyticsConfig $config * @param AnalyticsSegment $segment */ public function addOverviews(&$config, &$segment = null) { $em = $this->getEntityManager(); $today = new AnalyticsOverview(); $today->setTitle('dashboard.ga.tab.today'); $today->setTimespan(0); $today->setStartOffset(0); $today->setConfig($config); $today->setSegment($segment); $em->persist($today); $yesterday = new AnalyticsOverview(); $yesterday->setTitle('dashboard.ga.tab.yesterday'); $yesterday->setTimespan(1); $yesterday->setStartOffset(1); $yesterday->setConfig($config); $yesterday->setSegment($segment); $em->persist($yesterday); $week = new AnalyticsOverview(); $week->setTitle('dashboard.ga.tab.last_7_days'); $week->setTimespan(7); $week->setStartOffset(1); $week->setConfig($config); $week->setSegment($segment); $em->persist($week); $month = new AnalyticsOverview(); $month->setTitle('dashboard.ga.tab.last_30_days'); $month->setTimespan(30); $month->setStartOffset(1); $month->setConfig($config); $month->setSegment($segment); $em->persist($month); $year = new AnalyticsOverview(); $year->setTitle('dashboard.ga.tab.last_12_months'); $year->setTimespan(365); $year->setStartOffset(1); $year->setConfig($config); $year->setSegment($segment); $em->persist($year); $yearToDate = new AnalyticsOverview(); $yearToDate->setTitle('dashboard.ga.tab.year_to_date'); $yearToDate->setTimespan(365); $yearToDate->setStartOffset(1); $yearToDate->setConfig($config); $yearToDate->setSegment($segment); $yearToDate->setUseYear(true); $em->persist($yearToDate); $em->flush(); }
/** * Fetch a specific goals * * @param AnalyticsOverview $overview The overview * @param $goalCollection */ private function parseGoals(&$overview, $goalCollection) { $timespan = $overview->getTimespan() - $overview->getStartOffset(); if ($overview->getGoals()) { // delete existing entries foreach ($overview->getGoals() as $goal) { $this->em->remove($goal); } $this->em->flush(); } foreach ($goalCollection as $goalEntry) { // create a new goal $goal = new AnalyticsGoal(); $goal->setOverview($overview); $goal->setName($goalEntry['name']); $goal->setPosition($goalEntry['position']); $chartData = array(); $totalVisits = 0; $goalVisits = 0; $i = 0; // Fill the chartdata array foreach ($goalEntry['visits'] as $timestamp => $visits) { $totalVisits += $visits; if ($timespan <= 7 && $timespan > 1) { $goalVisits += $visits; if ($i % 5 == 0) { $chartData[] = array('timestamp' => $timestamp, 'conversions' => $goalVisits); $goalVisits = 0; } } else { $chartData[] = array('timestamp' => $timestamp, 'conversions' => $visits); } $i += 1; } // set the data $goal->setVisits($totalVisits); $goal->setChartData(json_encode($chartData)); $goals = $overview->getGoals(); $goals[] = $goal; $this->em->persist($goal); $this->output->writeln("\t\t" . 'Fetched goal ' . $goal->getPosition() . ': "' . $goal->getName() . '" @ ' . $totalVisits); } }
/** * Reset the data for the overview * * @param AnalyticsOverview $overview The overview */ private function reset(AnalyticsOverview $overview) { // reset overview $overview->setNewUsers(0); $overview->setReturningUsers(0); }