Search in sources :

Example 36 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.

the class ProductPartitionNodeAdapter method createCriterionForAdd.

/**
 * Returns a new AdGroupCriterion configured for an ADD operation.
 *
 * @param node the node whose criterion should be added
 * @param adGroupId the ad group ID of the criterion
 * @param biddingConfig the bidding strategy configuration of the criterion
 */
static AdGroupCriterion createCriterionForAdd(ProductPartitionNode node, long adGroupId, BiddingStrategyConfiguration biddingConfig) {
    Preconditions.checkNotNull(node, "Null node");
    Preconditions.checkNotNull(biddingConfig, "Null bidding configuration");
    AdGroupCriterion adGroupCriterion;
    if (node.isExcludedUnit()) {
        adGroupCriterion = new NegativeAdGroupCriterion();
    } else if (node.isBiddableUnit()) {
        BiddableAdGroupCriterion biddableCriterion = new BiddableAdGroupCriterion();
        if (node.getBid() != null) {
            Money bidMoney = new Money();
            bidMoney.setMicroAmount(node.getBid());
            CpcBid cpcBid = new CpcBid();
            cpcBid.setBid(bidMoney);
            cpcBid.setCpcBidSource(BidSource.CRITERION);
            biddingConfig.setBids(new Bids[] { cpcBid });
            biddableCriterion.setBiddingStrategyConfiguration(biddingConfig);
        }
        if (node.getTrackingUrlTemplate() != null) {
            biddableCriterion.setTrackingUrlTemplate(node.getTrackingUrlTemplate());
        }
        biddableCriterion.setUrlCustomParameters(createCustomParameters(node));
        adGroupCriterion = biddableCriterion;
    } else {
        adGroupCriterion = new BiddableAdGroupCriterion();
    }
    adGroupCriterion.setAdGroupId(adGroupId);
    ProductPartition partition = new ProductPartition();
    partition.setId(node.getProductPartitionId());
    if (node.getParent() != null) {
        partition.setParentCriterionId(node.getParent().getProductPartitionId());
    }
    partition.setCaseValue(node.getDimension());
    partition.setPartitionType(node.isUnit() ? ProductPartitionType.UNIT : ProductPartitionType.SUBDIVISION);
    adGroupCriterion.setCriterion(partition);
    return adGroupCriterion;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) Bids(com.google.api.ads.adwords.axis.v201809.cm.Bids) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)

Example 37 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.

the class ProductPartitionTreeImpl method createRemoveOperation.

/**
 * Returns a REMOVE operation for the specified node.
 */
private OperationPair createRemoveOperation(ProductPartitionNode node) {
    Preconditions.checkNotNull(node.getProductPartitionId(), "Node for REMOVE operation has no partition ID: %s", node);
    Preconditions.checkArgument(node.getProductPartitionId().longValue() >= 0L, "Node for REMOVE operation has a negative partition ID: %s", node);
    AdGroupCriterionOperation removeOp = new AdGroupCriterionOperation();
    removeOp.setOperator(Operator.REMOVE);
    removeOp.setOperand(ProductPartitionNodeAdapter.createCriterionForRemove(node, adGroupId));
    return new OperationPair(node, removeOp);
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)

Example 38 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.

the class ProductPartitionTreeImpl method addMutateOperations.

/**
 * Adds to the operations list all operations required to mutate {@code originalNode} to the state
 * of {@code newNode}.
 *
 * <p>The returned set of child product dimensions will only <em>potentially</em> be non-empty if
 * both {@code originalNode != null} and {@code newNode != null}.
 *
 * @param originalNode may be null
 * @param newNode may be null
 * @param ops the operations list to add to
 *
 * @return the set of child product dimensions that require further processing
 */
