此处:https://ga-dev-tools.appspot.com/query-explorer/

我可以使用多个过滤器,以“或”和“与”分隔。

范例:

 ga:eventAction==display;ga:eventCategory==ban,ga:eventAction==button;ga:eventCategory==ban


上面写着:

 "display and ban" or "button and ban"


如何使用Google Analytics for Php重现此内容?

我试过了

 $filter_clause = new Google_Service_AnalyticsReporting_DimensionFilterClause();

 $filter = new Google_Service_AnalyticsReporting_DimensionFilter();
 $filter->setDimensionName(array('ga:eventAction','ga:eventCategory'));
 $filter->setOperator('EXACT');
 $filter->setExpressions(array('display','ban' ));

 $filter_clause->setFilters( $filter );

 $filter1 = new Google_Service_AnalyticsReporting_DimensionFilter();
 $filter1->setDimensionName(array('ga:eventAction','ga:eventCategory'));
 $filter1->setOperator('EXACT');
 $filter1->setExpressions(array('button','ban'));

 $filter_clause->setFilters( $filter1 );


或这个 :

 $filter_clause->setFilters(array($filter, $filter1));


但是没有任何效果。

最佳答案

对于我的过滤条件:ga:medium =〜organic,ga:sourcemedium =〜^ yandex.ru /引荐; ga:eventlabel =〜gotoreg
或ga:medium =〜organic; ga:eventlabel =〜gotoreg,ga:sourcemedium =〜^ yandex.ru /引荐; ga:eventlabel =〜gotoreg。

代码将如下所示:

/**
 * @return Google_Service_AnalyticsReporting_ReportRequest
 */
protected function createRequest(): Google_Service_AnalyticsReporting_ReportRequest
{
    parent::createRequest();
    $eventLabelDimensionFilterClause = $this->setEventLabelDimensionFilterClause();
    $sourceMediumDimensionFilterClause = $this->setSourceMediumDimensionFilterClause();
    $this->request->setDimensionFilterClauses([$eventLabelDimensionFilterClause,$sourceMediumDimensionFilterClause,]);

    return $this->request;
}

/**
 * @return array
 */
protected function getDimensions(): array
{
    $hostname = $this->setHostnameDimension();
    $source = $this->setSourceDimension();
    $medium = $this->setMediumDimension();
    $landingPagePath = $this->setLandingPagePathDimension();
    $date = $this->setDateDimension();

    return [$hostname, $source, $medium, $landingPagePath, $date,];
}

/**
 * @return Google_Service_AnalyticsReporting_Dimension
 */
protected function setLandingPagePathDimension(): Google_Service_AnalyticsReporting_Dimension
{
    //Create the landingPagePath dimension.
    $landingPagePath = new Google_Service_AnalyticsReporting_Dimension();
    $landingPagePath->setName("ga:landingPagePath");

    return $landingPagePath;
}

/**
 * @return Google_Service_AnalyticsReporting_DimensionFilterClause
 */
protected function setSourceMediumDimensionFilterClause(): Google_Service_AnalyticsReporting_DimensionFilterClause
{
    $mediumDimensionFilter = $this->setMediumDimensionFilter();
    $sourcemediumDimensionFilter = $this->setSourcemediumDimensionFilter();
    $dimensionFilterClause = new Google_Service_AnalyticsReporting_DimensionFilterClause();
    $dimensionFilterClause->setFilters([$sourcemediumDimensionFilter, $mediumDimensionFilter]);
    $dimensionFilterClause->setOperator('OR');

    return $dimensionFilterClause;
}

/**
 * @return Google_Service_AnalyticsReporting_DimensionFilterClause
 */
protected function setEventLabelDimensionFilterClause(): Google_Service_AnalyticsReporting_DimensionFilterClause
{
    $eventLabelDimensionFilter = $this->setEventLabelDimensionFilter();
    $dimensionFilterClause = new Google_Service_AnalyticsReporting_DimensionFilterClause();
    $dimensionFilterClause->setFilters([$eventLabelDimensionFilter]);
    $dimensionFilterClause->setOperator('AND');

    return $dimensionFilterClause;
}

/**
 * @return Google_Service_AnalyticsReporting_SegmentDimensionFilter
 */
protected function setMediumDimensionFilter(): Google_Service_AnalyticsReporting_SegmentDimensionFilter
{
    // Create Dimension Filter.
    $dimensionFilter = new Google_Service_AnalyticsReporting_SegmentDimensionFilter();
    $dimensionFilter->setDimensionName("ga:medium");
    $dimensionFilter->setOperator("REGEXP");
    $dimensionFilter->setExpressions("organic");

    return $dimensionFilter;
}

/**
 * @return Google_Service_AnalyticsReporting_SegmentDimensionFilter
 */
protected function setSourcemediumDimensionFilter(): Google_Service_AnalyticsReporting_SegmentDimensionFilter
{
    // Create Dimension Filter.
    $dimensionFilter = new Google_Service_AnalyticsReporting_SegmentDimensionFilter();
    $dimensionFilter->setDimensionName("ga:sourcemedium");
    $dimensionFilter->setOperator("REGEXP");
    $dimensionFilter->setExpressions("^yandex.ru / referral");

    return $dimensionFilter;
}

/**
 * @return Google_Service_AnalyticsReporting_SegmentDimensionFilter
 */
protected function setEventLabelDimensionFilter(): Google_Service_AnalyticsReporting_SegmentDimensionFilter
{
    // Create Dimension Filter.
    $dimensionFilter = new Google_Service_AnalyticsReporting_SegmentDimensionFilter();
    $dimensionFilter->setDimensionName("ga:eventlabel");
    $dimensionFilter->setOperator("REGEXP");
    $dimensionFilter->setExpressions(["GoToReg"]);
    $dimensionFilter->setCaseSensitive(false);

    return $dimensionFilter;
}


对于您的过滤器代码将是相似的。

关于php - Google_Service_AnalyticsReporting_DimensionFilterClause中的多个过滤器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44042986/

10-14 13:36