gpt4 book ai didi

php - Google Analytics API 日期范围请求返回的数据与 native Google UI 不同

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

我目前正在开发一种分析网络工具,该工具可以从各种网络分析 API 中提取数据并生成各种报告,其中之一是基于 Google Analytics(分析)的报告。

我提取了大量数据,所有这些数据都与我在 Google 原生 UI 中看到的结果相匹配...好吧,除了一个数据项(30 天段的日期范围查询)之外的所有数据正好 1 年前。

我花了时间查看 Google 论坛和此处的 SO,但我没有发现其他人的日期范围查询数据不准确。我看到的大多数不准确之处都与数据样本集与原始查询有关 ( https://support.google.com/analytics/answer/1042498?hl=en )

如果我 var_dump() 返回结果,我会发现开始日期和结束日期与我在 GA UI 中输入的开始日期和结束日期正确匹配。有谁知道这里会发生什么?我见过其他 SO 线程,其中用户似乎能够通过 Google Analytics native UI 获取日期范围请求的匹配结果。

if(!$cached) {
$analytics_svc = new Google_Service_Analytics($client);

$metrics = [
'ga:sessions',
'ga:pageviews',
'ga:bounces',
'ga:avgSessionDuration',
'ga:avgPageLoadtime',
'ga:bounceRate',
'ga:goalConversionRateAll',
'ga:organicSearches'
];

$dimensions = [
'ga:date',
'ga:source',
'ga:medium',
'ga:socialNetwork'
];

$metrics = implode(',', $metrics);
$dimensions = implode(',', $dimensions);

$from = date('Y-m-d', strtotime('-31 days'));
$to = date('Y-m-d', time() - 86400);
$from_lm = date('Y-m-d', strtotime('-61 days'));
$to_lm = date('Y-m-d', strtotime('-31 days'));
$from_ly = date('Y-m-d', strtotime('-1 year -31 days'));
$to_ly = date('Y-m-d', strtotime('-1 year -1 day'));

try {
$adwords_metrics = implode(','['ga:CPC','ga:CTR','ga:impressions','ga:adClicks']);
$adwords_dimensions = implode(',', []);
$adwords = $analytics_svc->data_ga->get('ga:' . $profile->profile, $from, $to, $adwords_metrics, ['dimensions' => $adwords_dimensions]);
$analytics = $analytics_svc->data_ga->get('ga:' . $profile->profile, $from, $to, $metrics, compact('dimensions'));
$analytics_lm = $analytics_svc->data_ga->get('ga:' . $profile->profile, $from_lm, $to_lm, $metrics, compact('dimensions'));
$analytics_ly = $analytics_svc->data_ga->get('ga:' . $profile->profile, $from_ly, $to_ly, $metrics, compact('dimensions'));
} catch(Exception $e) {
Session::flush();
Session::regenerate();

Flash::error('An error was encountered while attempting to read from Google Analytics.<br/>If the problem persists, '.
'<a href="https://accounts.google.com/logout?service=oz" target="_blank">log out of your Google account</a>'.
' and try again.<br/>' . $e->getMessage());
return Redirect::to('/login');
}
}

我得到的两个结果集并没有显着不同,但足以让我的客户担心。 API 请求与原生 GA UI 是否可能使用不同的时间/日期区域?如果是这样,我是否错过了在请求中发送参数?

最佳答案

可能是抽样的情况。尝试将您的分割范围缩小到几天或几周。

关于php - Google Analytics API 日期范围请求返回的数据与 native Google UI 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33137550/

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