Example #1
0
 public function google_login()
 {
     require_once APPPATH . 'libraries/google-api-php-client/src/Google/autoload.php';
     //$this->load->model('users_model');
     //$redirect = isEmpty($this->input->get('referuri'))?'':$this->input->get('referuri');
     $data = array();
     //echo 'test';
     // Start a session to persist credentials.
     //session_start();
     //echo BASEPATH;
     //var_dump(is_file(APPPATH.'libraries/google-api-php-client/client_secrets.json'));
     //exit('test');
     // Create the client object and set the authorization configuration
     // from the client_secrets.json you downloaded from the Developers Console.
     $client = new Google_Client();
     $client->setAuthConfigFile(APPPATH . 'libraries/google-api-php-client/client_secrets.json');
     //$client->setRedirectUri(base_url('login/google_callback'));
     $client->setScopes('email');
     $client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
     // If the user has already authorized this app then get an access token
     // else redirect to ask the user to authorize access to Google Analytics.
     if ($this->session->userdata('access_token') != '') {
         // Set the access token on the client.
         $client->setAccessToken($this->session->userdata('access_token'));
         // Create an authorized analytics service object.
         $analytics = new Google_Service_Analytics($client);
         // Get the first view (profile) id for the authorized user.
         $profile = getFirstProfileId($analytics);
         // Get the results from the Core Reporting API and print the results.
         printResults(getResults($analytics, $profile));
     } else {
         $redirect_uri = base_url('login/google_callback');
         //header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
         redirect(filter_var($redirect_uri, FILTER_SANITIZE_URL));
     }
 }
Example #2
0
    #the profile name and total sessions.
    if (count($results->getRows()) > 0) {
        #Get the profile name.
        $profileName = $results->getProfileInfo()->getProfileName();
        #Get the entry for the first entry in the first row.
        $rows = $results->getRows();
        $sessions = $rows[0][0];
        #Print the results.
        print "First view (profile) found: {$profileName}\n";
        print "Total sessions: {$sessions}\n";
    } else {
        print "No results found.\n";
    }
}
$analytics = getService();
$profile = getFirstProfileId($analytics);
$results = getResults($analytics, $profile);
displayResults($results);
#printResults($results);
/*
#Set up Analytics object
$analytics = getService();

#Set up query & date range
$ga_profileID = 'ga:UA-67891724-1'; #set actual ID
$ga_dimensions = 'ga:landingPagePath, ga:pageTitle';
$ga_metrics = 'ga:pageviews';
$ga_sort_by = '-ga:pageviews';
$ga_max_results = '10';
$params = array('dimensions' => $ga_dimensions, 'sort' => $ga_sort_by, 'max_results' => $ga_max_results);
            function printResults(&$results)
            {
                // Parses the response from the Core Reporting API and prints
                // the profile name and total sessions.
                if (count($results->getRows()) > 0) {
                    // Get the profile name.
                    $profileName = $results->getProfileInfo()->getProfileName();
                    // Get the entry for the first entry in the first row.
                    $rows = $results->getRows();
                    $sessions = $rows[0][0];
                } else {
                    print "No results found.\n";
                }
            }
            $analytics = getService();
            $profile = getFirstProfileId($analytics, $accountId);
            //$results = getResults($analytics, $profile);
            //
            //echo '<pre>';
            //print_r($profile);
            $site_name = $analytics->management_webproperties->listManagementWebproperties($accountId)->items[0]->name;
            $site_url = $analytics->management_webproperties->listManagementWebproperties($accountId)->items[0]->websiteUrl;
            //echo '</pre>';
            ?>
<style>
@font-face {
	font-family: Gunar;
	src: url(fonts/The Northern Block - Gunar Light.otf);	
}
@media screen, print {
	#hiilite_seo_report * {