skip to Main Content

I have a PHP file which give’s me google analytics data, such as pageviews, Top Pages, or Organic Data simple stuff.

Now I neet to get Stuff from the SEO Part.

For example: TOP 50 Search Keywords (with Impression and Clicks)

I can’t find any help in the API how to get these values.

this is a example of my api call:

$params = array(
    'dimensions' => array('date', 'pagePath', 'pageTitle'),
    'metrics' => array('sessions', 'pageviews'),
    'sort' => '-ga:sessions',
    'filters' => null,
    'startdate' => $startdate,
    'enddate' => $enddate,
    'startindex' => null,
    'limit' => 25,
    'mapping' => array('pagepath' => 'pagepath', 'pagetitle' => 'pagetitle', 'sessions' => 'visits', 'pageviews' => 'pageviews'),

$results = $this->service->data_ga->get($this->profile, $params['startdate'], $params['enddate'], $metrics, $optParams);



  1. You would need to update the Dimensions and Metrics of your query. The traffic dimensions and metrics should be of help.

    Below is a simplified query which gets the number of impressions and clicks for various sources and keyword combinations:

    $optParams = array(
      'dimensions' => 'ga:source,ga:keyword',
      'sort' => '-ga:impressions,ga:source',
      'filters' => 'ga:medium==organic',
      'max-results' => '25');
    $metrics = 'ga:impressions,ga:adClicks';
    $results = $this->service->data_ga->get(

    Your code must have some mapping that it does from the values in $param field to the actual dimensions and metric names. I would also encourage you to play around with the query explorer to get a field of what queries are possible.

    Login or Signup to reply.
  2. The search engine optimization data shown in Google Analytics actually comes from Google Search Console (Webmaster Tools) and is available from the Google Search Console API.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top