Reputation: 1385
I have a very simple custom report in Google Analytics that lists Date, Visits, Unique Visitors and Pageviews for a certain month.
I am trying to duplicate this very simple report using GAPI, but I cannot find a simple way to add Unique Visitors to my table.
See my code below. How can I modify this code to show Unique Visitors?
$profile_id = "xxxxxxxx";
$report_id = "xxxxxxxx";
$dimensions = array('date');
$metrics = array('pageviews','visits');
$sort_metric = array('date');
$filter = null;
$start_date = '2013-02-01';
$end_date = '2013-02-28';
$start_index = 1;
$max_results = 10000;
echo '<table>';
echo '<tr>';
echo '<th>Date</th>';
echo '<th>Visits</th>';
echo '<th>Unique Visitors</th>';
echo '<th>Page Views</th>';
echo '</tr>';
$ga = new gapi('[email protected]','xxxxxxxx');
$ga->requestReportData($profile_id, $dimensions, $metrics, $sort_metric, $filter, $start_date, $end_date, $start_index, $max_results);
foreach($ga->getResults() as $result)
{
echo '<td>' . $result->getDate() . '</td>';
echo '<td>' . $result->getVisits() . '</td>';
echo '<td>' . '?' . '</td>';
echo '<td>' . $result->getPageviews() . '</td>';
echo '</tr>';
}
echo "</table>";
Upvotes: 2
Views: 2765
Reputation: 1
$profile_id = "xxxxxxxx";
$report_id = "xxxxxxxx";
$dimensions = array('date');
$metrics = array('pageviews','visits','visitors');
$sort_metric = array('date');
$filter = null;
$start_date = '2013-02-01';
$end_date = '2013-02-28';
$start_index = 1;
$max_results = 10000;
Upvotes: 0
Reputation: 31
The metric is called visitors and no visitor and you have to change the dimension to userDefinedValue
$profile_id = "xxxxxxxx";
$report_id = "xxxxxxxx";
$dimensions = array('userDefinedValue');
$metrics = array('pageviews','visits','visitors');
$sort_metric = array('date');
$filter = null;
$start_date = '2013-02-01';
$end_date = '2013-02-28';
$start_index = 1;
$max_results = 10000;
Upvotes: 2