2.3K members online now
Understand information in your reports and troubleshoot reporting issues such as self-referrals, (not set) data, and inaccurate information
Guide Me

Sort on SessionDurationBucket in the GA query explorer

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭



I trying to create a report about how much time people spend on my site.

I'm using the Google Analytics Query explorer and the Google Analytics sheets plugin.


I'm trying to get a list with

0 seconds - 350 sessions 

1 second - 400 sessions

2 seconds - 300 sessions

3 seconds - 800 sessions


From what I know this should be possible by creating a report.

metrics: sessions

dimensions: sessionDurationBucket

sort: sessionDurationBucket


But both the query explorer and Google analytics sheets plugin use "text sorting"

So this querry returns:

0s -  40000 sessions

1s - 3000 sessions

10s - 3500 sessions

100s - 18000 sessions

11s - 400 sessions


and so on. While I would expext 0, 1, 2, 3, etc..

Does anybody know how I can fix this?


I can obviously just execute the query and sort in sheets. But the query only exports ±1000 lines and the last lines is 1881 seconds.

So then I only have 1 til 18 seconds...


It's dificult to explain, let me know if you need more info.


I would think this is a bug in the way the query explorer has sorting implemented.


1 Expert replyverified_user

Re: Sort on SessionDurationBucket in the GA query explorer

Top Contributor
# 2
Top Contributor
Include the Avg Sessions Duration METRIC, and sort on that, ascending.

If each row includes only a sessions duration bucket of 10 seconds, then regardless of how many sessions are included that row should also show an average session duration (number) or 10. Metrics sort numerically.

Your next problem is that there may be some numbers missing in the sequence, especially as they numbers get larger. You also have to do the grouping to get a frequency distribution chart typically shown in reports.
Mike Sullivan, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.