douke1954 2016-01-18 09:24
浏览 64
已采纳

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

I'm using https://github.com/google/google-api-php-client to get pageviews from google analytics. I'm following this guide: https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php. my custom code:

function getResults(&$analytics, $profileId) {
   return $analytics->data_ga->get(
       'ga:' . $profileId,
       '7daysAgo',
       'today',
       'ga:visits',
        array(
            '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.

  • 写回答

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".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改