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);
2
Answers
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:
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.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.
https://developers.google.com/webmaster-tools/?hl=en