Skip to content

Commit 9690bcc

Browse files
committed
Address Josh comments
Change-Id: I8a8381d9efe98d420ce74bcff47339bd132a1fdf
1 parent 0decc98 commit 9690bcc

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

google-ads-examples/src/main/java/com/google/ads/googleads/examples/planning/GenerateHistoricalMetrics.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2019 Google LLC
1+
// Copyright 2022 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828
import com.google.protobuf.ProtocolStringList;
2929
import java.io.FileNotFoundException;
3030
import java.io.IOException;
31+
import java.util.List;
3132

3233
/**
3334
* Generates historical metrics for a keyword plan. To create a keyword plan, run the {@link
@@ -108,7 +109,7 @@ private void runExample(GoogleAdsClient googleAdsClient, Long customerId, Long p
108109
// These metrics include those for both the search query and any close variants included in
109110
// the response.
110111

111-
ProtocolStringList variants = metric.getCloseVariantsList();
112+
List<String> variants = metric.getCloseVariantsList();
112113
String variantsList =
113114
(variants.isEmpty())
114115
? ""
@@ -131,18 +132,24 @@ private void runExample(GoogleAdsClient googleAdsClient, Long customerId, Long p
131132
// placement is for a keyword. The level of competition from 0-100 is determined by the
132133
// number of ad slots filled divided by the total number of ad slots available. If not
133134
// enough data is available, None will be returned.
134-
System.out.printf(
135-
"\tCompetition index: %d.%n", metric.getKeywordMetrics().getCompetitionIndex());
135+
if (metric.getKeywordMetrics().hasCompetitionIndex()) {
136+
System.out.printf(
137+
"\tCompetition index: %d.%n", metric.getKeywordMetrics().getCompetitionIndex());
138+
}
136139

137140
// Top of page bid low range (20th percentile) in micros for the keyword.
138-
System.out.printf(
139-
"\tTop of page bid low range %d.%n",
140-
metric.getKeywordMetrics().getLowTopOfPageBidMicros());
141+
if (metric.getKeywordMetrics().hasLowTopOfPageBidMicros()) {
142+
System.out.printf(
143+
"\tTop of page bid low range %d.%n",
144+
metric.getKeywordMetrics().getLowTopOfPageBidMicros());
145+
}
141146

142147
// Top of page bid high range (80th percentile) in micros for the keyword.
143-
System.out.printf(
144-
"\tTop of page bid high range %d.%n",
145-
metric.getKeywordMetrics().getHighTopOfPageBidMicros());
148+
if (metric.getKeywordMetrics().hasHighTopOfPageBidMicros()) {
149+
System.out.printf(
150+
"\tTop of page bid high range %d.%n",
151+
metric.getKeywordMetrics().getHighTopOfPageBidMicros());
152+
}
146153

147154
// Approximate number of searches on this query for the past twelve months.
148155
for (MonthlySearchVolume month : metric.getKeywordMetrics().getMonthlySearchVolumesList()) {

0 commit comments

Comments
 (0)