我正在尝试使用Segment维度过滤器在Java中的Google Analytics Api v4中使用自定义维度。作为模板,我使用以下示例:
https://developers.google.com/analytics/devguides/reporting/core/v4/samples
这适用于所有尺寸,但只要我尝试过滤其中一个自定义尺寸,过滤器似乎就会停止工作。如果Dimension满足过滤条件并不重要,则响应包括所有值。
但奇怪的是,当我在自定义维度中不存在的过滤条件中设置值时,我没有得到任何响应。所以在那一刻,过滤器似乎有效。
谢谢大家的帮助。
// Create the DateRange object.
DateRange dateRange = new DateRange();
dateRange.setStartDate("yesterday");
dateRange.setEndDate("yesterday");
Metric User = new Metric().setExpression("ga:users").setAlias("User");
Dimension prev_page_path = new Dimension().setName("ga:previousPagePath");
Dimension err = new Dimension().setName("ga:dimension14");
Dimension ShopName = new Dimension().setName("ga:dimension1");
// Create the segment dimension.
Dimension segmentDimensions = new Dimension().setName("ga:segment");
// Create Dimension Filter.
SegmentDimensionFilter dimensionFilter = new SegmentDimensionFilter()
.setDimensionName("ga:dimension14")
.setOperator("EXACT")
.setExpressions(Arrays.asList("404"));
// Create Segment Filter Clause.
SegmentFilterClause segmentFilterClause = new SegmentFilterClause()
.setDimensionFilter(dimensionFilter);
// Create the Or Filters for Segment.
OrFiltersForSegment orFiltersForSegment = new OrFiltersForSegment()
.setSegmentFilterClauses(Arrays.asList(segmentFilterClause));
// Create the Simple Segment.
SimpleSegment simpleSegment = new SimpleSegment()
.setOrFiltersForSegment(Arrays.asList(orFiltersForSegment));
// Create the Segment Filters.
SegmentFilter segmentFilter = new SegmentFilter()
.setSimpleSegment(simpleSegment);
// Create the Segment Definition.
SegmentDefinition segmentDefinition = new SegmentDefinition()
.setSegmentFilters(Arrays.asList(segmentFilter));
// Create the Dynamic Segment.
DynamicSegment dynamicSegment = new DynamicSegment()
.setSessionSegment(segmentDefinition)
.setName("404");
// Create the Segments object.
Segment segment = new Segment()
.setDynamicSegment(dynamicSegment);
// Create the ReportRequest object.
ReportRequest request = new ReportRequest()
.setViewId(VIEW_ID)
.setDateRanges(Arrays.asList(dateRange))
.setDimensions(Arrays.asList( prev_page_path, ShopName, err, segmentDimensions))
.setSegments(Arrays.asList(segment))
.setMetrics(Arrays.asList(User));
// Create the GetReportsRequest object.
GetReportsRequest getReport = new GetReportsRequest()
.setReportRequests(Arrays.asList(request));
// Call the batchGet method.
GetReportsResponse response = service.reports().batchGet(getReport).execute();
Anwser看起来像:
ga:previousPagePath: #########
ga:dimension1: #########
ga:dimension14: 404
ga:segment: 404
Date Range (0): User: 1
ga:previousPagePath: #########
ga:dimension1: #########
ga:dimension14: productlist
ga:segment: 404
Date Range (0): User: 1
...
答案 0 :(得分:0)
问题仍然存在,但我找到了一个解决方法,适用于处于相同情况的每个人:
DimensionFilterClause DFC = new DimensionFilterClause().setFilters(Arrays.asList(
new DimensionFilter()
.setDimensionName("ga:dimension14")
.setOperator("EXACT")
.setExpressions(Arrays.asList("404"))));
// Create the ReportRequest object.
ReportRequest request = new ReportRequest()
.setViewId(VIEW_ID)
.setDateRanges(Arrays.asList(dateRange))
.setDimensionFilterClauses(Arrays.asList(DFC))
.setDimensions(Arrays.asList( prev_page_path, ShopName, Seitentyp))
.setMetrics(Arrays.asList(User));