Skip to content

Commit 5f0c655

Browse files
authored
Add --conversionDateTime optional parameter to enhanced conversions example (#509)
1 parent 414fc20 commit 5f0c655

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

google-ads-examples/src/main/java/com/google/ads/googleads/examples/remarketing/UploadConversionEnhancement.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.google.ads.googleads.v9.services.ConversionAdjustment;
2828
import com.google.ads.googleads.v9.services.ConversionAdjustmentResult;
2929
import com.google.ads.googleads.v9.services.ConversionAdjustmentUploadServiceClient;
30+
import com.google.ads.googleads.v9.services.GclidDateTimePair;
3031
import com.google.ads.googleads.v9.services.RestatementValue;
3132
import com.google.ads.googleads.v9.services.UploadConversionAdjustmentsRequest;
3233
import com.google.ads.googleads.v9.services.UploadConversionAdjustmentsResponse;
@@ -53,6 +54,16 @@ private static class UploadConversionEnhancementParams extends CodeSampleParams
5354
@Parameter(names = ArgumentNames.ORDER_ID, required = true)
5455
private String orderId;
5556

57+
@Parameter(
58+
names = ArgumentNames.CONVERSION_DATE_TIME,
59+
required = false,
60+
description =
61+
"The date time at which the conversion with the specified order ID occurred. "
62+
+ "Must be after the click time, and must include the time zone offset. "
63+
+ "The format is 'yyyy-mm-dd hh:mm:ss+|-hh:mm', e.g. '2019-01-01 12:32:45-08:00'. "
64+
+ "Setting this field is optional, but recommended.")
65+
private String conversionDateTime;
66+
5667
@Parameter(names = ArgumentNames.USER_AGENT, required = false)
5768
private String userAgent;
5869

@@ -77,7 +88,9 @@ public static void main(String[] args)
7788
params.conversionActionId = Long.parseLong("INSERT_CONVERSION_ACTION_ID_HERE");
7889
params.orderId = "INSERT_ORDER_ID_HERE";
7990

80-
// Optional: Specify the user agent, restatement value and restatement currency code.
91+
// Optional: Specify the conversion date/time, user agent, restatement value, and restatement
92+
// currency code.
93+
params.conversionDateTime = null;
8194
params.userAgent = null;
8295
params.restatementValue = null;
8396
params.currencyCode = null;
@@ -102,6 +115,7 @@ public static void main(String[] args)
102115
params.customerId,
103116
params.conversionActionId,
104117
params.orderId,
118+
params.conversionDateTime,
105119
params.userAgent,
106120
params.restatementValue,
107121
params.currencyCode);
@@ -128,6 +142,7 @@ public static void main(String[] args)
128142
* @param customerId the client customer ID.
129143
* @param conversionActionId conversion action ID associated with this conversion.
130144
* @param orderId unique order ID (transaction ID) of the conversion.
145+
* @param conversionDateTime
131146
* @param userAgent the HTTP user agent of the conversion.
132147
* @param restatementValue the enhancement value.
133148
* @param restatementCurrencyCode the currency of the enhancement value.
@@ -138,6 +153,7 @@ private void runExample(
138153
long customerId,
139154
long conversionActionId,
140155
String orderId,
156+
String conversionDateTime,
141157
String userAgent,
142158
Double restatementValue,
143159
String restatementCurrencyCode)
@@ -151,6 +167,13 @@ private void runExample(
151167
// Enhancements MUST use order ID instead of GCLID date/time pair.
152168
.setOrderId(orderId);
153169

170+
// Sets the conversion date and time if provided. Providing this value is optional but
171+
// recommended.
172+
if (conversionDateTime != null) {
173+
enhancementBuilder.setGclidDateTimePair(
174+
GclidDateTimePair.newBuilder().setConversionDateTime(conversionDateTime));
175+
}
176+
154177
// Creates a SHA256 message digest for hashing user identifiers in a privacy-safe way, as
155178
// described at https://support.google.com/google-ads/answer/9888656.
156179
MessageDigest sha256Digest = MessageDigest.getInstance("SHA-256");

0 commit comments

Comments
 (0)