private Set<ProductDimension> addMutateOperations(@Nullable ProductPartitionNode originalNode, @Nullable ProductPartitionNode newNode, List<OperationPair> ops) {
    Set<ProductDimension> childDimensionsToProcess = Sets.newTreeSet(dimensionComparator);
    NodeDifference nodeDifference = ProductPartitionNodeDiffer.diff(originalNode, newNode, dimensionComparator);
    boolean isProcessChildren;
    switch(nodeDifference) {
        case NEW_NODE:
            ops.addAll(createAddOperations(newNode));
            // No need to further process children. The ADD operations above will include operations
            // for all children of newNode.
            isProcessChildren = false;
            break;
        case REMOVED_NODE:
            ops.add(createRemoveOperation(originalNode));
            // No need to further process children. The REMOVE operation above will perform a
            // cascading delete of all children of newNode.
            isProcessChildren = false;
            break;
        case PARTITION_TYPE_CHANGE:
        case EXCLUDED_UNIT_CHANGE:
            ops.add(createRemoveOperation(originalNode));
            ops.addAll(createAddOperations(newNode));
            // No need to further process children. The ADD operations above will include operations
            // for all children of newNode.
            isProcessChildren = false;
            break;
        case BIDDABLE_UNIT_CHANGE:
            // Ensure that the new node has the proper ID (this may have been lost if the node
            // was removed and then re-added).
            newNode = newNode.setProductPartitionId(originalNode.getProductPartitionId());
            ops.add(createSetBidOperation(newNode));
            // Process the children of newNode. The SET operation above will only handle changes
            // made to newNode, not its children.
            isProcessChildren = true;
            break;
        case NONE:
            // Ensure that the new node has the proper ID (this may have been lost if the node
            // was removed and then re-added).
            newNode = newNode.setProductPartitionId(originalNode.getProductPartitionId());
            // This node does not have changes, but its children may.
            isProcessChildren = true;
            break;
        default:
            throw new IllegalStateException("Unrecognized difference: " + nodeDifference);
    }
    if (isProcessChildren) {
        for (ProductPartitionNode childNode : Iterables.concat(originalNode.getChildren(), newNode.getChildren())) {
            childDimensionsToProcess.add(childNode.getDimension());
        }
    }
    return childDimensionsToProcess;
}
Also used : NodeDifference(com.google.api.ads.adwords.axis.utils.v201809.shopping.ProductPartitionNodeDiffer.NodeDifference) ProductDimension(com.google.api.ads.adwords.axis.v201809.cm.ProductDimension)

Example 39 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.

