GA Core Reporting API和GA仪表板中的数据差异

时间:2016-08-02 07:36:15

标签: java google-analytics google-analytics-v4 google-analytics-filters

我正在通过java使用Core Reporting API(V4)来提取具有自定义维度的数据。 有两种情景。其中我使用两个维度(pagePath和hostname),而在另一个维度中我只使用一个维度(仅限pagePath)。 问题是我观察到两个请求的差异。在使用一个维度时,数据是我在GA仪表板上看到的内容的精确副本。但是在使用两个维度时,我收到的这些数据不符合DA仪表板。 请参阅以下代码 -

DateRange dateRange = new DateRange();
dateRange.setStartDate("2016-08-01");
dateRange.setEndDate("2016-08-01");
Metric sessions = new Metric().setExpression("gaSmiley Tongueageviews").setAlias("PageViews");
Metric avgtime = new Metric().setExpression("ga:timeOnPage").setAlias("Time On Page");
List<Metric> list = new ArrayList<Metric>();
list.add(sessions);
list.add(avgtime);
Dimension dimension1 = new Dimension().setName("gaSmiley TongueagePath");
Dimension dimension2 = new Dimension().setName("ga:hostname");

List<Dimension> listd = new ArrayList<Dimension>();
listd.add(dimension1);
listd.add(dimension2); //---Error Occurs on Addition of this

List<DimensionFilter> filterList = new ArrayList<DimensionFilter>();
DimensionFilter dimFilter = new DimensionFilter().setDimensionName("gaSmiley TongueagePath").setOperator("REGEXP")
.setExpressions(Arrays.asList("53474130"));
filterList.add(dimFilter);
DimensionFilterClause clause = new DimensionFilterClause().setFilters(filterList);
clause.setFilters(filterList);

List<GetReportsResponse> responseList = new ArrayList<GetReportsResponse>();
String pageToken = "";
while(pageToken != null){
ReportRequest request = new ReportRequest().setViewId(VIEW_ID).setDateRanges(Arrays.asList(dateRange))
.setDimensions(listd).setMetrics(list).setDimensionFilterClauses(Arrays.asList(clause));
System.out.println(request);
if(pageToken != null && !pageToken.isEmpty()){
request.setPageToken(pageToken); }
ArrayList<ReportRequest> requests = new ArrayList<ReportRequest>();
requests.add(request);
GetReportsRequest getReport = new GetReportsRequest().setReportRequests(requests);
GetReportsResponse response = service.reports().batchGet(getReport).execute();
System.out.println(response);
responseList.add(response);
pageToken = response.getReports().get(0).getNextPageToken();
break;
}

我什么时候使用&#34; dimension2&#34;在查询数据中出现(3条记录,其数据与我在仪表板上看到的数据不同) -

{
"dimensions": ["m.photos.timesofindia.com/celebs/celeb-themes/celebs-at-airport/articleshow/53474130.cms",
"m.photos.timesofindia.com"],
"metrics": [{
"values": ["12",
"19.0"]
}]
}{
"dimensions": ["m.photos.timesofindia.com/celebs/celeb-themes/celebs/celeb-themes/celebs-at-airport/articleshow/53474130.cms",
"m.photos.timesofindia.com"],
"metrics": [{
"values": ["231",
"698.0"]
}]
}{
"dimensions": ["photogallery.indiatimes.com/celebs/celeb-themes/celebs-at-airport/articleshow/53474130.cms",
"photogallery.indiatimes.com"],
"metrics": [{
"values": ["168",
"648.0"]
}]
}

但是当我重新运行我的代码时没有&#34;主机名&#34;维度,我看到的数据符合仪表板上可见的内容。在这种情况下的回应是 -

{
    "dimensions": ["m.photos.timesofindia.com/celebs/celeb-themes/celebs/celeb-themes/celebs-at-airport/articleshow/53474130.cms"],
    "metrics": [{
        "values": ["217",
        "746.0"]
    }]
}{
    "dimensions": ["photogallery.indiatimes.com/celebs/celeb-themes/celebs-at-airport/articleshow/53474130.cms"],
    "metrics": [{
        "values": ["181",
        "2031.0"]
    }]
}

目前使用的Core Reporting API版本是V4。 我也尝试过采样。但是回应没有区别。 一旦我添加&#34;主机名&#34;我看到了数据的差异。尺寸。 请帮帮我。

温暖的问候,

Vibhav

0 个答案:

没有答案