Reputation: 1642
I trying to fetch multiple dimension values for single metrics .i am getting an error as
"{ "error": { "code": 400, "message": "Unknown dimension(s): ga:sourceMedium,ga:deviceCategory", "errors": [ { "message": "Unknown dimension(s): ga:sourceMedium,ga:deviceCategory", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } }".
it is workign fine if i m sending single dimension value "$browser->setName("ga:sourceMedium"); "
$VIEW_ID = "XXXXXXXX";
// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();
$dateRange->setStartDate($pulldate);//YYYY-mm-dd
$dateRange->setEndDate($pulldate);////YYYY-mm-dd
// Create the Metrics object.
$sessions = new Google_Service_AnalyticsReporting_Metric();
$sessions->setExpression("ga:sessions");
$sessions->setAlias("sessions");
$browser = new Google_Service_AnalyticsReporting_Dimension();
$browser->setName("ga:sourceMedium,ga:deviceCategory");
// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();
$request->setViewId($VIEW_ID);
$request->setDateRanges($dateRange);
$request->setDimensions(array($browser));
$request->setMetrics(array($sessions));
$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analytics->reports->batchGet( $body );
Upvotes: 1
Views: 1910
Reputation: 198
You should get a new instance for Google_Service_AnalyticsReporting_Dimension()
for each dimension like:
$sourceMedium = new Google_Service_AnalyticsReporting_Dimension();
$sourceMedium->setName("ga:sourceMedium");
$deviceCategory = new Google_Service_AnalyticsReporting_Dimension();
$deviceCategory->setName("ga:deviceCategory");
Then when you setDimensions()
you should do it like this:
$request->setDimensions(array($sourceMedium, $deviceCategory));
Easy?
Upvotes: 3
Reputation: 11
Here is the sample This is the way to add multiple Dimensions and metrics..
ReportRequest request = new ReportRequest().setViewId(VIEW_ID).setDateRanges(Arrays.asList(dateRange)).setDimensions(Arrays.asList(browser,browserVersion)).setMetrics(Arrays.asList(sessions));
Upvotes: 0