title: how to use multiple filter in google analytics reporting api v4?
body: <p><a href="https://developers.google.com/analytics/devguides/reporting/core/v4/samples" rel="nofollow noreferrer">https://developers.google.com/analytics/devguides/reporting/core/v4/samples</a> for find data from google analytic.</p>
  
  <p>I want to find data using multiple dimension filter but not able to do it.<br>
  i am using the code.</p>
  
  <p>function buildSimpleSegment($segmentName, $dimension, $dimensionFilterExpression) {</p>
  
  <pre><code>// Create the segment dimension.
  $segmentDimensions = new Google_Service_AnalyticsReporting_Dimension();
  $segmentDimensions-&gt;setName("ga:segment");
  
  // Create Dimension Filter.
  $dimensionFilter = new Google_Service_AnalyticsReporting_SegmentDimensionFilter();
  $dimensionFilter-&gt;setDimensionName($dimension);
  $dimensionFilter-&gt;setOperator("EXACT");
  $dimensionFilter-&gt;setExpressions(array($dimensionFilterExpression));
  
  //print_r($dimensionFilter);die;
  // Create Segment Filter Clause.
  $segmentFilterClause = new Google_Service_AnalyticsReporting_SegmentFilterClause();
  $segmentFilterClause-&gt;setDimensionFilter($dimensionFilter);
  
  // Create the Or Filters for Segment.
  $orFiltersForSegment = new Google_Service_AnalyticsReporting_OrFiltersForSegment();
  $orFiltersForSegment-&gt;setSegmentFilterClauses(array($segmentFilterClause));
  
  // Create the Simple Segment.
  $simpleSegment = new Google_Service_AnalyticsReporting_SimpleSegment();
  $simpleSegment-&gt;setOrFiltersForSegment(array($orFiltersForSegment));
  
  // Create the Segment Filters.
  $segmentFilter = new Google_Service_AnalyticsReporting_SegmentFilter();
  $segmentFilter-&gt;setSimpleSegment($simpleSegment);
  
  // Create the Segment Definition.
  $segmentDefinition = new Google_Service_AnalyticsReporting_SegmentDefinition();
  $segmentDefinition-&gt;setSegmentFilters(array($segmentFilter));
  
  // Create the Dynamic Segment.
  $dynamicSegment = new Google_Service_AnalyticsReporting_DynamicSegment();
  $dynamicSegment-&gt;setSessionSegment($segmentDefinition);
  $dynamicSegment-&gt;setName($segmentName);
  
  // Create the Segments object.
  $segment = new Google_Service_AnalyticsReporting_Segment();
  $segment-&gt;setDynamicSegment($dynamicSegment);
  return $segment;
  </code></pre>
  
  <p>}</p>
  
  <p>function getReport($analyticsreporting) {</p>
  
  <pre><code>// Create the DateRange object.
  $dateRange = new Google_Service_AnalyticsReporting_DateRange();
  
  if (isset($_GET['startdat']) &amp;&amp; isset($_GET['enddate'])) {
      $dateRange-&gt;setStartDate($_GET['startdat']);
      $dateRange-&gt;setEndDate($_GET['enddate']);
  } else {
      $dateRange-&gt;setStartDate(date('Y-m-d', strtotime(date('Y-m-d') . ' - 1 month')));
      $dateRange-&gt;setEndDate(date('Y-m-d'));
  }
  $domain = $_GET['domain'];
  $VIEW_ID = "xyz";
  // Create the Metrics object.
  
  $totalevent = new Google_Service_AnalyticsReporting_Metric();
  $totalevent-&gt;setExpression("ga:totalEvents");
  $totalevent-&gt;setAlias("totalEvent");
  
  $source = new Google_Service_AnalyticsReporting_Dimension();
  $source-&gt;setName("ga:source");
  
  $eventAction = new Google_Service_AnalyticsReporting_Dimension();
  $eventAction-&gt;setName("ga:eventAction");
  
  $eventLabel = new Google_Service_AnalyticsReporting_Dimension();
  $eventLabel-&gt;setName("ga:eventLabel");
  
  $eventCategory = new Google_Service_AnalyticsReporting_Dimension();
  $eventCategory-&gt;setName("ga:eventCategory");
  
  // Create the segment dimension.
  $segmentDimensions = new Google_Service_AnalyticsReporting_Dimension();
  $segmentDimensions-&gt;setName("ga:segment");
  
  // Create the ReportRequest object.
  $request = new Google_Service_AnalyticsReporting_ReportRequest();
  $request-&gt;setViewId($VIEW_ID);
  $request-&gt;setDateRanges(array($dateRange));
  $request-&gt;setDimensions(array($source, $eventAction, $eventLabel, $eventCategory, $segmentDimensions));
  $request-&gt;setMetrics(array($totalevent));
  
  $sourceSegment = buildSimpleSegment("Source", "ga:source", $domain);
  $videoSegment = buildSimpleSegment("Category", "ga:eventCategory", "JW Player Video Plays");
  $request-&gt;setSegments(array($sourceSegment, $videoSegment));
  
  
  // Call the batchGet method.
  $body = new Google_Service_AnalyticsReporting_GetReportsRequest();
  
  
  
  $body-&gt;setReportRequests(array($request));
  return $response = $analyticsreporting-&gt;reports-&gt;batchGet($body);
  </code></pre>
  
  <p>}</p>