title: Get Time-series / Data by Metric Over Time in Google Analytics API v3 + PHP
body: <p>I'm using CodeIgniter and the Analytics v3 API PHP library. </p>
  
  <p><strong><em>EDIT:</strong> originally I was using <a href="https://github.com/jayaneetha/GoogleAnalytics-CodeIgniter" rel="nofollow noreferrer">jayaneetha/GoogleAnalytics-CodeIgniter</a>...That repo is great for initial CodeIgniter setup, but is probably less favourable than using the v4 library)</em></p>
  
  <p><strong>What I want to accomplish:</strong> Build out a line chart of sessions for a specific date range; ideally as an array so I can JSON encode it. For example:</p>
  
  <pre><code>$ga_timeseries_data = (
    '2019-01-01' =&gt; 123,
    '2019-01-02' =&gt; 456,
    // ...
  );
  </code></pre>
  
  <p><strong>What I have:</strong> The API set up and able to call summary metrics for specific date ranges. Specifically, the returned information is a sum of the data for the specified range.</p>
  
  <p><strong>Where I'm getting stuck:</strong> How can I pull time-series data via the API? I don't want to loop through dates and make an API request for each date as I imagine that doing so would be slow.</p>
  
  <p>My code:</p>
  
  <pre><code>function get_timeseries($type = 'sessions',$start_date, $end_date) {
     if ($this-&gt;access_token_ready) {
         $analytics = new Google_AnalyticsService($this-&gt;client);
         try {
             $optParams = array();
             $optParams['max-results'] = '5000';
             $results = $analytics-&gt;data_ga-&gt;get('ga:' . $this-&gt;ga_api_profileId, $start_date, $end_date, 'ga:' . $type, $optParams);
             return $results-&gt;getRows(); // This only outputs sum data.
         } catch (Exception $ex) {
             $error = $ex-&gt;getMessage();
             die($error);
         }
     }
  }
  </code></pre>