当前位置: 动力学知识库 > 问答 > 编程问答 >

google analytics api - GA API v4 several DimensionFilter's works strange (php)

问题描述:

I trying to get statistic by event using GA APi v4 on php.

Here is ga js on the page:

 <script type="text/javascript">

ga("send", "event", "eventCategory", "eventAction", "eventLabel");

</script>

I want to get count of executions of this event(eventCategory), filtered by , eventAction and eventLabel. Here is my code, based on Google guide:

 function getReport($analytics) {

$totalEvents = new Google_Service_AnalyticsReporting_Metric();

$totalEvents->setExpression("ga:totalEvents");

$totalEvents->setAlias("totalEvents");

$dimensionFilter = new Google_Service_AnalyticsReporting_DimensionFilter();

$dimensionFilter->setDimensionName('ga:eventCategory');

$dimensionFilter->setOperator('EXACT');

$dimensionFilter->setExpressions('My_event name');

$dimensionFilter2 = new Google_Service_AnalyticsReporting_DimensionFilter();

$dimensionFilter2->setDimensionName('ga:eventAction');

$dimensionFilter2->setOperator('EXACT');

$dimensionFilter2->setExpressions('My_event_action');

$dimensionFilter3 = new Google_Service_AnalyticsReporting_DimensionFilter();

$dimensionFilter3->setDimensionName('ga:eventLabel');

$dimensionFilter3->setOperator('EXACT');

$dimensionFilter3->setExpressions('My_event_label');

$dimensionFilterClause = new Google_Service_AnalyticsReporting_DimensionFilterClause();

$dimensionFilterClause->setFilters([$dimensionFilter, $dimensionFilter2, $dimensionFilter3]);

$request = new Google_Service_AnalyticsReporting_ReportRequest();

$request->setViewId($VIEW_ID);

$request->setDateRanges($dateRange);

$request->setMetrics(array($totalEvents));

$request->setDimensionFilterClauses([$dimensionFilterClause]);

$body = new Google_Service_AnalyticsReporting_GetReportsRequest();

$body->setReportRequests( array( $request) );

return $analytics->reports->batchGet( $body );

}

But i get strange results.

 $dimensionFilterClause->setFilters([$dimensionFilter]);

As i understand, this is all executions of my event My_event_name. Answer from API, totalEvents: 1737

 $dimensionFilterClause->setFilters([$dimensionFilter, $dimensionFilter2]);

In this case, i want to get all executions of My_event name, dut filtered by ga:eventAction = My_event_action. Answer from API, totalEvents: 1738

Count of filtered events greater then count of all events?

 $dimensionFilterClause->setFilters([$dimensionFilter, $dimensionFilter2, $dimensionFilter3]);

In case of all filters answer is 1737 again.

In this settings i expect to receive number of execution of My_event name, filtered by ga:eventAction = My_event_action, and ga:eventLabel = My_event_label but something is going wrong. It seems that the filters do not work when their count is more than 1.

Maybe I'm doing something wrong?

分享给朋友:
您可能感兴趣的文章:
随机阅读: