|
@@ -9,6 +9,7 @@ import com.google.api.core.ApiFuture;
|
|
|
import com.wechi.adweb.bridge.exception.DataException;
|
|
|
import com.wechi.adweb.bridge.google.ads.common.CountryCode;
|
|
|
import com.wechi.adweb.bridge.google.ads.common.PlacementUtils;
|
|
|
+import com.wechi.adweb.bridge.google.ads.dto.CampaignStatsDTO;
|
|
|
import com.wechi.adweb.bridge.google.ads.dto.CustomerStatsDTO;
|
|
|
import com.wechi.adweb.bridge.google.ads.dto.MetricsDTO;
|
|
|
import com.wechi.adweb.bridge.google.ads.dto.ReportRequestDTO;
|
|
@@ -20,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -128,6 +130,34 @@ public class GoogleAdsService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public List<CampaignStatsDTO> getCampaignStats(ReportRequestDTO reportRequest)
|
|
|
+ throws DataException {
|
|
|
+ try (GoogleAdsServiceClient googleAdsServiceClient =
|
|
|
+ googleAdsClient.getLatestVersion().createGoogleAdsServiceClient()) {
|
|
|
+ String query =
|
|
|
+ String.format(
|
|
|
+ "SELECT campaign.name, campaign.status, campaign.primary_status, campaign.bidding_strategy_type, "
|
|
|
+ + "campaign.advertising_channel_type, campaign.advertising_channel_sub_type, campaign_budget.amount_micros, "
|
|
|
+ + "metrics.impressions, metrics.clicks, metrics.ctr, metrics.average_cpc, "
|
|
|
+ + "metrics.average_cpm, metrics.conversions, metrics.cost_micros "
|
|
|
+ + "FROM campaign "
|
|
|
+ + "WHERE campaign.status != 'REMOVED' AND %s "
|
|
|
+ + "ORDER BY metrics.impressions DESC, metrics.clicks DESC LIMIT %d",
|
|
|
+ reportRequest.toDateClause(), reportRequest.getLimit());
|
|
|
+
|
|
|
+ SearchGoogleAdsRequest request =
|
|
|
+ SearchGoogleAdsRequest.newBuilder()
|
|
|
+ .setCustomerId(reportRequest.getCustomerId())
|
|
|
+ .setQuery(query)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ SearchPagedResponse response = googleAdsServiceClient.search(request);
|
|
|
+ return StreamSupport.stream(response.iterateAll().spliterator(), false)
|
|
|
+ .map(CampaignStatsDTO::fromGoogleAdsRow)
|
|
|
+ .toList();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public Map<String, MetricsDTO> getKeywordStats(ReportRequestDTO reportRequest)
|
|
|
throws DataException {
|
|
|
try (GoogleAdsServiceClient googleAdsServiceClient =
|