简体   繁体   English

如何在 java 中使用 Google Analytics Data API (GA4) 以获取 screenPageViews 计数时扩展获取值?

[英]how to extend the get values while using Google Analytics Data API (GA4) in java to get count of screenPageViews?

I appreciate your attention to my ask.感谢您对我的提问的关注。 When I use the below java code to get information from google analytics, it shows just 10 values of pages... Actually, the total page on my website is 37 pages and I would like to get total values from ga4.当我使用下面的 java 代码从谷歌分析获取信息时,它只显示 10 个页面值...实际上,我网站上的总页面是 37 页,我想从 ga4 获取总值。 I just started study programming 2 months ago.我刚开始学习编程 2 个月前。 Please help me to solve it.请帮我解决它。

    private void testUpdateGoogleAnalyticsApi() {
        String ga4PropertyId = Container.config.getGa4PropertyId();
        try (AlphaAnalyticsDataClient analyticsData = AlphaAnalyticsDataClient.create()) {
            RunReportRequest request = RunReportRequest.newBuilder()
                    .setEntity(Entity.newBuilder().setPropertyId(ga4PropertyId))
                    .addDimensions(Dimension.newBuilder().setName("pagePath"))
                    .addMetrics(Metric.newBuilder().setName("screenPageViews"))
                    .addDateRanges(DateRange.newBuilder().setStartDate("2020-12-01").setEndDate("today")).build();

            // Make the request
            RunReportResponse response = analyticsData.runReport(request);
            
            System.out.println("Report result:");
            for (Row row : response.getRowsList()) {
                System.out.printf("%s, %s%n", row.getDimensionValues(0).getValue(), row.getMetricValues(0).getValue());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

在此处输入图像描述

If the limit parameter in the RunReportRequest is unspecified, the RunReportResponse will contain only 10 rows.如果未指定 RunReportRequest 中的 limit 参数,则 RunReportResponse 将仅包含 10 行。 For this report, this means you will only see 10 pages paths in the API's report even though a larger number of pages (37) exist for your website.对于此报告,这意味着即使您的网站存在大量页面 (37),您也只会在 API 报告中看到 10 个页面路径。

The solution is to use the "setLimit" method on RunReportRequest's Builder.解决方案是在 RunReportRequest 的 Builder 上使用“setLimit”方法。 For example, please update the request's builder to the following to return up to 10,000 rows.例如,请将请求的构建器更新为以下内容以返回最多 10,000 行。

RunReportRequest request = RunReportRequest.newBuilder()
 .setEntity(Entity.newBuilder().setPropertyId(ga4PropertyId))
 .addDimensions(Dimension.newBuilder().setName("pagePath"))
 .addMetrics(Metric.newBuilder().setName("screenPageViews"))
 .addDateRanges(DateRange.newBuilder().setStartDate("2020-12-01").setEndDate("today"))
 .setLimit(10000L).build();

There is documentation on this API's pagination mechanism here .这里有关于这个 API 的分页机制的文档。 Pagination specifies how many rows you would like to see in the response.分页指定您希望在响应中看到多少行。 In this case, the number of pages from your website.在这种情况下,来自您网站的页面数。

The setLimit method controls the number of rows in the report response and is documented on github here . setLimit 方法控制报告响应中的行数,并记录在github上。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Google Data Analytics API (ga4) 获取分析报告的 java 程序(jdk 1.8)的 maven 依赖项是什么? - What are maven dependencies for a java program (jdk 1.8) which uses Google Data Analytics API (ga4) to get analytics report? (GA4) 的 Google Analytics 数据 api 的数据处理延迟是多少? - What is the data processing latency for the Google Analytics data api for (GA4)? 如何使用Java获取Google Analytics(分析)数据? - How to get google analytics data using java? 如何在Google Analytics Export API上关联ga:campaign和ga:pagePath(内容)? - How to relate ga:campaign and ga:pagePath (content) on Google Analytics Export API? 如何在未经身份验证的情况下使用Google Spreadsheet API Java库获取公开的Google电子表格数据 - How to get public Google Spreadsheet data using Google Spreadsheet API Java library without authentication Google Analytics Report API v4:获取会话和收入数据 - Google Analytics Report API v4: get Sessions and Revenue data 使用JAVA将Google Analytics(分析)API中的数据导出为CSV文件格式 - Exporting data in google analytics api to CSV file format using JAVA 如何使用 Google API 通过 Java 获取 Google 日历 ID - How to get the Google Calendar ID using Google API by Java 如何获取访问令牌以获取谷歌分析数据? - How can I get the access token to get google analytics Data? 如何使用 JAVA 库在 Google API 上获取用户配置文件? - How to get user profile on Google API using the JAVA library?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM