$end_date) $errormsg = "invalid"; return $errormsg; } //returns sessionToken for multiple calls to API function googleLogin($email,$passwd){ $clientlogin_url = "https://www.google.com/accounts/ClientLogin"; $clientlogin_post = array( "accountType" => "GOOGLE", "Email" => $email, "Passwd" => $passwd, "service" => "analytics", "source" => "my-analytics" ); $curl = curl_init($clientlogin_url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $clientlogin_post); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($curl); preg_match("/Auth=([a-z0-9_\-]+)/i", $response, $matches); $sessionToken = $matches[1]; if (strlen($sessionToken) == 0){ $sessionToken = "Authentication Failed."; } return $sessionToken; } //returns session token for multiple calls to API function get_session_token($onetimetoken) { $output = call_api($onetimetoken, "https://www.google.com/accounts/AuthSubSessionToken"); if (preg_match("/Token=(.*)/", $output, $matches)) { $sessionToken = $matches[1]; } else { echo "Error authenticating with Google."; exit; } return $sessionToken; } //gets the data function call_api($sessionToken,$url){ $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); if (isset($_SESSION['authSub'])){ $curlheader[0] = sprintf("Authorization: AuthSub token=\"%s\"/n", $sessionToken); } else { $curlheader[0] = "Authorization: GoogleLogin auth=" . $sessionToken; } curl_setopt($curl, CURLOPT_HTTPHEADER, $curlheader); $response = curl_exec($curl); curl_close($curl); return $response; } //returns accounts list as array function parse_account_list($xml){ $doc = new DOMDocument(); if(stripos($xml,"<") !== FALSE) { $doc->loadXML($xml); $entries = $doc->getElementsByTagName('entry'); $i = 0; $profiles= array(); foreach($entries as $entry) { $profiles[$i] = array(); $properties = $entry->getElementsByTagName('property'); foreach($properties as $property) { if (strcmp($property->getAttribute('name'), 'ga:accountId') == 0) $profiles[$i]["accountId"] = $property->getAttribute('value'); if (strcmp($property->getAttribute('name'), 'ga:profileName') == 0) $profiles[$i]["title"] = $property->getAttribute('value'); if (strcmp($property->getAttribute('name'), 'dxp:tableId') == 0) $profiles[$i]["tableId"] = $property->getAttribute('value'); } $i++; } return $profiles; } else { $sessionToken = "Authentication Failed."; } } //returns data as array function parse_data($xml){ $doc = new DOMDocument(); $doc->loadXML($xml); $entries = $doc->getElementsByTagName('entry'); $i = 0; $results = array(); foreach($entries as $entry) { $dimensions = $entry->getElementsByTagName('dimension'); foreach($dimensions as $dimension) { $results[$i][ltrim($dimension->getAttribute("name"),"ga:")] = $dimension->getAttribute('value'); } $metrics = $entry->getElementsByTagName('metric'); foreach($metrics as $metric) { $results[$i][ltrim($metric->getAttribute('name'),"ga:")] = $metric->getAttribute('value'); } $i++; } return $results; } ?>
Authentication Failed. Please check your log in credentials and try again.
Date range of " . $full_start_date . " to " . $full_end_date . " is invalid. Please reselect the dates.
"; exit; } else { $visits_graph_type = $_POST['graphtype']; echo "| Referrer | Visits |
|---|---|
| "; }else{ echo " | |
| "; } echo $referrer["source"] . " | " . number_format($referrer["visits"]) . ""; $table_row++; } echo " |