Browse Source

Customer stats

wfansh 3 months ago
parent
commit
aa0679b21c

+ 5 - 2
src/main/java/com/wechi/adweb/bridge/google/ads/dto/CustomerStatsDTO.java

@@ -10,12 +10,15 @@ import lombok.Data;
 @Builder
 public class CustomerStatsDTO {
 
+    private String customerId;
     private String descriptiveName;
     private String currencyCode;
 
+    private double conversions;
+
+    private long costMicros;
     private long balanceMicros;
-    private long yesterdayCostMicros;
 
     // See https://developers.google.com/google-ads/api/docs/recommendations.
-    private double optimizationScore;
+    private double optiScore;
 }

+ 7 - 5
src/main/java/com/wechi/adweb/bridge/google/ads/service/GoogleAdsService.java

@@ -39,11 +39,11 @@ public class GoogleAdsService {
         try (GoogleAdsServiceClient googleAdsServiceClient =
                 googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) {
 
-            // 1. Queries customer resource fields, yesterday's cost and optimization score.
+            // 1. Queries customer resource fields, conversions, total cost and optimization score.
             String customerQuery =
                     "SELECT customer.descriptive_name, customer.currency_code, customer.optimization_score, "
-                            + "metrics.cost_micros "
-                            + "FROM customer WHERE segments.date DURING YESTERDAY";
+                            + "metrics.conversions, metrics.cost_micros "
+                            + "FROM customer";
             ApiFuture<SearchPagedResponse> customerResponse =
                     googleAdsServiceClient
                             .searchPagedCallable()
@@ -82,13 +82,15 @@ public class GoogleAdsService {
                             .sum();
 
             return CustomerStatsDTO.builder()
+                    .customerId(customerId)
                     .descriptiveName(customerResult.getCustomer().getDescriptiveName())
                     .currencyCode(customerResult.getCustomer().getCurrencyCode())
+                    .conversions(customerResult.getMetrics().getConversions())
+                    .costMicros(customerResult.getMetrics().getCostMicros())
                     // Balance.
                     .balanceMicros(balanceMicros)
-                    .yesterdayCostMicros(customerResult.getMetrics().getCostMicros())
                     // Optimization score.
-                    .optimizationScore(customerResult.getCustomer().getOptimizationScore())
+                    .optiScore(customerResult.getCustomer().getOptimizationScore())
                     .build();
         } catch (InterruptedException | ExecutionException e) {
             log.error(e.getMessage());