/** * @return \ManiaLib\Application\GoogleAnalytics */ protected static function getTracker() { if (!self::$trackingAccount) { $config = Config::getInstance(); self::$trackingAccount = $config->account; } $t = new GoogleAnalytics(self::$trackingAccount, self::$cookieNameSuffix); $t->loadCookie(); return $t; }
public function actionGoogle() { $oAnalytics = new GoogleAnalytics('*****@*****.**', 't8KmiMfc5ehBtA'); $oAnalytics->setProfileByName('www.propagacnepredmety.sk'); $oAnalytics->setDateRange(date('Y-m-d', time() - 60 * 60 * 24 * 40), date('Y-m-d', time() - 60 * 60 * 24 * 1)); $this->template->visitors = $oAnalytics->getVisitors(); $this->template->keywords = $oAnalytics->getData(array('dimensions' => 'ga:keyword', 'metrics' => 'ga:visits', 'sort' => 'ga:keyword')); print_r($this->template->keywords); // echo '<pre>'; // // print out visitors for given period // print_r($oAnalytics->getVisitors()); // // // print out pageviews for given period // print_r($oAnalytics->getPageviews()); // // // use dimensions and metrics for output // // see: http://code.google.com/intl/nl/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html // print_r($oAnalytics->getData(array( 'dimensions' => 'ga:keyword', // 'metrics' => 'ga:visits', // 'sort' => 'ga:keyword'))); }
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; }
<?php /*---------------------------------------- Name: PHP JFlot (jQuery Flot Charts) Developed by: Dog and Rooster Team 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; }
<?php /** * @var modX $modx */ /* load the analytics lexicon into the JS lexicon */ //load class $corePath = $modx->getOption('analytics.core_path', null, $modx->getOption('core_path') . 'components/analytics/'); require_once $corePath . 'model/analytics/analytics.class.php'; $ga = new GoogleAnalytics($modx); $modx->controller->addLexiconTopic('analytics:default'); $modx->regClientStartupHTMLBlock('<script type="text/javascript">var GA = {connector_url:"' . $ga->config['connectorUrl'] . '",assets_url:"' . $ga->config['assetsUrl'] . '"};</script>'); $sitename = $modx->getOption('analytics_sitename'); //Get the amount of days $days = $modx->getOption('analytics_days', null, 7); //Get the settings $settings = array('sessionToken' => trim($modx->getOption('analytics_sessionToken')), 'profileId' => trim($modx->getOption('analytics_profileId')), 'accountId' => trim($modx->getOption('analytics_accountId')), 'webPropertyId' => trim($modx->getOption('analytics_webPropertyId')), 'start_date' => date('Y-m-d', strtotime('-' . ($days - 1) . ' day', time())), 'end_date' => date('Y-m-d')); //load lexicon files $modx->getService('lexicon', 'modLexicon'); $modx->lexicon->load('analytics:default'); //lexicon to js $lexicon = $modx->lexicon->fetch($prefix = 'analytics.', $removePrefix = true); $lexiconJs = $modx->toJSON($lexicon); $modx->smarty->assign('_langs', $lexicon); if ($_REQUEST['token']) { $sessiontoken = $ga->getSessionToken($_REQUEST['token']); $Setting = $modx->getObject('modSystemSetting', 'analytics_sessionToken'); $Setting->set('value', trim($sessiontoken)); $Setting->save(); $settings['sessionToken'] = trim($sessiontoken); unset($_REQUEST['token']);
<?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; } ?>
*/ public static function init() { add_action('customize_register', array('PressGang\\GoogleAnalytics', 'customizer')); add_action('wp_footer', array('PressGang\\GoogleAnalytics', 'script')); } /** * Add to customizer * * @param $wp_customize */ public static function customizer($wp_customize) { $wp_customize->add_section('google', array('title' => __("Google", THEMENAME))); $wp_customize->add_setting('google-analytics-id', array('default' => '', 'sanitize_callback' => 'sanitize_text_field')); $wp_customize->add_control(new \WP_Customize_Control($wp_customize, 'google-analytics-id', array('label' => __("Google Analytics ID", THEMENAME), 'section' => 'google'))); } /** * script * * @return void */ public static function script() { if ($google_analytics_id = urlencode(get_theme_mod('google-analytics-id'))) { \Timber::render('google-analytics.twig', array('google_analytics_id' => $google_analytics_id)); } } } GoogleAnalytics::init();
<?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);
public function searchrefer_data() { $api = new GoogleAnalytics(); if ($api->login(Config::get("analytics/email"), Config::get("analytics/password"))) { $api->load_accounts(); $this->pages_data = $api->data(Config::get("analytics/id"), 'ga:keyword', 'ga:visits'); array_shift($this->pages_data); foreach ($this->pages_data as $source => $count) { $subs[] = array("link" => "http://google.com?q=" . $source, "keyword" => $source, "count" => $count["ga:visits"]); } return $subs; } else { return false; } }
function GoogleTest() { parent::WebPage('Google Analytics Test'); //Enter Your Google Anlytics Code GoogleAnalytics::Track('UA-XXXXXX-X'); }
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(); }
require_once $corePath . 'model/analytics/analytics.class.php'; require_once $corePath . 'model/google-api-php-client/src/Google/Client.php'; require_once $corePath . 'model/google-api-php-client/src/Google/Service/Analytics.php'; $client_id = '697135090133-s51enie43b74v6qnpgfo8i23qv11gll6.apps.googleusercontent.com'; $client_secret = 'T5svt7HvpF3eYScE-HeCvdxh'; $developer_key = 'AIzaSyBQyj6t45IvALZA91L9aNwxX7Z1tHMu0Xs'; // new instance of client class $client = new Google_Client(); $client->setApplicationName('Google Analytics Dashboard Widget'); $client->setClientId($client_id); $client->setClientSecret($client_secret); $client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob'); $client->setDeveloperKey($developer_key); $client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly')); $client->setAccessType('offline'); $ga = new GoogleAnalytics($modx); $modx->controller->addLexiconTopic('analytics:default'); $modx->regClientStartupHTMLBlock('<script type="text/javascript">var GA = {connector_url:"' . $ga->config['connectorUrl'] . '",assets_url:"' . $ga->config['assetsUrl'] . '"};</script>'); $sitename = $modx->getOption('analytics_sitename'); //Get the amount of days $days = $modx->getOption('analytics_days', null, 7); //Get the settings $settings = array('refreshToken' => trim($modx->getOption('analytics_refreshToken')), 'profileId' => trim($modx->getOption('analytics_profileId')), 'accountId' => trim($modx->getOption('analytics_accountId')), 'webPropertyId' => trim($modx->getOption('analytics_webPropertyId')), 'start_date' => date('Y-m-d', strtotime('-' . ($days - 1) . ' day', time())), 'end_date' => date('Y-m-d')); //load lexicon files $modx->getService('lexicon', 'modLexicon'); $modx->lexicon->load('analytics:default'); //lexicon to js $lexicon = $modx->lexicon->fetch($prefix = 'analytics.', $removePrefix = true); $lexiconJs = $modx->toJSON($lexicon); $modx->smarty->assign('_langs', $lexicon); if (isset($_POST['auth_code']) && $_POST['auth_code'] != '') {