the class UploadOfflineData method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param conversionName the name of the conversion tracker.
 * @param externalUploadId the external upload ID.
 * @param emailAddresses the list of email addresses. Must contain exactly two entries for this
 *     example.
 * @param offlineDataUploadType the type of store sales upload metadata to upload.
 * @param advertiserUploadTime the date and time of the advertiser upload.
 * @param bridgeMapVersionId the bridge map version ID.
 * @param partnerId the partner ID.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws UnsupportedEncodingException if encoding the offline data values failed.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, String conversionName, long externalUploadId, List<String> emailAddresses, OfflineDataUploadType offlineDataUploadType, String advertiserUploadTime, String bridgeMapVersionId, Integer partnerId) throws RemoteException, UnsupportedEncodingException {
    // This example requires exactly 2 email addresses.
    if (emailAddresses.size() != 2) {
        throw new IllegalArgumentException(String.format("%d email addresses specified. Please specify exactly 2 email addresses.", emailAddresses.size()));
    }
    // Get the OfflineDataUploadService.
    OfflineDataUploadServiceInterface offlineDataUploadService = adWordsServices.get(session, OfflineDataUploadServiceInterface.class);
    List<OfflineData> offlineDataList = new ArrayList<>();
    // Create the first offline data for upload.
    // This transaction occurred 7 days ago with amount of 200 USD.
    DateTime transactionTime1 = DateTime.now().minusDays(7);
    long transactionAmount1 = 200_000_000L;
    List<UserIdentifier> userIdentifiers1 = Arrays.asList(createUserIdentifier(OfflineDataUploadUserIdentifierType.HASHED_EMAIL, emailAddresses.get(0)), createUserIdentifier(OfflineDataUploadUserIdentifierType.STATE, "New York"));
    offlineDataList.add(createOfflineData(transactionTime1, transactionAmount1, "USD", conversionName, userIdentifiers1));
    // Create the second offline data for upload.
    // This transaction occurred 14 days ago with amount of 450 EUR.
    DateTime transactionTime2 = DateTime.now().minusDays(14);
    long transactionAmount2 = 450_000_000L;
    List<UserIdentifier> userIdentifiers2 = Arrays.asList(createUserIdentifier(OfflineDataUploadUserIdentifierType.HASHED_EMAIL, emailAddresses.get(1)), createUserIdentifier(OfflineDataUploadUserIdentifierType.STATE, "California"));
    offlineDataList.add(createOfflineData(transactionTime2, transactionAmount2, "EUR", conversionName, userIdentifiers2));
    // Create offline data upload object.
    OfflineDataUpload offlineDataUpload = new OfflineDataUpload();
    offlineDataUpload.setExternalUploadId(externalUploadId);
    offlineDataUpload.setOfflineDataList(offlineDataList.toArray(new OfflineData[offlineDataList.size()]));
    offlineDataUpload.setUploadType(offlineDataUploadType);
    // Set the type and metadata of this upload.
    StoreSalesUploadCommonMetadata storeSalesUploadMetadata;
    if (OfflineDataUploadType.STORE_SALES_UPLOAD_FIRST_PARTY.equals(offlineDataUploadType)) {
        storeSalesUploadMetadata = new FirstPartyUploadMetadata();
    } else {
        ThirdPartyUploadMetadata thirdPartyUploadMetadata = new ThirdPartyUploadMetadata();
        thirdPartyUploadMetadata.setAdvertiserUploadTime(advertiserUploadTime);
        thirdPartyUploadMetadata.setValidTransactionRate(1.0);
        thirdPartyUploadMetadata.setPartnerMatchRate(1.0);
        thirdPartyUploadMetadata.setPartnerUploadRate(1.0);
        thirdPartyUploadMetadata.setBridgeMapVersionId(bridgeMapVersionId);
        thirdPartyUploadMetadata.setPartnerId(partnerId);
        storeSalesUploadMetadata = thirdPartyUploadMetadata;
    }
    storeSalesUploadMetadata.setLoyaltyRate(1.0);
    storeSalesUploadMetadata.setTransactionUploadRate(1.0);
    UploadMetadata uploadMetadata = new UploadMetadata();
    uploadMetadata.setStoreSalesUploadCommonMetadata(storeSalesUploadMetadata);
    offlineDataUpload.setUploadMetadata(uploadMetadata);
    // Create an offline data upload operation.
    List<OfflineDataUploadOperation> operations = new ArrayList<>();
    OfflineDataUploadOperation offlineDataUploadOperation = new OfflineDataUploadOperation();
    offlineDataUploadOperation.setOperator(Operator.ADD);
    offlineDataUploadOperation.setOperand(offlineDataUpload);
    operations.add(offlineDataUploadOperation);
    // Upload offline data on the server and print some information.
    OfflineDataUploadReturnValue returnValue = offlineDataUploadService.mutate(operations.toArray(new OfflineDataUploadOperation[0]));
    offlineDataUpload = returnValue.getValue(0);
    System.out.printf("Uploaded offline data with external upload ID %d, and upload status %s.%n", offlineDataUpload.getExternalUploadId(), offlineDataUpload.getUploadStatus());
    // Print any partial failure errors from the response.
    if (returnValue.getPartialFailureErrors() != null) {
        for (ApiError apiError : returnValue.getPartialFailureErrors()) {
            // Get the index of the failed operation from the error's field path elements.
            Integer operationIndex = getFieldPathElementIndex(apiError, "operations");
            if (operationIndex != null) {
                OfflineDataUpload failedOfflineDataUpload = operations.get(operationIndex).getOperand();
                // Get the index of the entry in the offline data list from the error's field path
                // elements.
                Integer offlineDataListIndex = getFieldPathElementIndex(apiError, "offlineDataList");
                System.out.printf("Offline data list entry %d in operation %d with external upload ID %d and type " + "'%s' has triggered a failure for the following reason: '%s'.%n", offlineDataListIndex, operationIndex, failedOfflineDataUpload.getExternalUploadId(), failedOfflineDataUpload.getUploadType(), apiError.getErrorString());
            } else {
                System.out.printf("A failure has occurred for the following reason: %s%n", apiError.getErrorString());
            }
        }
    }
}
Also used : OfflineData(com.google.api.ads.adwords.axis.v201809.rm.OfflineData) OfflineDataUploadReturnValue(com.google.api.ads.adwords.axis.v201809.rm.OfflineDataUploadReturnValue) ArrayList(java.util.ArrayList) DateTime(org.joda.time.DateTime) StoreSalesUploadCommonMetadata(com.google.api.ads.adwords.axis.v201809.rm.StoreSalesUploadCommonMetadata) ThirdPartyUploadMetadata(com.google.api.ads.adwords.axis.v201809.rm.ThirdPartyUploadMetadata) FirstPartyUploadMetadata(com.google.api.ads.adwords.axis.v201809.rm.FirstPartyUploadMetadata) OfflineDataUploadServiceInterface(com.google.api.ads.adwords.axis.v201809.rm.OfflineDataUploadServiceInterface) FirstPartyUploadMetadata(com.google.api.ads.adwords.axis.v201809.rm.FirstPartyUploadMetadata) ThirdPartyUploadMetadata(com.google.api.ads.adwords.axis.v201809.rm.ThirdPartyUploadMetadata) UploadMetadata(com.google.api.ads.adwords.axis.v201809.rm.UploadMetadata) OfflineDataUploadOperation(com.google.api.ads.adwords.axis.v201809.rm.OfflineDataUploadOperation) ApiError(com.google.api.ads.adwords.axis.v201809.cm.ApiError) UserIdentifier(com.google.api.ads.adwords.axis.v201809.rm.UserIdentifier) OfflineDataUpload(com.google.api.ads.adwords.axis.v201809.rm.OfflineDataUpload)

Example 40 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.

the class AddPrices method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign where price feed items will be added.
 * @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, Long campaignId) throws ApiException, RemoteException {
    // Get the CustomerExtensionSettingService.
    CustomerExtensionSettingServiceInterface customerExtensionSettingService = adWordsServices.get(session, CustomerExtensionSettingServiceInterface.class);
    // Create the price extension feed item.
    PriceFeedItem priceFeedItem = new PriceFeedItem();
    priceFeedItem.setPriceExtensionType(PriceExtensionType.SERVICES);
    // Price qualifier is optional.
    priceFeedItem.setPriceQualifier(PriceExtensionPriceQualifier.FROM);
    priceFeedItem.setTrackingUrlTemplate("http://tracker.example.com/?u={lpurl}");
    priceFeedItem.setLanguage("en");
    FeedItemCampaignTargeting campaignTargeting = new FeedItemCampaignTargeting();
    campaignTargeting.setTargetingCampaignId(campaignId);
    priceFeedItem.setCampaignTargeting(campaignTargeting);
    priceFeedItem.setScheduling(new FeedItemScheduling(new FeedItemSchedule[] { new FeedItemSchedule(DayOfWeek.SUNDAY, 10, MinuteOfHour.ZERO, 18, MinuteOfHour.ZERO), new FeedItemSchedule(DayOfWeek.SATURDAY, 10, MinuteOfHour.ZERO, 22, MinuteOfHour.ZERO) }));
    // To create a price extension, at least three table rows are needed.
    List<PriceTableRow> priceTableRows = new ArrayList<>();
    String currencyCode = "USD";
    priceTableRows.add(createPriceTableRow("Scrubs", "Body Scrub, Salt Scrub", "http://www.example.com/scrubs", "http://m.example.com/scrubs", 60000000, currencyCode, PriceExtensionPriceUnit.PER_HOUR));
    priceTableRows.add(createPriceTableRow("Hair Cuts", "Once a month", "http://www.example.com/haircuts", "http://m.example.com/haircuts", 75000000, currencyCode, PriceExtensionPriceUnit.PER_MONTH));
    priceTableRows.add(createPriceTableRow("Skin Care Package", "Four times a month", "http://www.example.com/skincarepackage", null, 250000000, currencyCode, PriceExtensionPriceUnit.PER_MONTH));
    priceFeedItem.setTableRows(priceTableRows.toArray(new PriceTableRow[priceTableRows.size()]));
    // Create your campaign extension settings. This associates the sitelinks
    // to your campaign.
    CustomerExtensionSetting customerExtensionSetting = new CustomerExtensionSetting();
    customerExtensionSetting.setExtensionType(FeedType.PRICE);
    ExtensionSetting extensionSetting = new ExtensionSetting();
    extensionSetting.setExtensions(new ExtensionFeedItem[] { priceFeedItem });
    customerExtensionSetting.setExtensionSetting(extensionSetting);
    CustomerExtensionSettingOperation operation = new CustomerExtensionSettingOperation();
    operation.setOperand(customerExtensionSetting);
    operation.setOperator(Operator.ADD);
    // Add the extensions.
    CustomerExtensionSettingReturnValue returnValue = customerExtensionSettingService.mutate(new CustomerExtensionSettingOperation[] { operation });
    if (returnValue.getValue() != null && returnValue.getValue().length > 0) {
        CustomerExtensionSetting newExtensionSetting = returnValue.getValue(0);
        System.out.printf("Extension setting with type '%s' was added.%n", newExtensionSetting.getExtensionType().getValue());
    } else {
        System.out.println("No extension settings were created.");
    }
}
Also used : CustomerExtensionSettingServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSettingServiceInterface) ExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.ExtensionSetting) CustomerExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSetting) CustomerExtensionSettingOperation(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSettingOperation) FeedItemSchedule(com.google.api.ads.adwords.axis.v201809.cm.FeedItemSchedule) ArrayList(java.util.ArrayList) PriceTableRow(com.google.api.ads.adwords.axis.v201809.cm.PriceTableRow) FeedItemCampaignTargeting(com.google.api.ads.adwords.axis.v201809.cm.FeedItemCampaignTargeting) FeedItemScheduling(com.google.api.ads.adwords.axis.v201809.cm.FeedItemScheduling) PriceFeedItem(com.google.api.ads.adwords.axis.v201809.cm.PriceFeedItem) CustomerExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSetting) CustomerExtensionSettingReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSettingReturnValue)

Aggregations

ArrayList (java.util.ArrayList)24 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)18 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)17 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)16 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)15 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)14 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)14 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)13 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)13 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)12 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)12 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)11 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)11 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)10 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)10 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)9 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)8 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)8 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)8 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)8