如何对特定用户页面使用 google 分析 api

How to use google analytics api for specific user pages

我网站上的注册用户有自己的页面。我想为他们提供一些基本的页面浏览量分析:浏览量、引荐来源网址、浏览器、OS 和国家/地区。用户应该能够按小时、天、周、月和所有进行过滤。 我可以使用 Google Analytics API 在我的网站上实施吗?

我正在尝试了解这个过程。

问题:

Should I use API v3 or v4?

开始新项目时,最好始终使用 api 的最新版本,因为旧版本有时会被关闭。

What are valid date ranges, can it be any DateTime value? Eg. 22/01/19 8:00:00 AM to 22/01/19 9:00:00 AM

Google 分析始于 2005 年,因此只要有开始日期,由于数据延迟,结束日期应该在 48 小时前左右。另外,您发送的时间不只是日期。您应该查阅文档。

Can I use one query to get view count, referrer, browser, OS and country for a page based on a certain date rage? Not sure what metrics and dimensions I need to use. If you can please provide me with a sample query.

你应该查阅文档我无法为你查询,因为只有你知道你需要什么数据而且你可能不会使用与我相同的编程语言

If the analytics account is GMT +00:00, how would I deal with this for different user locals? Get the users region convert to DateTime.UtcNow, do the query and the convert back to local DateTime?

我认为即使考虑到这一点也会让我头疼,我祝你好运。 Google 分析中的数据是多维分析。我不知道您打算如何找出当前用户的时区,然后将其更改为帐户的实际时区,然后只为该时区以外的用户请求结果。再次祝你好运

来自评论

So it not possible to get say the view for the last hour?

如果您现在需要数据,您可以使用实时 api,但您的问题将与配额有关。您每天只能针对单个视图发出 10k 个请求。实时api可以快点吃那个。

I specified what data I want view count and referrer, browser, OS, country for each view based on a date range. Is it not possible to create a single query for this or you're not sure how it would be done?

是的,这是可能的。我建议您检查 documentation 中的名称..

     "reportRequests":[
      {
        "viewId":"XXXX",
        "dateRanges":[
          {
            "startDate":"2015-06-15",
            "endDate":"2015-06-30"
          }],
        "metrics":[
          {
            "expression":"ga:sessions"
          }],
        "dimensions": [
          {
            "name":"ga:browser"
          }, {
            "name":"ga:os"
          },
{
            "name":"ga:country"
          }]
        }]
    }

Not sure what you mean by your last answer, can you please elaborate. How would you solve it?

不,我无法详细说明,因为我不会解决它。你正在做的事情是行不通的你每天只能针对这个 api 每个视图发出 10k 请求我看不出你打算如何为你网站上的每个用户获取数据,除非你可能只有 100 个用户。