CodeIgniter Library to connect Google Analytics API.
- Copy
config/ga_api.php
file to theconfig
folder of your application. - Copy
GoogleAnalytics.php
file andgoogle-api-php-client
folder to thelibrary
folder of your application.
- Load the config file to your controller
$this->config->load('ga_api');
- Load the library & config values
$ga_params = array(
'applicationName' => $this->config->item('ga_api_applicationName'),
'clientID' => $this->config->item('ga_api_clientId'),
'clientSecret' => $this->config->item('ga_api_clientSecret'),
'redirectUri' => $this->config->item('ga_api_redirectUri'),
'developerKey' => $this->config->item('ga_api_developerKey'),
'profileID' => $this->config->item('ga_api_profileId')
);
$this->load->library('GoogleAnalytics', $ga_params);
$this->googleanalytics->get_total('users')
returns total number of users visited to your page.$this->googleanalytics->get_total({metric})
{metric} = users, newUsers, percentNewSessions, sessionsPerUser.
$this->googleanalytics->get_dimensions('browser','users')
returns array of number of users visited to your page with browsers.$this->googleanalytics->get_dimensions({dimension},{matric})
{metric} = users, newUsers, percentNewSessions, sessionsPerUser. {dimension} = browser, browserVersion, operatingSystem, operatingSystemVersion, mobileDeviceBranding, mobileDeviceModel, mobileInputSelector, mobileDeviceInfo, mobileDeviceMarketingName, deviceCategory.
Dimensions & Metrics Reference
$this->googleanalytics->logout();
Destroys the session.