[英]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.