PinkyTV
PinkyTV

Reputation: 118

Google analytics api DateRange definition

What exactly is the definition of "1daysAgo" in the google analytics reporting api?

I'm using the analytics api to fetch incoming traffic. I want to get results of incoming traffic for the last 24 hours.

If i create a new DateTime Object in php like:

$date = new DateTime('1daysAgo');

I'm getting a date which is exactly 24 hours ago. But it seems the google analytics api uses a different alogrithm for "1daysago".

When i use something like:

// Create the DateRange object.
$dateRange = new \Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate( "1daysAgo" );
$dateRange->setEndDate( "today" );

at first the output result looks fine, if i compare it with my results on analytics.google.com. But i cannot exactly compare it because in the webconsole i could only filter by date and not by time.

And for some reason at 00:00 am the output response from incoming traffic makes a big step back.

For example:

at 11:30pm example.com sends 2500 user.
at 00:00am example.com sends 1500 user.

So how exactly can i correct understand the DateRange "1daysAgo"?

Upvotes: 0

Views: 971

Answers (1)

sdhaus
sdhaus

Reputation: 1896

1) What date is used by Google Analytics API:

The 'daysAgo' Google Analytics API starts from 'yesterday'. This means that for the API, 1daysAgo could be anything from 24:01 hours ago, to 47:59 hours ago.

E.g. At 3pm on the 15/12/2016, 1dayAgo would be the day of 14/12/2016, from 00:00 to 23:59.

2) The reason why there would be a large drop at mid night is that Google Analytics sessions end at midnight. This means that in your example, there were probably 1000 inactive users who's session was cut off at midnight.

Upvotes: 1

Related Questions