我目前正在研究一种分析Web工具,该工具从各种网络分析API中提取并生成各种报告,其中之一是基于Google Analytics(分析)的报告。谷歌分析API日期范围请求返回的数据不是本地Google用户界面
我拉了很多数据,它们都与我在Google的原生用户界面中看到的结果相匹配......好吧,除了一个数据项,这是一个30天的日期范围查询细分正好在1年前。
我花了一段时间在谷歌论坛上搜索和在这里,但我还没有发现任何人有日期范围查询的数据不准确。大多数我见过有相关的数据采样不准确的设置VS原始查询(https://support.google.com/analytics/answer/1042498?hl=en)
如果我var_dump()
我的结果恢复我看到开始和结束日期是否正确匹配我在进入开始和结束日期GA用户界面。有谁知道这里会发生什么?我已经看到其他SO线程,用户似乎可以使用Google Analytics本机用户界面为日期范围请求获得匹配结果。
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用户界面可能使用不同的时间/日期区域吗?如果是这样,我错过了在我的请求中发送一个参数吗?