private function getTopContent($options) { if (!isset($options['limit']) or !is_numeric($options['limit'])) { throw new sfException('A limit of type integer is required'); } $arrGaReportsSettings = sfConfig::get('app_a_gareports', false); if (!isset($arrGaReportsSettings['username'])) { die('Google Analytics username is missing'); } if (!isset($arrGaReportsSettings['password'])) { die('Google Analytics password is missing '); } if (!isset($arrGaReportsSettings['profile'])) { die('Google Analytics profile is missing '); } if (!isset($arrGaReportsSettings['key'])) { die('Google Analytics API Key is missing '); } try { // create an instance of the GoogleAnalytics class using your own Google {email} and {password} // todo pull all config data from app.yml $ga = new GoogleAnalytics($arrGaReportsSettings['username'], $arrGaReportsSettings['password']); // set the Google Analytics profile you want to access - format is 'ga:123456'; $ga->setProfile($arrGaReportsSettings['profile']); $ga->setKey($arrGaReportsSettings['key']); // set the date range we want for the report - format is YYYY-MM-DD // todo: have this adjustable from the slot edit view $dateFormat = 'Y-m-d'; $startDate = date($dateFormat, strtotime('-1 month')); $endDate = date($dateFormat, time()); $ga->setDateRange($startDate, $endDate); // get the report for date and country filtered by Australia, showing pageviews and visits $report = $ga->getReport(array('dimensions' => urlencode('ga:pagetitle,ga:pagePath'), 'metrics' => urlencode('ga:pageviews'), 'sort' => '-ga:pageviews', 'max-results' => $options['limit']), $returnJson = TRUE); } catch (Exception $e) { $report = 'Error: ' . $e->getMessage(); } return $report; }
Date Created: -- --, 2010 Last Updated: -- --, 2010 Copyright: 2010 @ Dog and Rooster ----------------------------------------*/ // include the Google Analytics PHP class include "ga/gapi.class.php"; try { // create an instance of the GoogleAnalytics class using your own Google {email} and {password} $ga = new GoogleAnalytics('*****@*****.**', 'password'); // set the Google Analytics profile you want to access - format is 'ga:123456'; $ga->setProfile('ga:1234567'); // set the date range we want for the report - format is YYYY-MM-DD $month = date("m"); $ga->setDateRange('2010-' . $month . '-01', '2010-' . $month . '-31'); // get the report for date, showing pageviews and visits $report = $ga->getReport(array('dimensions' => 'ga:date', 'metrics' => 'ga:visits,ga:pageviews')); // view all Arrays //print "<pre>"; //print_r($report); //print "</pre>"; // set to JFlot Chart panel if (count($report)) { foreach ($report as $key => $reports) { if (list($inner_key, $inner_val) = each($reports)) { $visit = $inner_val; } $page_views = each($reports); $views = implode(array_values($page_views), ","); $pageviews = $views[0]; $count = $count + 1; $flot_datas_visits[] = '[' . $count . ',' . $visit . ']';
<?php include '../application/libraries/googleanalytics.php'; $ga = new GoogleAnalytics(); $ga->setProfile('ga:60386809'); $yesterday_date = date('Y-m-d', strtotime('1 day ago')); $y_date = str_replace('-', '', $yesterday_date); $ga->setDateRange($yesterday_date, $yesterday_date); $data['report'] = $ga->getReport(array('dimensions' => urlencode('ga:date'), 'metrics' => urlencode('ga:pageviews,ga:uniquePageviews,ga:visitors,ga:newVisits'))); //print_r($data['report']); $noofvisitor = $data['report'][$y_date]['ga:visitors']; $noofuniquevisitor = $data['report'][$y_date]['ga:newVisits']; $pageviews = $data['report'][$y_date]['ga:pageviews']; $uniquepageviews = $data['report'][$y_date]['ga:uniquePageviews']; //$to=array('*****@*****.**','*****@*****.**','*****@*****.**','*****@*****.**'); $to = "*****@*****.**"; $subject = "Google Analytics Daily Report"; $message = "Dear sir,\n Yesterday report of site visitors is described below\n"; $message .= "No of Visitors : " . $noofvisitor . '\\n\\n'; $message .= "No of Unique Visitors : " . $noofuniquevisitor . '\\n\\n'; $message .= "No of Page Views : " . $pageviews . '\\n'; $message .= "No of Unique Page Views : " . $uniquepageviews . '\\n'; $headers = "From: webmaster@example.com" . "\r\n" . "CC: somebodyelse@example.com"; //mail('*****@*****.**',$subject,$message,$headers);
<?php include 'google/analytics/GoogleAnalytics.php'; $user = $_POST["user"]; $pass = $_POST["pass"]; $end = $_POST["end"]; $ga = new GoogleAnalytics(); if ($ga->login($user, $pass)) { $accounts = $ga->getAccounts(); $profiles = $ga->getSiteProfiles($accounts['railk']); $report = $ga->getReport($profiles['portfolio'], '20070207', $end); $saved = $ga->saveReport($report, '../report.xml'); echo $saved; } ?>
function cronjob() { $this->load->library('googleanalytics'); $this->load->library('email'); $ga = new GoogleAnalytics(); $ga->setProfile('ga:60386809'); $yesterday_date = date('Y-m-d', strtotime('1 day ago')); $y_date = str_replace('-', '', $yesterday_date); $ga->setDateRange($yesterday_date, $yesterday_date); $data['report'] = $ga->getReport(array('dimensions' => urlencode('ga:date'), 'metrics' => urlencode('ga:pageviews,ga:uniquePageviews,ga:visitors,ga:newVisits'))); $noofvisitor = $data['report'][$y_date]['ga:visitors']; $noofuniquevisitor = $data['report'][$y_date]['ga:newVisits']; $pageviews = $data['report'][$y_date]['ga:pageviews']; $uniquepageviews = $data['report'][$y_date]['ga:uniquePageviews']; $to = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**'); $subject = "Google Analytics Daily Report"; $message = "Dear sir,<br /> Yesterday report of site visitors is described below<br /><br />"; $message .= "Total No of Visitors : " . $noofvisitor . '<br /><br />'; $message .= "Total No of Unique Visitors : " . $noofuniquevisitor . '<br /><br />'; $message .= "Total No of Page Views : " . $pageviews . '<br /><br />'; $message .= "Total No of Unique Page Views : " . $uniquepageviews . '<br />'; $body = $message; $config['protocol'] = $this->config->item('mail_protocol'); $config['smtp_host'] = $this->config->item('smtp_server'); $config['smtp_user'] = $this->config->item('smtp_user_name'); $config['smtp_pass'] = $this->config->item('smtp_pass'); $this->email->initialize($config); $this->email->from('*****@*****.**', 'MeetUniversities.com'); $this->email->to($to); $this->email->subject($subject); $this->email->message($body); $this->email->send(); }