Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle analytics PHP API returns empty values
    primarykey
    data
    text
    <p>When I perform an API request to google analytics I often get no data back. Sometimes it works and other times it just doesnt.</p> <p>My API call looks like this:</p> <pre><code>public function get_pageviews( ) { $result = $this-&gt;service-&gt;data_ga-&gt;get( 'ga:' . $this-&gt;profile_id, // report id $this-&gt;convert_time( "-".$this-&gt;timespan." days", "Y-m-d" ), // start date $this-&gt;convert_time( $this-&gt;end, "Y-m-d" ), // end date "ga:pageviews", // metrics array( "dimensions" =&gt; "ga:date" ) // other... ); return $result; } </code></pre> <p>The correct output is: </p> <pre><code> ["totalsForAllResults"]=&gt; array(1) { ["ga:pageviews"]=&gt; string(4) "1503" } ["rows"]=&gt; array(8) { [0]=&gt; array(2) { [0]=&gt; string(8) "20120823" [1]=&gt; string(3) "333" } [1]=&gt; array(2) { [0]=&gt; string(8) "20120824" [1]=&gt; string(3) "185" } [2]=&gt; array(2) { [0]=&gt; string(8) "20120825" [1]=&gt; string(2) "52" } [3]=&gt; array(2) { [0]=&gt; string(8) "20120826" [1]=&gt; string(3) "110" } [4]=&gt; array(2) { [0]=&gt; string(8) "20120827" [1]=&gt; string(3) "335" } [5]=&gt; array(2) { [0]=&gt; string(8) "20120828" [1]=&gt; string(3) "222" } [6]=&gt; array(2) { [0]=&gt; string(8) "20120829" [1]=&gt; string(3) "257" } [7]=&gt; array(2) { [0]=&gt; string(8) "20120830" [1]=&gt; string(1) "9" } } </code></pre> <p>And the wrong output, with no data is: </p> <pre><code>["totalsForAllResults"]=&gt; array(1) { ["ga:pageviews"]=&gt; string(1) "0" } ["rows"]=&gt; array(8) { [0]=&gt; array(2) { [0]=&gt; string(8) "20120823" [1]=&gt; string(1) "0" } [1]=&gt; array(2) { [0]=&gt; string(8) "20120824" [1]=&gt; string(1) "0" } [2]=&gt; array(2) { [0]=&gt; string(8) "20120825" [1]=&gt; string(1) "0" } [3]=&gt; array(2) { [0]=&gt; string(8) "20120826" [1]=&gt; string(1) "0" } [4]=&gt; array(2) { [0]=&gt; string(8) "20120827" [1]=&gt; string(1) "0" } [5]=&gt; array(2) { [0]=&gt; string(8) "20120828" [1]=&gt; string(1) "0" } [6]=&gt; array(2) { [0]=&gt; string(8) "20120829" [1]=&gt; string(1) "0" } [7]=&gt; array(2) { [0]=&gt; string(8) "20120830" [1]=&gt; string(1) "0" } } </code></pre> <p>As you can see, the multidimensional array <strong>rows</strong> is not empty but the values in the array are set to 0 while it is the exact same request i have sent using the Google Analtyics API.</p> <p>Is there anything I am missing in my request or something else I am doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload