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 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。
  • ¥15 已知隐函数其中一个变量τ的具体值,求另一个变量
  • ¥15 r语言Hurst指数
  • ¥15 Acrn IVSHMEM doorbell问题
  • ¥15 yolov5中的val测试集训练时数量变小问题