I've currently got an integration with the Google Analytics (GA) API which pulls data on a daily basis and stores it within a database for use within a PHP project.

I'm trying to get the "Average Session Duration" within my project to match the value of which is set within GA for a specific channel (Organic Search), on a specific day (Apr 1, 2018 - Apr 1, 2018).

As you can see from the below image, the total Average Session Duration for that specific filter within GA is returning "00:04:28", for use later, this in seconds is 268 (Calculated by multiplying the time by [24 * 60 * 60]).

Google Analytics Organic Search Filter View NB: I've removed some key, personal, information from the above image.

If we perform an export of this view, and select the option "Excel (XLSX)", this will give us a spreadsheet with values in which replicate what's returned from the GA API.

The below image shows this dataset, and i've highlighted a few key things which are explained below the image:

Google Analytics Filter View Export

The contents highlighted in blue is static data which is calculated by GA at export-time. This includes an average from them, which is the last row within the highlighted section (H7).

The contents highlighted in red is using the time to seconds calculations (Which was explained earlier), and this successfully replicates the same contents which is within GA. This means that the Average Session Duration coming from the API (In Seconds) converts correctly to the values which are shown (In Time) on the GA dashboard.

Now, here's where I'm having issues; The contents highlighted in pink is using the AVERAGE calculation within Excel, and takes values from H2:H6 and I2:I6 respectively. What I'm expecting is for these two averages to match the averages at the bottom of the blue and red sections, however, as you can see they don't.

Is there anyone here that's able to help with how GA are calculating that average, please?

migrated from webapps.stackexchange.com May 9 '18 at 22:37

This question came from our site for power users of web applications.


I'm afraid you have mis-calculated. You have taken an average of the 'averages' for each traffic source. GA's total average accounts for the weighting of traffic in each channel source - for example, the average session duration of 10,203 google organic sessions was 4:23 so that was the average duration for circa 94% of your traffic in the table. Relatively speaking only a handful of sessions had much higher session durations so they will have little impact on the total average, pulling it up only a bit, hence the total average of 4:28

You can't just take a straight average of the 'averages' which is what your calculation has done. Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy