Search in sources :

Example 6 with Bids

use of com.google.api.ads.adwords.axis.v201809.cm.Bids 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 7 with Bids

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

the class AddDynamicPageFeed method addDsaTargeting.

/**
 * Sets custom targeting for the page feed URLs based on a list of labels.
 *
 * @param adWordsServices
 * @param session
 * @param adGroupId
 * @param dsaPageUrlLabel
 */
private static void addDsaTargeting(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long adGroupId, String dsaPageUrlLabel) throws ApiException, RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    // Create a webpage criterion.
    Webpage webpage = new Webpage();
    WebpageParameter parameter = new WebpageParameter();
    parameter.setCriterionName("Test criterion");
    webpage.setParameter(parameter);
    // Add a condition for label=specified_label_name.
    WebpageCondition condition = new WebpageCondition();
    condition.setOperand(WebpageConditionOperand.CUSTOM_LABEL);
    condition.setArgument(dsaPageUrlLabel);
    parameter.setConditions(new WebpageCondition[] { condition });
    BiddableAdGroupCriterion criterion = new BiddableAdGroupCriterion();
    criterion.setAdGroupId(adGroupId);
    criterion.setCriterion(webpage);
    // Set a custom bid for this criterion.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    CpcBid cpcBid = new CpcBid();
    Money money = new Money();
    money.setMicroAmount(1_500_000L);
    cpcBid.setBid(money);
    biddingStrategyConfiguration.setBids(new Bids[] { cpcBid });
    criterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
    operation.setOperand(criterion);
    operation.setOperator(Operator.ADD);
    BiddableAdGroupCriterion newCriterion = (BiddableAdGroupCriterion) adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { operation }).getValue(0);
    System.out.printf("Web page criterion with ID %d and status '%s' was created.%n", newCriterion.getCriterion().getId(), newCriterion.getUserStatus());
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) Webpage(com.google.api.ads.adwords.axis.v201809.cm.Webpage) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) WebpageParameter(com.google.api.ads.adwords.axis.v201809.cm.WebpageParameter) WebpageCondition(com.google.api.ads.adwords.axis.v201809.cm.WebpageCondition)

Example 8 with Bids

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

the class ProductPartitionTreeImpl method getBid.

/**
 * Returns the criterion-level bid, or null if no such bid exists.
 */
private static Money getBid(BiddableAdGroupCriterion biddableCriterion) {
    BiddingStrategyConfiguration biddingConfig = biddableCriterion.getBiddingStrategyConfiguration();
    Money cpcBidAmount = null;
    if (biddingConfig.getBids() != null) {
        for (Bids bid : biddingConfig.getBids()) {
            if (bid instanceof CpcBid) {
                CpcBid cpcBid = (CpcBid) bid;
                if (BidSource.CRITERION.equals(cpcBid.getCpcBidSource())) {
                    cpcBidAmount = cpcBid.getBid();
                    break;
                }
            }
        }
    }
    return cpcBidAmount;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) Bids(com.google.api.ads.adwords.axis.v201809.cm.Bids) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid)

Example 9 with Bids

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

