简体   繁体   中英

Google Analytics SEO - PHP API

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);

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

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(
    'ga:XXXX',
    'today',
    '7daysAgo',
    $metrics,
    $optParams);

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 technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM