gpt4 book ai didi

php - Google Analytics PHP API(GAPI)-获取直接流量数据

转载 作者:行者123 更新时间:2023-12-03 16:06:18 25 4
gpt4 key购买 nike

我是Google Analytics(分析)的新手,但仍能找到解决方法。我正在尝试找到一种方法来在仪表板上的直接流量(流量来源->来源->下)下检索数据(着陆页,访问次数,页面/访问次数,平均访问持续时间,新访问百分比,跳出率)直接)。我试过通过使用define('filter', 'source == direct');作为their website states对其进行过滤,但是没有运气。我看到过类似的帖子here,但我想加深搜索范围。我想念什么吗?

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

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 />';
}

最佳答案

我找到了答案,只是想与大家分享,以防万一有人遇到相同的问题。

基本上,我的错误是我没有用括号direct()引起来。我只是将define('filter', 'source == direct');替换为define('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);

关于php - Google Analytics PHP API(GAPI)-获取直接流量数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14953919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com