Search code examples
google-analytics-api

Specify order of Rows with ga:dayOfWeekName as dimension


I am making an API call using ga:dayOfWeekName as the dimension:

https://www.googleapis.com/analytics/v3/data/ga?ids=ga:xxxxxxxxx&dimensions=ga:dayOfWeekName&metrics=ga:pageviews&start-date=2016-12-24&end-date=2017-01-23&max-results=24

The data returned is not in ga:dayOfWeek order (e.g. Sunday,Monday,Tuesday, etc). Instead it comes back Friday, Monday, Saturday, etc (see screen shot below). Nor is it ordering by the metric. Is there an option to have it return results by the numerical day equivalent?

enter image description here


Solution

  • It is not possible to sort ga:dayOfWeekName as you have mentioned, because it will sort alphabetically only.

    If you want to sort in the order that you have mentioned, add one more dimension ga:dayOfWeek in your API request, which is a one-digit number from 0 (Sunday) to 6 (Saturday) and then add sort query parameter in your API request.

    So your API request should be something like this

    https://www.googleapis.com/analytics/v3/data/ga?ids=ga:xxxxxxxxx&dimensions=ga:dayOfWeekName,ga:dayOfWeek&metrics=ga:pageviews&sort=ga:dayOfWeek&start-date=2016-12-24&end-date=2017-01-23&max-results=24

    Hope it helps.