2016-01-18 09:24
浏览 59

PHP - 每小时获取Google Analytics综合浏览量

I'm using to get pageviews from google analytics. I'm following this guide: my custom code:

function getResults(&$analytics, $profileId) {
   return $analytics->data_ga->get(
       'ga:' . $profileId,
            'filters' => 'ga:pagePath==/project_z2o/',
            'dimensions' => 'ga:pagePath',
            'metrics' => 'ga:pageviews',
            'sort' => '-ga:pageviews',
            'max-results' => '25'

Is it possible if I want to get the pageviews every hour. If Yes, What query is it? If No, Is there any another ways that I can get it. Thanks.

图片转代码服务由CSDN问答提供 功能建议

我正在使用 从谷歌分析中获取网页浏览量。 我正在关注此指南: https:// developers。 。 我的自定义代码:

  function getResults(& $ analytics,$ profileId){
 return $ analytics-> data_ga-> get(
'ga:'  。$ profileId,
'filters'=>'ga:pagePath == / project_z2o /',
' 维度'=>'ga:pagePath',
'max-results'=>  '25'

如果我想每小时获取一次综合浏览量,是否可能。 如果是,那是什么查询? 如果不是,还有其他方法我可以得到它。 谢谢。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpprx26000 2016-01-18 10:06

    Edit, okay, I misunderstood your question. If you want to query the current hour you'D have to use the realtime API (and more often than hourly), as GA requires some processing time for incoming data, so current data is usually not available (i.e. what you want might not be possible or at least not very reliable). Realtime will return current data on a few select metrics and dimensions (which include path and pageviews). Plus you cannot specify hours for the timeframe so this is moot in any case, you'd have to select "today" as start- and endpoint and break down by the hour (you could add a filter by "ga:hour" and specify the current hour. As I pointed out this will return unreliable data, or no data at all).

    Unless you really really need the data immediately you are better of to query yesterdays data and have it broken down by hour.

    Old answer: I assume that you want the pageview metrics broken down by hour - you'd have to add "ga:hour" as dimension (which would return the hour of the day from 0 to 23). Alternatively you can use ga:nthHour which sequentially counts the hours within your timeframe (i.e. in a seven day timeframe it would count upward to 7*24 = 168 hours).

    You can find this in the dimensions and metrics explorer, "time-based dimensions".

    解决 无用
    打赏 举报

相关推荐 更多相似问题