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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题