Background
Google API client libraries are created from Google Apps for discovery . And the PHP client library generates setProperty and getProperty for each resource property.
Google V4 Reporting Reporting API
References V4 Reporting API reports in Google Analytics describe the API API exhustively. The developer guide provides a basic example of JSON that will be generated by client libraries:
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet { "reportRequests": [ { "viewId": "XXXX", "dateRanges": [ {"endDate": "2014-11-30", "startDate": "2014-11-01"} ], "metrics": [ {"expression": "ga:pageviews"}, {"expression": "ga:sessions"} ], "dimensions": [{"name": "ga:browser"}, {"name": "ga:country"}], "dimensionFilterClauses": [ { "filters": [ { "dimensionName": "ga:browser", "operator": "EXACT", "expressions": ["Chrome"] } ] } ] } ] }
And the Samples page provides many sample queries in Python, Java, PHP and JavaScript that should give you a good idea of โโhow to work with individual client libraries, But you are right, there is no explicit example of PHP using a filter.
PHP Filter Example
Below is the example above:
// Create the DateRange object. $dateRange = new Google_Service_AnalyticsReporting_DateRange(); $dateRange->setStartDate("2014-11-01"); $dateRange->setEndDate("2014-11-30"); // Create the Metrics object. $pageviews = new Google_Service_AnalyticsReporting_Metric(); $pageviews->setExpression("ga:pageviews"); $sessions = new Google_Service_AnalyticsReporting_Metric(); $sessions->setExpression("ga:sessions"); //Create the Dimensions object. $browser = new Google_Service_AnalyticsReporting_Dimension(); $browser->setName("ga:browser"); $country = new Google_Service_AnalyticsReporting_Dimension(); $country->setName("ga:country"); // Create the DimensionFilter. $dimensionFilter = new Google_Service_AnalyticsReporting_DimensionFilter(); $dimensionFilter->setDimensionName('ga:browser'); $dimensionFilter->setOperator('EXACT'); $dimensionFilter->setExpressions(array('Chrome')); // Create the DimensionFilterClauses $dimensionFilterClause = new Google_Service_AnalyticsReporting_DimensionFilterClause(); $dimensionFilterClause->setFilters(array($dimensionFilter)); // Create the ReportRequest object. $request = new Google_Service_AnalyticsReporting_ReportRequest(); $request->setViewId("XXXX"); $request->setDateRanges($dateRange); $request->setDimensions(array($browser, $country)); $request->setDimensionFilterClauses(array($dimensionFilterClause)); $request->setMetrics(array($pageviews, $sessions)); $body = new Google_Service_AnalyticsReporting_GetReportsRequest(); $body->setReportRequests( array( $request) ); return $analyticsreporting->reports->batchGet( $body );
As you probably noticed, I never used $object->getProperty() . Basically all he would do was give me the current value. When calling the API, you always only need $object->setProperty($value); Therefore, why I gave you the background created by the client libraries.
Conclusion
The Analytics Reporting API itself is complex and there are many client library languages. It is not always possible to give an example of using the API in all possible languages โโof the client library. That is why it is necessary to understand how to look at reference documents and understand how client libraries are created from the described structure.