首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用java读取google analytics 4中的标记及其相关触发器名称/值

如何使用java读取google analytics 4中的标记及其相关触发器名称/值
EN

Stack Overflow用户
提问于 2022-09-27 08:12:46
回答 1查看 16关注 0票数 0

我使用GA4教程Google Analytics 4进行API调用,该链接中提供的代码是根据定义的维度和Google Tag Manager中的metrics.Suppose列出我的数据,我已经创建了一个标记和类似于这张照片中的相对触发器:

例如,如果用户单击菜单栏,而Click URL包含特定的URL,则会触发标记。当然,可以从谷歌标签助理中看到这些信息。

现在我想知道是否也可以使用JAVA列出这些标记和触发器?提前谢谢你

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-27 10:53:17

最后我找到了怎么做。作为我创建的标记和触发器的示例:

代码语言:javascript
运行
复制
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import com.google.analytics.data.v1beta.BetaAnalyticsDataClient;
import com.google.analytics.data.v1beta.BetaAnalyticsDataSettings;
import com.google.analytics.data.v1beta.DateRange;
import com.google.analytics.data.v1beta.Dimension;
import com.google.analytics.data.v1beta.RunReportRequest;
import com.google.analytics.data.v1beta.RunReportResponse;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;

import io.grpc.LoadBalancerRegistry;
import io.grpc.grpclb.GrpclbLoadBalancerProvider;

public class Ga4DataAnalytics2 {

    static {
        LoadBalancerRegistry.getDefaultRegistry().register( new GrpclbLoadBalancerProvider());
    }
    public static void main(String[] args) throws IOException {

    String credentialsJsonPath="path to credential.json";
    String propertyId = "your property ID";
    Files.createDirectories(Paths.get(credentialsJsonPath).getParent());

    GoogleCredentials credentials =
            GoogleCredentials.fromStream(new FileInputStream(credentialsJsonPath));

    BetaAnalyticsDataSettings betaAnalyticsDataSettings =
            BetaAnalyticsDataSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credentials))
            .build();    

    try (BetaAnalyticsDataClient analyticsData =
            BetaAnalyticsDataClient.create(betaAnalyticsDataSettings)) {
        RunReportRequest request =
                RunReportRequest.newBuilder()
                .setProperty("properties/" + propertyId)
                .addDimensions(Dimension.newBuilder().setName("linkUrl"))
                .addDimensions(Dimension.newBuilder().setName("linkText"))          
                .addDateRanges(DateRange.newBuilder().setStartDate("2022-09-25").setEndDate("2022-09-26"))
                .build();
        RunReportResponse response = analyticsData.runReport(request);
        System.out.println("Report result:\n"+response);
     
    }

}

}

以及为什么我使用linkUrllinkText作为维度,这是因为我的标记配置是:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73864343

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档