UPDATE: Cross posting in Google Groups to draw more attention.
I manage to get my php client using Google Analytics v3 API.
However, I have trouble navigating to get the bounce rate based on 3 different segments:
My code is below:
// create service and get data
$service = new Google_Service_Analytics($client);
// ids - Unique table ID for retrieving Analytics data. Table ID is of the form ga:XXXX, where XXXX is the Analytics view (profile) ID.
// startDate - Start date for fetching Analytics data. Requests can specify a start date formatted as YYYY-MM-DD, or as a relative date (e.g., today, yesterday, or 7daysAgo). The default value is 7daysAgo.
// endDate - End date for fetching Analytics data. Request can should specify an end date formatted as YYYY-MM- DD, or as a relative date (e.g., today, yesterday, or 7daysAgo). The default value is yesterday.
// metrics - A comma-separated list of Analytics metrics. E.g., 'ga:sessions,ga:pageviews'. At least one metric must be specified.
$ids = 'ga:59542xxx';
$startDate = '2014-01-01';
$endDate = '2014-01-31';
$metrics = 'ga:bounces';
$optParams = array('segment' => 'users::sequence::ga:userType==New Vistor');
$call = $service->data_ga->get($ids, $startDate, $endDate, $metrics, $optParams);
My code is largely based on this link.
The 3 segments I want is Organic Traffic, New Users, Returning Users.
I know the condition is
ga:userType==New Visitor
ga:userType==Returning Visitor
ga:medium==organic
My questions are:
do I need to send 3 separate calls?
How do I structure the conditionScope and conditionType? Based on https://developers.google.com/analytics/devguides/reporting/core/v3/segments#reference