2

I'm trying to obtain unsampled data from the Google Analytics API, but for some reason it always comes out sampled. Even if I select only one day and filter for one page only. This is what I've tried on Google's Query Explorer:

Sampled Data Always

What do I need to do to overcome this? Also, is there a way to see how much of the data is sampled (without having to log into the Google Analytics page...)?

4

2 回答 2

3

在您的查询中,您需要提供采样级别

samplingLevel=DEFAULT Optional.
  Use this parameter to set the sampling level (i.e. the number of visits used to 
  calculate the result) for a reporting query. The allowed values are consistent with
  the web interface and include: 
       •DEFAULT — Returns response with a sample size that balances speed and accuracy. 
       •FASTER — Returns a fast response with a smaller sample size. 
       •HIGHER_PRECISION — Returns a more accurate response using a large sample size, 
         but this may result in the response being slower. 

If not supplied, the DEFAULT sampling level will be used.

您还没有说明您使用的是哪种语言,因此您必须检查库中的该语言并弄清楚如何发送它。


更新:尝试帮助编写代码。我没有对此进行测试,但我猜你会将它添加为可选参数。让我知道它是否不起作用,我会看看我是否可以让它工作。

$optParams = array(
    'dimensions' => 'ga:dateHour,ga:hour', 
    'filters' => 'ga:pagePath=~'.$pagelink.'*', 
    'max-results' => 1, 
    'sort' => 'ga:dateHour',
    'samplingLevel' => 'HIGHER_PRECISION' );


$results_starttime = $connect->data_ga->get( 'ga:' . $signedupuser["google id"],
$startdate_analysed, 
$enddate_analysed, 
'ga:uniquePageviews', $optParams );

更新 2:确保您从我检查过的 GitHub google/google-api-php-client下载了 lib,并且那里的 Analytics.php 确实有支持采样级别的代码。


更新 3 您从上面的 GitHub 检查链接获取旧版本的 lib。 google-api-php 客户端

地位:

库的下一个主要版本(1.0.1-beta)的 beta 版本可用,请尽可能迁移。较新的版本发布在 GitHub 上。所有新的开发和问题跟踪都将在 Github 上进行。

于 2014-02-10T08:34:16.720 回答
1

您是否偶然超过了采样的每日限制(500,000 次访问) ?如果是这样,获取非抽样数据在技术上是不可能的。

否则,请在非常相似的问题上查看此答案。

于 2014-02-12T09:20:22.290 回答