简体   繁体   English

如何使用google-api-php-client获取搜索查询

[英]how to get search queries using google-api-php-client

I have read the instructions from the Hello Analytics API: PHP quickstart for service accounts and all works ok, but I need some other behavior of the function getResults 我已经阅读了Hello Analytics API的说明:服务帐户的PHP快速入门,并且一切正常,但是我需要函数getResults其他一些行为

In the exampe it returns the number of sessions in the specified period 在示例中,它返回指定时间段内的会话数

function getResults(&$analytics, $profileId) {
  // Calls the Core Reporting API and queries for the number of sessions
  // for the last seven days.
   return $analytics->data_ga->get(
       'ga:' . $profileId,
       '7daysAgo',
       'today',
       'ga:sessions');
}

Is it possible to modify this function to return the search keywords instead of sessions? 是否可以修改此功能以返回搜索关键字而不是会话?

You cannot get keywords instead of sessions - keywords is a dimension, sessions is a metric, and at least one metric is required. 您无法获得关键字而不是会话-关键字是一个维度,会话是一个指标,并且至少需要一个指标。 So while you cannot get keywords instead of sessions you can get both keywords and sessions, and the sessions metric will be broken down by keyword. 因此,虽然您无法获取关键字而不是会话,但您可以同时获取关键字和会话,并且会话指标将按关键字细分。

For that you need to pass in an options array with the dimension: 为此,您需要传递一个具有以下维度的options数组:

$optParams = array(
    'dimensions' => 'ga:keyword',
);
return $analytics->data_ga->get(
       'ga:' . $profileId,
       '7daysAgo',
       'today',
       'ga:sessions',
       $optParams

);

ga:keyword is the organic keyword; ga:keyword是随机关键字; keep in mind that the value is not set for ssl secured searched (now the default), so for 90+ % of orgnaic sessions the value will be "not set". 请记住,没有为ssl安全搜索设置该值(现在是默认值),因此对于90%以上的orgnaic会话,该值将为“未设置”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过“google-api-php-client”库检索谷歌搜索分析 - Retrieving Google Search Analytics by "google-api-php-client" library 使用google-api-php-client的DoubleClick Search API中出现空批处理错误 - Empty batch encountered error in DoubleClick Search API using google-api-php-client 使用google / google-api-php-client以php发布到GooglePlus - Posting to GooglePlus in php using google/google-api-php-client 如何使用google-api-php-client向Google Analytics API进行查询 - How to make query to Google Analytics API using google-api-php-client 使用google-api-php-client不再进行文件更新 - Files updates no longer works using the google-api-php-client google-api-php-client-获取文件内容 - google-api-php-client - Get File Contents 如何使用纤薄的3 Rest API授权google-api-php-client? - How to authorize google-api-php-client with a slim 3 Rest API? 在google-api-php-client中使用importTable()导入FusionTable - import a fusiontable using importTable() in google-api-php-client 使用google-api-php-client无法创建正确的signedurl - using google-api-php-client not able to create proper signedurl 使用google-api-php-client下载文件 - Downloading files using google-api-php-client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM