Browse Source

Data report

wfansh 5 months ago
parent
commit
db0ab3b5a6
11 changed files with 302 additions and 2 deletions
  1. 35 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/GAReportRequestDTO.java
  2. 9 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/OrderByType.java
  3. 23 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/ReportConstant.java
  4. 80 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/ReportType.java
  5. 15 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/data/CountryChartData.java
  6. 34 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/data/CustomReportData.java
  7. 31 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/data/DateViewData.java
  8. 6 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/data/GAReportDataDTO.java
  9. 22 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/data/PagePathViewData.java
  10. 28 0
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/data/SourceMediaViewData.java
  11. 19 2
      jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/service/google/GAReportService.java

+ 35 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/GAReportRequestDTO.java

@@ -0,0 +1,35 @@
+package org.jeecg.modules.adweb.dmp.dto.google.analytics.report;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author wfansh
+ */
+@Data
+public class GAReportRequestDTO {
+
+    private String propertyResourceName;
+
+    private ReportType reportType;
+
+    private String startDate;
+
+    private String endDate;
+
+    /** Use default values in {@link ReportType} instead. */
+    @Deprecated private List<String> metrics;
+
+    /** Use default values in {@link ReportType} instead. */
+    @Deprecated private List<String> dimensions;
+
+    /** Use default values in {@link ReportType} instead. */
+    @Deprecated private String orderBy;
+
+    /** Use default values in {@link ReportType} instead. */
+    @Deprecated private OrderByType orderByType;
+
+    /** Use default values in {@link ReportType} instead. */
+    @Deprecated private Boolean orderByDesc;
+}

+ 9 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/OrderByType.java

@@ -0,0 +1,9 @@
+package org.jeecg.modules.adweb.dmp.dto.google.analytics.report;
+
+/**
+ * @author wfansh
+ */
+public enum OrderByType {
+    METRICS,
+    DIMENSIONS
+}

+ 23 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/ReportConstant.java

@@ -0,0 +1,23 @@
+package org.jeecg.modules.adweb.dmp.dto.google.analytics.report;
+
+/**
+ * @author wfansh
+ */
+public class ReportConstant {
+
+    public static final String METRIC_TOTAL_USERS = "totalUsers";
+    public static final String METRIC_NEW_USERS = "newUsers";
+    public static final String METRIC_ACTIVE_USERS = "activeUsers";
+    public static final String METRIC_SESSIONS = "sessions";
+    public static final String METRIC_AVG_SESSION_DURATION = "averageSessionDuration";
+    public static final String METRIC_SCREEN_PAGE_VIEWS = "screenPageViews";
+    public static final String METRIC_SCREEN_PAGE_VIEWS_PER_SESSION = "screenPageViewsPerSession";
+    public static final String METRIC_BOUNCE_RATE = "bounceRate";
+    public static final String METRIC_ENGAGEMENT_RATE = "engagementRate";
+    public static final String METRIC_USER_ENGAGEMENT_DURATION = "userEngagementDuration";
+
+    public static final String DIMENSION_COUNTRY = "country";
+    public static final String DIMENSION_SESSION_SOURCE_MEDIUM = "sessionSourceMedium";
+    public static final String DIMENSION_PAGE_PATH = "pagePath";
+    public static final String DIMENSION_DATE = "date";
+}

+ 80 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/ReportType.java

@@ -0,0 +1,80 @@
+package org.jeecg.modules.adweb.dmp.dto.google.analytics.report;
+
+import static org.jeecg.modules.adweb.dmp.dto.google.analytics.report.OrderByType.*;
+import static org.jeecg.modules.adweb.dmp.dto.google.analytics.report.ReportConstant.*;
+
+import lombok.Getter;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author wfansh
+ */
+@Getter
+public enum ReportType {
+    // V2 - adweb:country:chart
+    ADWEB_COUNTRY_CHART(List.of(METRIC_TOTAL_USERS), List.of(DIMENSION_COUNTRY)),
+    // v2 - adweb:sourceMedium:list
+    ADWEB_SESSION_SOURCE_MEDIUM_VIEW(
+            List.of(
+                    METRIC_TOTAL_USERS,
+                    METRIC_NEW_USERS,
+                    METRIC_SESSIONS,
+                    METRIC_BOUNCE_RATE,
+                    METRIC_AVG_SESSION_DURATION,
+                    METRIC_SCREEN_PAGE_VIEWS_PER_SESSION),
+            List.of(DIMENSION_SESSION_SOURCE_MEDIUM)),
+    // V2 - adweb:pagePath:list
+    ADWEB_PAGE_PATH_VIEW(
+            List.of(
+                    METRIC_ENGAGEMENT_RATE,
+                    METRIC_SCREEN_PAGE_VIEWS,
+                    METRIC_USER_ENGAGEMENT_DURATION),
+            List.of(DIMENSION_PAGE_PATH),
+            METRIC_SCREEN_PAGE_VIEWS,
+            METRICS,
+            true),
+    // V2 - adwebV2:customer:api, pageviews, uniqueuser, bounce, AvgSessionDuration,
+    // adweb:active:user
+    ADWEB_DATE_VIEW(
+            List.of(
+                    METRIC_TOTAL_USERS,
+                    METRIC_ACTIVE_USERS,
+                    METRIC_SCREEN_PAGE_VIEWS,
+                    METRIC_BOUNCE_RATE,
+                    METRIC_AVG_SESSION_DURATION),
+            List.of(DIMENSION_DATE),
+            DIMENSION_DATE,
+            DIMENSIONS,
+            false),
+    // For flexible query.
+    ADWEB_CUSTOM_REPORT(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
+
+    ReportType(List<String> defaultMetrics, List<String> defaultDimensions) {
+        this.defaultMetrics = defaultMetrics;
+        this.defaultDimensions = defaultDimensions;
+        this.defaultOrderBy = null;
+        this.defaultOrderByType = null;
+        this.defaultOrderByDesc = false;
+    }
+
+    ReportType(
+            List<String> defaultMetrics,
+            List<String> defaultDimensions,
+            String defaultOrderBy,
+            OrderByType defaultOrderByType,
+            boolean defaultOrderByDesc) {
+        this.defaultMetrics = defaultMetrics;
+        this.defaultDimensions = defaultDimensions;
+        this.defaultOrderBy = defaultOrderBy;
+        this.defaultOrderByType = defaultOrderByType;
+        this.defaultOrderByDesc = defaultOrderByDesc;
+    }
+
+    private final List<String> defaultMetrics;
+    private final List<String> defaultDimensions;
+    private final String defaultOrderBy;
+    private final OrderByType defaultOrderByType;
+    private final Boolean defaultOrderByDesc;
+}

+ 15 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/data/CountryChartData.java

@@ -0,0 +1,15 @@
+package org.jeecg.modules.adweb.dmp.dto.google.analytics.report.data;
+
+import lombok.Builder;
+import lombok.Data;
+
+/**
+ * @author wfansh
+ */
+@Data
+@Builder
+public class CountryChartData implements GAReportDataDTO {
+
+    private String country;
+    private int totalUsers;
+}

+ 34 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/data/CustomReportData.java

@@ -0,0 +1,34 @@
+package org.jeecg.modules.adweb.dmp.dto.google.analytics.report.data;
+
+import org.jeecg.modules.adweb.dmp.dto.google.analytics.report.ReportType;
+
+import java.util.*;
+
+/**
+ * Represents a flexible GA report for {@link ReportType#ADWEB_CUSTOM_REPORT}, structured as a
+ * {@link Map} collection.
+ *
+ * <p>This {@link Map} contains two types of key-value pairs:
+ *
+ * <ul>
+ *   <li><strong>Dimensions:</strong>
+ *       <ul>
+ *         <li><strong>Key:</strong> the name of the dimension.
+ *         <li><strong>Value:</strong> the value of the dimension.
+ *       </ul>
+ *   <li><strong>Metrics:</strong>
+ *       <ul>
+ *         <li><strong>Key:</strong> the name of the metric.
+ *         <li><strong>Value:</strong> the value of the metric.
+ *       </ul>
+ * </ul>
+ *
+ * <p>This structure allows for flexible representation of both dimensions and metrics in custom GA
+ * reports.
+ *
+ * @author wfansh
+ */
+public class CustomReportData extends LinkedHashMap<String, String> implements GAReportDataDTO {
+
+    private CustomReportData() {}
+}

+ 31 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/data/DateViewData.java

@@ -0,0 +1,31 @@
+package org.jeecg.modules.adweb.dmp.dto.google.analytics.report.data;
+
+import lombok.Builder;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.format.DateTimeFormatter;
+
+/**
+ * @author wfansh
+ */
+@Data
+@Builder
+public class DateViewData implements GAReportDataDTO {
+
+    /**
+     * Formatted as {@link DateTimeFormatter#ISO_LOCAL_DATE}, originated from {@link
+     * DateTimeFormatter#BASIC_ISO_DATE}
+     */
+    private String date;
+
+    private int totalUsers;
+
+    private int activeUsers;
+
+    private int pageViews;
+
+    private BigDecimal bounceRate;
+
+    private BigDecimal avgSessionDuration;
+}

+ 6 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/data/GAReportDataDTO.java

@@ -0,0 +1,6 @@
+package org.jeecg.modules.adweb.dmp.dto.google.analytics.report.data;
+
+/**
+ * @author wfansh
+ */
+public interface GAReportDataDTO {}

+ 22 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/data/PagePathViewData.java

@@ -0,0 +1,22 @@
+package org.jeecg.modules.adweb.dmp.dto.google.analytics.report.data;
+
+import lombok.Builder;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * @author wfansh
+ */
+@Data
+@Builder
+public class PagePathViewData implements GAReportDataDTO {
+
+    private String pagePath;
+
+    private BigDecimal engagementRate;
+
+    private int pageViews;
+
+    private BigDecimal avgTimeOnPage;
+}

+ 28 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/dto/google/analytics/report/data/SourceMediaViewData.java

@@ -0,0 +1,28 @@
+package org.jeecg.modules.adweb.dmp.dto.google.analytics.report.data;
+
+import lombok.Builder;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * @author wfansh
+ */
+@Data
+@Builder
+public class SourceMediaViewData implements GAReportDataDTO {
+
+    private String type;
+
+    private int totalUsers;
+
+    private int newUsers;
+
+    private int sessions;
+
+    private BigDecimal bounceRate;
+
+    private BigDecimal avgSessionDuration;
+
+    private BigDecimal pageViewsPerSession;
+}

+ 19 - 2
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/adweb/dmp/service/google/GAReportService.java

@@ -5,6 +5,7 @@ import jakarta.annotation.PostConstruct;
 import lombok.extern.slf4j.Slf4j;
 
 import org.jeecg.modules.adweb.common.util.RestTemplateUtil;
+import org.jeecg.modules.adweb.dmp.entity.GoogleGTM;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
@@ -18,16 +19,32 @@ import org.springframework.web.client.RestTemplate;
 @Service
 public class GAReportService {
 
+    private static final String DATA_BRIDGE_GA_REPORT_PATH = "/api/google/ga/report";
+
+    private RestTemplate restTemplate;
+
     @Value("${data-bridge.api.host}")
     private String dataBridgeApiHost;
 
     @Value("${data-bridge.api.token}")
     private String dataBridgeApiToken;
 
-    private RestTemplate restTemplate;
-
     @PostConstruct
     private void init() {
         this.restTemplate = RestTemplateUtil.getRestTemplate(30, 30, dataBridgeApiToken);
     }
+
+//    /**
+//     * 拉取Google Analytics国家报表
+//     *
+//     * @param googleGTM
+//     */
+//    private void queryGARegionReport(GoogleGTM googleGTM) {}
+//
+
+
+    private void runGAReport(GARe) {
+
+    }
+
 }