use of com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentType in project googleads-java-lib by googleads.
the class UploadConversionAdjustment method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param conversionName the name of the conversion tracker.
* @param gclId the GCLID for the conversion.
* @param adjustmentType the type of adjustment.
* @param adjustmentTime the date and time of the adjustment.
* @param conversionTime the date and time of the conversion.
* @param adjustedValue the adjusted value.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, String conversionName, String gclId, OfflineConversionAdjustmentType adjustmentType, String conversionTime, String adjustmentTime, @Nullable Double adjustedValue) throws RemoteException {
// Get the OfflineConversionAdjustmentFeedService.
OfflineConversionAdjustmentFeedServiceInterface offlineConversionFeedService = adWordsServices.get(session, OfflineConversionAdjustmentFeedServiceInterface.class);
// Associate conversion adjustments with the existing named conversion tracker. The GCLID should
// have been uploaded before with a conversion.
GclidOfflineConversionAdjustmentFeed feed = new GclidOfflineConversionAdjustmentFeed();
feed.setConversionName(conversionName);
feed.setAdjustmentType(adjustmentType);
feed.setConversionTime(conversionTime);
feed.setAdjustmentTime(adjustmentTime);
feed.setAdjustedValue(adjustedValue);
feed.setGoogleClickId(gclId);
OfflineConversionAdjustmentFeedOperation offlineConversionOperation = new OfflineConversionAdjustmentFeedOperation();
offlineConversionOperation.setOperator(Operator.ADD);
offlineConversionOperation.setOperand(feed);
OfflineConversionAdjustmentFeedReturnValue offlineConversionReturnValue = offlineConversionFeedService.mutate(new OfflineConversionAdjustmentFeedOperation[] { offlineConversionOperation });
for (OfflineConversionAdjustmentFeed newFeed : offlineConversionReturnValue.getValue()) {
System.out.printf("Uploaded conversion adjusted value of %.4f for Google Click ID '%s'.%n", newFeed.getAdjustedValue(), ((GclidOfflineConversionAdjustmentFeed) newFeed).getGoogleClickId());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentType in project googleads-java-lib by googleads.
the class UploadConversionAdjustment method main.
public static void main(String[] args) {
AdWordsSession session;
try {
// Generate a refreshable OAuth2 credential.
Credential oAuth2Credential = new OfflineCredentials.Builder().forApi(Api.ADWORDS).fromFile().build().generateCredential();
// Construct an AdWordsSession.
session = new AdWordsSession.Builder().fromFile().withOAuth2Credential(oAuth2Credential).build();
} catch (ConfigurationLoadException cle) {
System.err.printf("Failed to load configuration from the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, cle);
return;
} catch (ValidationException ve) {
System.err.printf("Invalid configuration in the %s file. Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, ve);
return;
} catch (OAuthException oe) {
System.err.printf("Failed to create OAuth credentials. Check OAuth settings in the %s file. " + "Exception: %s%n", DEFAULT_CONFIGURATION_FILENAME, oe);
return;
}
AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
UploadOfflineConversionsParams params = new UploadOfflineConversionsParams();
if (!params.parseArguments(args)) {
// Either pass the required parameters for this example on the command line, or insert them
// into the code here. See the parameter class definition above for descriptions.
params.conversionName = "INSERT_CONVERSION_NAME_HERE";
params.gclId = "INSERT_GCL_ID_HERE";
params.adjustmentType = "INSERT_ADJUSTMENT_TYPE_HERE";
params.conversionTime = "INSERT_CONVERSION_TIME_HERE";
params.adjustmentTime = "INSERT_ADJUSTMENT_TIME_HERE";
// Optional: Adjusted value for adjustment type RESTATE.
params.adjustedValue = Double.parseDouble("INSERT_ADJUSTED_VALUE_HERE");
}
OfflineConversionAdjustmentType adjustmentTypeEnum = OfflineConversionAdjustmentType.fromString(params.adjustmentType);
try {
runExample(adWordsServices, session, params.conversionName, params.gclId, adjustmentTypeEnum, params.conversionTime, params.adjustmentTime, params.adjustedValue);
} catch (ApiException apiException) {
// ApiException is the base class for most exceptions thrown by an API request. Instances
// of this exception have a message and a collection of ApiErrors that indicate the
// type and underlying cause of the exception. Every exception object in the adwords.axis
// packages will return a meaningful value from toString
//
// ApiException extends RemoteException, so this catch block must appear before the
// catch block for RemoteException.
System.err.println("Request failed due to ApiException. Underlying ApiErrors:");
if (apiException.getErrors() != null) {
int i = 0;
for (ApiError apiError : apiException.getErrors()) {
System.err.printf(" Error %d: %s%n", i++, apiError);
}
}
} catch (RemoteException re) {
System.err.printf("Request failed unexpectedly due to RemoteException: %s%n", re);
}
}
Aggregations