google analytics region fetch from google anaytics using google-api-php-client library -


i want fetch region google analytics getting country city want region

this code have used google-api-php-client library data google analytics can't query retrive region ga. have tried ga:region in dimension butget nothing that.any appreciated

  <?php  session_start();  require_once 'google-api-php-client-master/autoload.php';  set_include_path("../".path_separator.get_include_path()); require_once 'google-api-php-client-master/src/google/client.php';       require_once 'google-api-php-client-master/src/google/service/analytics.php';     $client_id = 'xxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com'; $client_secret = 'xxxxxxxxxxxxxxxxxxx'; $redirect_uri = 'http://php.vervesys.com/test/index.php';  $client = new google_client(); $client->setapplicationname('test project'); $client->setclientid($client_id); $client->setclientsecret($client_secret); $client->setredirecturi($redirect_uri);    $client->addscope("https://www.googleapis.com/auth/analytics.readonly");    if (isset($_request['logout'])) {  unset($_session['access_token']);  }     if (isset($_get['code'])) { $client->authenticate($_get['code']); $_session['access_token'] = $client->getaccesstoken(); $redirect = 'http://' . $_server['http_host'] . $_server['php_self']; header('location: ' . filter_var($redirect, filter_sanitize_url)); }      if (isset($_session['access_token']) && $_session['access_token']) {   $client->setaccesstoken($_session['access_token']);   } else {   $authurl = $client->createauthurl();   }  ?>     <?php if (isset($authurl)): ?>     <a class='login' href='<?php echo $authurl; ?>'>connect me!</a>  <?php  else: ?>  <a class='logout' href='?logout'>logout</a>    <?php endif ?>  <hr/>  <?php     if ($client->getaccesstoken()) {       $analytics = new google_service_analytics($client);    $_session['access_token'] = $client->getaccesstoken();        $properties = $analytics->management_webproperties->listmanagementwebproperties("~all");   $items = $properties->getitems();    if(is_array($items)){    foreach($items $key => $property)   {     $profile = $analytics->management_profiles->listmanagementprofiles($property->accountid, $property->id)->getitems();    echo '<a href="index.php?id=' . $profile[0]->id . '&domain=' . urlencode($property->websiteurl) . '">' . $property->websiteurl . '</a>      <br/>';      }      }     }      if(isset($_get['id'])){    $results_top_pages = $analytics->data_ga->get(     'ga:'.$_get['id'],     date('y-m-d',strtotime('-14 days')),     date('y-m-d',strtotime('-1 day')),     'ga:pageviews',     array(          'dimensions' => 'ga:pagepath,ga:city,ga:country,ga:operatingsystem,ga:operatingsystemversion,ga:browser,ga:browserversion,         'sort' => '-ga:pageviews',         'max-results' => 50     ));   if(is_array($results_top_pages->getrows())){     echo '<ol>';     foreach($results_top_pages->getrows() $top_page){         echo '<li>';         echo $top_page[0];         echo ' - '.$top_page[1].' ';  echo ' - '.$top_page[2].' ';  echo ' - '.$top_page[3].' ';  echo ' - '.$top_page[4].' ';  echo ' - '.$top_page[5].' ';  echo ' - '.$top_page[6].' ';           echo '</li>';      }      echo '</ol>';   } } ?> 

from code output this:

/mm/bi_analysis/ - ahmedabad - india - linux - i686 - chrome - 42.0.2311.135

/mm/bi_analysis/ - ahmedabad - india - windows - 8.1 - chrome - 45.0.2454.101

/mm/bi_analysis/ - ahmedabad - india - macintosh - intel 10.10 - chrome - 46.0.2490.42

/mm/bi_analysis/ - ahmedabad - india - windows - 7 - chrome - 45.0.2454.101

i want region in this

did try requesting ga:region ?

ga:region
ui name: region
region of users, derived ip addresses or geographical ids. in u.s., region state, such new york.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -