20.12.31 GoogleAnalytics API 도입 테스트(feat.Maven)
2020. 12. 31. 17:31ㆍJAVA/Blog 사이트 프로젝트
<testApp.java>
public class testApp {
@JsonIgnoreProperties(ignoreUnknown = true)
public static class TestDataType1 {
public int age;
public String name;
public int height;
}
public void run() {
//testApp();
//testJackson5();
testGoogleCredentials();
testUpdateGoogleAnalyticsApi();
}
private void testUpdateGoogleAnalyticsApi() {
//GoogleAnalytics 버전4의 PropertyId 가져오기
String ga4PropertyId = Container.appConfig.getGa4PropertyId();
try (AlphaAnalyticsDataClient analyticsData = AlphaAnalyticsDataClient.create()) {
RunReportRequest request = RunReportRequest.newBuilder()
.setEntity(Entity.newBuilder().setPropertyId(ga4PropertyId)) //검색(데이터 가져올) 대상
//해설 참고: http://www.goldenplanet.co.kr/blog/2017/01/24/google-analytics-dimension-metric/
//공식 정보: https://developers.google.com/analytics/devguides/reporting/data/v1/api-schema
//Dimension(측정 기준): 웹사이트 방문자들의 특성(속성)
.addDimensions(
Dimension.newBuilder().setName("pagePath")) //pagePath: The web pages visited, listed by URI.
//Metric(측정 항목): Dimension을 측정하는 “숫자”
.addMetrics(Metric.newBuilder().setName("activeUsers")) //activeUsers: The number of distinct users who visited your site or app.
.addDateRanges(
DateRange.newBuilder().setStartDate("2020-10-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();
}
}
private void testGoogleCredentials() {
//환경변수 경로를 가져오기
String variablesPath = System.getenv("GOOGLE_APPLICATION_CREDENTIALS");
System.out.println(variablesPath);
}
'JAVA > Blog 사이트 프로젝트' 카테고리의 다른 글
21.01.06 ajax 통신 연계 통한 블로그 게시물 검색 페이지 생성(+인덱스 게시판 디자인 개편) (0) | 2021.01.06 |
---|---|
21.01.05 템플릿에 검색어 구현 연습 (0) | 2021.01.05 |
20.12.30 Disqus api 적용 - 댓글수, 추천수 동기화 기능 추가( + 이모지 적용)(feat.jackson) (0) | 2020.12.30 |
20.12.27 사이트 메타태그 적용(상세페이지 내용 나오게 하기 등) (0) | 2020.12.27 |
20.12.21 게시판 사이트 프로젝트(사이드바,top버튼 적용, 홈화면 애니메이션 적용, 로고, open graph, favicon 적용 등) (0) | 2020.12.21 |