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;
}
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());
}
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;
}
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);
}
}
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());
}
}
}
Aggregations