Search code examples
google-analyticsgoogle-analytics-apiendpoint

Getting all profiles from Google Analytics API


I'm trying to get all profiles using ~all option with this endpoint

https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/profiles

It doesn't return all profiles due to ~all for accounts. If I include account ID instead of ~all, then it returns profiles based on that account id - which are missing when used with ~all option.

https://www.googleapis.com/analytics/v3/management/accounts/89478503/webproperties/~all/profiles

Am I doing something wrong or is this GA API bug?


Solution

  • I sugst you look into using account summaries list

    GET https://www.googleapis.com/analytics/v3/management/accountSummaries
    

    This will return all the account information for a user.

    {
      "kind": "analytics#accountSummaries",
      "username": "me@gmail.com",
      "totalResults": 15,
      "startIndex": 1,
      "itemsPerPage": 1000,
      "items": [
        {
          "id": "59183475",
          "kind": "analytics#accountSummary",
          "name": "Cube Analytics",
          "webProperties": [
            {
              "kind": "analytics#webPropertySummary",
              "id": "UA-59183475-1",
              "name": "Cube Analytics",
              "internalWebPropertyId": "93305066",
              "level": "STANDARD",
              "websiteUrl": "XXXXXXX",
              "profiles": [
                {
                  "kind": "analytics#profileSummary",
                  "id": "115455750",
                  "name": "Alaternate",
                  "type": "WEB"
                },
                {
                  "kind": "analytics#profileSummary",
                  "id": "97191919",
                  "name": "All Web Site Data",
                  "type": "WEB"
                },
                {
                  "kind": "analytics#profileSummary",
                  "id": "178538323",
                  "name": "MobileView",
                  "type": "APP"
                }
              ]
            },      ]
    }
    

    By using this call you should only need to make one call and get all of the information back.