谷歌分析PHP API(GAPI)-获取直接流量数据

谷歌分析PHP API(GAPI)-获取直接流量数据,php,google-analytics,google-analytics-api,Php,Google Analytics,Google Analytics Api,我是google analytics的新手,现在仍在寻找出路。我试图找到一种方法来检索仪表板上直接流量(流量源-->源-->直接)下的数据(登录页、访问次数、页面/访问次数、平均访问持续时间、%新访问次数、跳出率)。我尝试使用define('filter','source==direct')对其进行过滤as,但运气不佳。我看过类似的帖子,但我想深化我的搜索。我错过什么了吗 我的当前代码只能从所有流量中检索数据。 require_once('gapi.class.php'); define('e

我是google analytics的新手,现在仍在寻找出路。我试图找到一种方法来检索仪表板上直接流量(流量源-->源-->直接)下的数据(登录页、访问次数、页面/访问次数、平均访问持续时间、%新访问次数、跳出率)。我尝试使用
define('filter','source==direct')对其进行过滤as,但运气不佳。我看过类似的帖子,但我想深化我的搜索。我错过什么了吗

我的当前代码只能从所有流量中检索数据。

require_once('gapi.class.php');

define('email', 'email address');
define('password', 'password');
define('profileID', profileID);
define('dimensions', 'source');
define('metrics', 'visits');
define('sortMetric', '-visits');
define('filter', null);
define('startDate', '2013-01-18');
define('endDate', '2013-02-17');
define('startIndex', 1);
define('maxResult', 10);

$ga = new gapi(email, password);
$ga->requestReportData(profileID,dimensions,metrics,sortMetric,filter,startDate,endDate,startIndex,maxResult);

foreach($ga->getResults() as $result){
    echo '<strong>'.$result.'</strong><br />';
    echo 'Source: ' . $result->getSource() . ' ';
    echo 'Visits: ' . $result->getVisits() . '<br /><br />';
}
require_once('gapi.class.php');
定义(“电子邮件”、“电子邮件地址”);
定义(‘密码’、‘密码’);
定义('profileID',profileID);
定义(‘维度’、‘来源’);
定义(‘指标’、‘访问’);
定义(‘排序’、‘访问’);
定义('filter',null);
定义(“起始日期”、“2013-01-18”);
定义(“截止日期”、“2013-02-17”);
定义('startIndex',1);
定义('maxResult',10);
$ga=新的gapi(电子邮件、密码);
$ga->requestReportData(profileID、维度、度量、sortMetric、筛选器、startDate、endDate、startIndex、maxResult);
foreach($ga->getResults()作为$result){
回显“”.$result.“
”; 回显“Source:”.$result->getSource(); 回显“访问:”。$result->getvisions()。

; }
我找到了答案,只是想和大家分享一下,以防有人遇到同样的问题

基本上,我的错误是没有用括号括住
direct
)。我刚刚替换了
define('filter','source==direct')进入
定义('filter','source==(direct')和中提琴!我得到我想要的

这是我的代码,以防您需要它,您可能会注意到我已经替换了维度和度量,因为我需要它们成为一个数组

require_once('gapi.class.php');

define('email', 'email address');
define('password', 'password');
define('profileID', profileID);
$dimensions = array('landingPagePath');
$metrics = array('visits','pageviewsPerVisit','avgTimeOnSite','percentNewVisits','visitBounceRate');
define('sortMetric', '-visits');
define('filter', 'ga:source==(direct)');
define('startDate', '2013-01-18');
define('endDate', '2013-02-17');
define('startIndex', 1);
define('maxResult', 10);

$ga = new gapi(email, password);
$ga->requestReportData(profileID,$dimensions,$metrics,sortMetric,filter,startDate,endDate,startIndex,maxResult);

我找到了答案,只是想和大家分享一下,以防有人遇到同样的问题

基本上,我的错误是没有用括号括住
direct
)。我刚刚替换了
define('filter','source==direct')进入
定义('filter','source==(direct')和中提琴!我得到我想要的

这是我的代码,以防您需要它,您可能会注意到我已经替换了维度和度量,因为我需要它们成为一个数组

require_once('gapi.class.php');

define('email', 'email address');
define('password', 'password');
define('profileID', profileID);
$dimensions = array('landingPagePath');
$metrics = array('visits','pageviewsPerVisit','avgTimeOnSite','percentNewVisits','visitBounceRate');
define('sortMetric', '-visits');
define('filter', 'ga:source==(direct)');
define('startDate', '2013-01-18');
define('endDate', '2013-02-17');
define('startIndex', 1);
define('maxResult', 10);

$ga = new gapi(email, password);
$ga->requestReportData(profileID,$dimensions,$metrics,sortMetric,filter,startDate,endDate,startIndex,maxResult);