How to use google analytic API to retrieve today data

I am unable to retrieve the data for today visits from google analytics.

If I use this code I got nothing (0):

 $request_today = array(
      'metrics' => array('ga:visits'),
      'start_date' => strtotime('today'),
      'end_date' =>  strtotime('tomorrow'), 
 );
$analytic_data_today = @google_analytics_counter_report_data($request_today);

If I use this query I get the users of today and yesterday..

 $request_today = array(
      'metrics' => array('ga:visits'),
      'start_date' => strtotime('today')-1,
      'end_date' =>  strtotime('tomorrow'), 
 );
$analytic_data_today = @google_analytics_counter_report_data($request_today);

Answers


Antonello, I am afraid what you are trying to do is not possible with "standard" API due to the data processing delay:

Processing latency is 24-48 hours. Standard accounts that send more than 200,000 visits per day to Google Analytics will result in the reports being refreshed only once a day. This can delay updates to reports and metrics for up to two days.

There is Real-time API available as well, only for Premium customers though (and only metrics available is number of active visitors).


Need Your Help

JLabel with HTML containing "<" and ">" characters

java html swing special-characters jlabel

From time to time I use HTML in JLabels in Java Swing. Lastly I've came across something a little bit, for me, confusing...

Nehe's lesson02 in SDL2, square is not a square

c opengl sdl

I'm trying to do Nehe's OpenGL lessons with SDL2.0, I'm on lesson 2 but I have a geometric problem.