the class UpdateAdGroup method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group to update.
 * @param bidMicroAmount the optional bid amount in micros to use for the ad group bid.
 * @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 adGroupId, @Nullable Long bidMicroAmount) throws RemoteException {
    // Get the AdGroupService.
    AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
    // Create an ad group with the specified ID.
    AdGroup adGroup = new AdGroup();
    adGroup.setId(adGroupId);
    // Update the CPC bid if specified.
    if (bidMicroAmount != null) {
        BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
        Money cpcBidMoney = new Money();
        cpcBidMoney.setMicroAmount(bidMicroAmount);
        CpcBid cpcBid = new CpcBid();
        cpcBid.setBid(cpcBidMoney);
        biddingStrategyConfiguration.setBids(new Bids[] { cpcBid });
        adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    }
    // Pause the ad group.
    adGroup.setStatus(AdGroupStatus.PAUSED);
    // Create operations.
    AdGroupOperation operation = new AdGroupOperation();
    operation.setOperand(adGroup);
    operation.setOperator(Operator.SET);
    AdGroupOperation[] operations = new AdGroupOperation[] { operation };
    // Update ad group.
    AdGroupReturnValue result = adGroupService.mutate(operations);
    // Display ad groups.
    for (AdGroup adGroupResult : result.getValue()) {
        BiddingStrategyConfiguration biddingStrategyConfiguration = adGroupResult.getBiddingStrategyConfiguration();
        // Find the CpcBid in the bidding strategy configuration's bids collection.
        Long cpcBidMicros = null;
        if (biddingStrategyConfiguration != null) {
            if (biddingStrategyConfiguration.getBids() != null) {
                for (Bids bid : biddingStrategyConfiguration.getBids()) {
                    if (bid instanceof CpcBid) {
                        cpcBidMicros = ((CpcBid) bid).getBid().getMicroAmount();
                        break;
                    }
                }
            }
        }
        System.out.printf("Ad group with ID %d and name '%s' updated to have status '%s' and CPC bid %d%n", adGroupResult.getId(), adGroupResult.getName(), adGroupResult.getStatus(), cpcBidMicros);
    }
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) Bids(com.google.api.ads.adwords.axis.v201809.cm.Bids) AdGroupReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Example 10 with Bids

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

the class UpdateKeyword method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group for the criterion.
 * @param keywordId the ID of the criterion to update.
 * @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 adGroupId, Long keywordId) throws RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    // Create ad group criterion with updated bid.
    Criterion criterion = new Criterion();
    criterion.setId(keywordId);
    BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
    biddableAdGroupCriterion.setAdGroupId(adGroupId);
    biddableAdGroupCriterion.setCriterion(criterion);
    // Create bids.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    CpcBid bid = new CpcBid();
    bid.setBid(new Money(null, 10000000L));
    biddingStrategyConfiguration.setBids(new Bids[] { bid });
    biddableAdGroupCriterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // Create operations.
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
    operation.setOperand(biddableAdGroupCriterion);
    operation.setOperator(Operator.SET);
    AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] { operation };
    // Update ad group criteria.
    AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
    // Display ad group criteria.
    for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
        if (adGroupCriterionResult instanceof BiddableAdGroupCriterion) {
            biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult;
            CpcBid criterionCpcBid = null;
            // Find the criterion-level CpcBid among the keyword's bids.
            for (Bids bids : biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids()) {
                if (bids instanceof CpcBid) {
                    CpcBid cpcBid = (CpcBid) bids;
                    if (BidSource.CRITERION.equals(cpcBid.getCpcBidSource())) {
                        criterionCpcBid = cpcBid;
                    }
                }
            }
            System.out.printf("Ad group criterion with ad group ID %d, criterion ID %d, type " + "'%s', and bid %d was updated.%n", biddableAdGroupCriterion.getAdGroupId(), biddableAdGroupCriterion.getCriterion().getId(), biddableAdGroupCriterion.getCriterion().getCriterionType(), criterionCpcBid.getBid().getMicroAmount());
        }
    }
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) AdGroupCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) Criterion(com.google.api.ads.adwords.axis.v201809.cm.Criterion) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) 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)

Aggregations

CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)12 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)11 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)10 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)8 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)6 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)5 Bids (com.google.api.ads.adwords.axis.v201809.cm.Bids)5 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)4 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)4 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)4 NegativeAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)4 AdGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface)3 ProductPartition (com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)3 AdGroupCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue)2 AdGroupReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue)2 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)2 Webpage (com.google.api.ads.adwords.axis.v201809.cm.Webpage)2 WebpageCondition (com.google.api.ads.adwords.axis.v201809.cm.WebpageCondition)2 WebpageParameter (com.google.api.ads.adwords.axis.v201809.cm.WebpageParameter)2 HashMap (java.util.HashMap)2