Search code examples
google-analyticsgoogle-analytics-api

Why Google Analytics API works weird?


I am using Google Analytics Reporting API v4 and I noticed weird behavior when asking for users metric. When I use the next request body everything is just fine.

{
"reportRequests": [
    {
        "metrics": [
            {
                "expression": "ga:users"
            }
        ],
        "dateRanges": [
            {
                "startDate": "2016-08-23",
                "endDate": "2020-01-01"
            }
        ],
        "viewId": "1111111",
    }
]
}

I have the next response:

"data": {
    "rows": [
      {
        "metrics": [
          {
            "values": [
              "1985"
            ]
          }
        ]
      }

When I try to go forward on the timeline, setting startDate to "2017-08-23" or "2018-08-23", total number of users linearly decreases. That's logical and ok. But when I set start date to earlier dates, like "2016-08-22" or "2015-08-23", I get NO DATA. Example of request:

{
"reportRequests": [
    {
        "metrics": [
            {
                "expression": "ga:users"
            }
        ],
        "dateRanges": [
            {
                "startDate": "2015-08-22",
                "endDate": "2020-01-01"
            }
        ],
        "viewId": "1111111"
    }
]

}

Response:

"data": {
    "isDataGolden": true
  }

Request headers and viewId are valid.

Is it a bug or there is some logical explanation of such behavior? Any help will be appreciated.


Solution

  • From 1 September 2016, Google Analytics has added a new feature, the ability to set the Users metric as the main metric, instead of the Sessions. This event has been called Users Everywhere and affects some relationships, including audience reports and acquisition reports.

    If in the reports in Google Analytics the date range includes a period of time prior to 1 September 2016, 0 users are shown. This is true if the option to enable the Users metric in reports, present at the Property level, is active.

    So this could be the reason: https://www.analyticstraps.com/zero-utenti-con-sessioni/

    https://support.google.com/analytics/answer/2992042?hl=en