Hi Thanks for bringing this up!
It's a bit complicated, so let me try to explain what's going on.
First off. The data being accessed by both the Web UI and API is the same and the calculations of each dimension and metric is the same. The main issue people have is that the queries they are issuing between both interfaces is different, and why the numbers appear to be different.
In your query, you're comparing results for only ga:newVisits vs. ga:date and ga:newVisits.
This is easy to do in the API, but more difficult to represent in the UI. In the UI:
- to get new visits, you must look at the overview report and multiply visits * percent new visits.
- to get date and new visits, you can create a custom report, export to csv and sum the results.
If you do this, you'll notice the exact same problem. Both sums are off. So technically our API is working exactly like the UI, and this 'feature' has been around for a while.
So what's going on?
It has to do with sessions which span day boundaries. GA stores data at a daily level, where the end of the day is midnight in the timezone of the configured profile. If a session spans this boundary, GA will split the session into 2 sessions where all the values of the session are exactly the same. This causes the session to effectively be duplicated.
To determine new visits, the tracking code has a visit counter which is incremented for each new session. So if you visit a site on your first session, the visit count == 1. Then on your next session, visit count == 2, etc...
ga:newVisits is the number of occurrences of visit count == 1, for the first hit of a session, within the date range.
ga:date & ga:newVisits is the number of occurrences of visit count == 1 within the date range, for the first hit of a session, where the session is not a duplicated session which occurred from the day boundary splitting. So this value is de-duped.
Thats why you see a difference. And if you subtract the two sums, you can actually get a sense of the number of times this duplication is happening.
When I get a chance, I'll update the ga:newVisit docs.
Hope this helps,
-Nick