Google 分析 SEO - PHP API

Google Analytics SEO - PHP API

我有一个 PHP 文件,它为我提供了 google 分析数据,例如综合浏览量、首页或有机数据等简单内容。

现在我需要从 SEO 部分获取东西。

例如:TOP 50 搜索关键字(含展示次数和点击次数)

我在API如何获取这些值方面找不到任何帮助。

这是我的 api 调用的示例:

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

您需要更新 Dimensions and Metrics of your query. The traffic dimensions and metrics 应该会有帮助。

下面是一个简化的查询,它获取各种来源和关键字组合的展示次数和点击次数:

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

您的代码必须具有从 $param 字段中的值到实际维度和指标名称的某些映射。我还鼓励您尝试使用 query explorer 来获取可能的查询字段。

Google 分析中显示的搜索引擎优化数据实际上来自 Google Search Console(网站站长工具),可从 Google Search Console API 获得。 https://developers.google.com/webmaster-tools/?hl=en