}
        if (!isset($google['password']) || !$google['password']) {
            $ga_errors[2] = "Please enter your analytics password";
        }
        if (!isset($google['profile']) || !$google['profile']) {
            $ga_errors[3] = "Please enter your analytics Profile ID";
        } elseif (!is_numeric($google['profile'])) {
            $ga_errors[3] = "Profile ID must be numeric";
        }
        if (!isset($google['tracking']) || !$google['tracking']) {
            $ga_errors[4] = "Please enter your analytics Tracking ID";
        }
        if (!count($ga_errors)) {
            require_once "../includes/gapi.class.php";
            $ga = new gapi($google['username'], $google['password']);
            $check = $ga->authenticateUser($google['username'], $google['password']);
            if ($check) {
                try {
                    $res = $ga->requestReportData($google['profile'], array('country'), array('pageviews', 'visits'), array("-visits"), null, date("Y-m-d"), date("Y-m-d"));
                    $settings->addSetting("analytics", json_encode($google));
                    $ga_success = true;
                } catch (Exception $e) {
                    $ga_errors[3] = "Invalid Profile ID";
                }
            } else {
                $ga_errors[1] = "Can't authenticate";
            }
        }
    }
} else {
    $google = $settings->getSetting("analytics", true);
Ejemplo n.º 2
0
 /**
  * Authenticate Google Account with Google
  *
  * @param String $email
  * @param String $password
  */
 protected function authenticateUser($email, $password)
 {
     try {
         return parent::authenticateUser($email, $password);
     } catch (Exception $e) {
         throw new dmGapiException('GAPI: Failed to authenticate with email ' . $email . '. Please configure email and password in the admin configuration panel');
     }
 }
Ejemplo n.º 3
0
Archivo: graph.php Proyecto: kvox/TVSS
     $from = date("Y-m-d", strtotime("29 days ago"));
 } else {
     $from = $_GET['from'];
 }
 if (!isset($_GET['to']) || !$_GET['to']) {
     $to = date("Y-m-d");
 } else {
     $to = $_GET['to'];
 }
 if (!isset($_GET['report_type'])) {
     $report_type = "country";
 } else {
     $report_type = $_GET['report_type'];
 }
 $ga = new gapi($account->username, $account->password);
 $check = $ga->authenticateUser($account->username, $account->password);
 if ($check) {
     if ($report_type == "country") {
         $res = $ga->requestReportData($account->profile, array('country'), array('pageviews', 'visits'), array("-visits"), null, $from, $to);
         $data = array();
         if (count($res)) {
             foreach ($res as $key => $val) {
                 $data[] = array("label" => $val->dimensions['country'], "data" => $val->metrics['visits']);
                 if (count($data) >= 12) {
                     break;
                 }
             }
         }
     } elseif ($report_type == "daily") {
         $res = $ga->requestReportData($account->profile, array('date'), array('pageviews', 'visits'), array("date"), null, $from, $to);
         $data_pv = array();