Skip to content Skip to sidebar Skip to footer

Google Analytics, Display More Than 1 Query

I'm pretty new to PHP so bear with me please :) Right so I am working with google analytics and I am using one of their scripts to display one query. It looks all good but I'm not

Solution 1:

It is not clear if you need to make multiple queries or if you simply need to add more metrics to your existing query. For example you can query for ga:sessions and ga:percentNewSessions in the same query.

return$analytics->data_ga->get(
    'ga:146790870',
    '2016-11-01',
    'today',
    'ga:sessions, percentNewSessions');

Then you would need to extract the second metric from the results:

  $rows = $results->getRows();
  $sessionstotal = $rows[0][0];
  $percentNewSessions = $rows[0][1];


  // Print the results.
  print "<divclass='col s12 m6 l3'style='text-align:center;'><divclass='card green '><divclass='card-content white-text'><spanclass='card-title'>Total Sessions</span><pstyle='font-size: 1.8rem; font-weight: bold;'>$sessionstotal</p><spanclass='card-title'>Percent New Sessions</span><pstyle='font-size: 1.8rem; font-weight:bold;'>$percentNewSessions</p></div><divclass='card-action  green darken-2'></div></div></div>";

Play around with the results object until you get a sense of its structure. Always use the Reference docs to understand what fields are available.

Post a Comment for "Google Analytics, Display More Than 1 Query"