I've been looking at this tutorial http://www.codediesel.com/php/reading-google-analytics-data-from-php/ but am struggling as I only want to retrieve the total number of unique visitors which is a metric.
It appears that you have to use a 'dimension' to get the 'metric' when using their API.
Any ideas on how I can avoid using a dimension as all I want is the total.
Thanks
Dimension is not mandatory.
Use:
Metric: ga:visitors and do mention the start-date and end-date to get the data in the desired range, which is required. You will get the desired total.( P.S. The calculation of ga:visitors has been changed to return the number of unique visitors across the date range )
$analytics = new Google_Service_Analytics($client);
$profileId = 'UA-00000000-1';
$yesterday=$startDate=$endDate=date("Y-m-d", time() - 60 * 60 * 24 );
$metrics = 'sessions';
$results = $analytics->data_ga->get('ga:'.$profileId, $startDate, $endDate, 'ga:'.$metrics);
Requires - https://github.com/google/google-api-php-client
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With