Search in sources :

Example 1 with OfflineConversionAdjustmentType

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());
    }
}
Also used : OfflineConversionAdjustmentFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeedServiceInterface) OfflineConversionAdjustmentFeedOperation(com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeedOperation) OfflineConversionAdjustmentFeedReturnValue(com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeedReturnValue) GclidOfflineConversionAdjustmentFeed(com.google.api.ads.adwords.axis.v201809.cm.GclidOfflineConversionAdjustmentFeed) OfflineConversionAdjustmentFeed(com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeed) GclidOfflineConversionAdjustmentFeed(com.google.api.ads.adwords.axis.v201809.cm.GclidOfflineConversionAdjustmentFeed)

Example 2 with OfflineConversionAdjustmentType

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);
    }
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) OfflineConversionAdjustmentType(com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentType) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) AdWordsServicesInterface(com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface) ApiError(com.google.api.ads.adwords.axis.v201809.cm.ApiError) RemoteException(java.rmi.RemoteException) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException)

Aggregations

ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)1 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)1 GclidOfflineConversionAdjustmentFeed (com.google.api.ads.adwords.axis.v201809.cm.GclidOfflineConversionAdjustmentFeed)1 OfflineConversionAdjustmentFeed (com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeed)1 OfflineConversionAdjustmentFeedOperation (com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeedOperation)1 OfflineConversionAdjustmentFeedReturnValue (com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeedReturnValue)1 OfflineConversionAdjustmentFeedServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentFeedServiceInterface)1 OfflineConversionAdjustmentType (com.google.api.ads.adwords.axis.v201809.cm.OfflineConversionAdjustmentType)1 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)1 AdWordsServicesInterface (com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface)1 ConfigurationLoadException (com.google.api.ads.common.lib.conf.ConfigurationLoadException)1 OAuthException (com.google.api.ads.common.lib.exception.OAuthException)1 ValidationException (com.google.api.ads.common.lib.exception.ValidationException)1 Credential (com.google.api.client.auth.oauth2.Credential)1 RemoteException (java.rmi.RemoteException)1