Garrett Tichy
unread,Aug 14, 2012, 4:13:43 PM8/14/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google-analytics...@googlegroups.com
This is my first attempt to work with the Core Reporting API. I have
successfully made it through the Hello Analytics tutorial and making API
requests with no issue. My problem lies with querying the API for
using Dimensions, Metrics, and Filters. Below is the code I am working
with.. I am able to display how many visitors I have between the first
of the month and the current day. Then it displays how many of these
came from organic search. I am hoping someone can give me an example on querying the API with a more complex request.. perhaps including Dimensions, Metrics, Filters.. and then displaying then in rows. Any help is much appreciated. Below is my code so far...
function getResults($analytics, $profileId, $first_day, $today) {
return $analytics->data_ga->get(
'ga:' . $profileId,
$first_day,
$today,
'ga:visits, ga:organicSearches');
}
//OUTPUT THE RESULTS
function printResults(&$results) {
if (count($results->getRows()) > 0) {
$profileName = $results->getProfileInfo()->getProfileName();
$rows = $results->getRows();
$visits = $rows[0][0];
$organic = $rows[0][1];
print "<h1>$profileName</h1>";
echo '<table border="1" cellpadding="5">';
echo '<tr>';
echo '<td>Visits</td>';
echo '<td>Organic</td>';
echo '</tr>';
echo '<tr>';
echo '<td>'. $visits . '</td>';
echo '<td>'. $organic . '</td>';
echo '</td>';
echo '</table>';
} else {
print '<p>No results found.</p>';
}
}