use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation in project googleads-java-lib by googleads.
the class ProductPartitionTreeImpl method createSetBidOperation.
/**
* Returns a SET operation for the specified node.
*/
private OperationPair createSetBidOperation(ProductPartitionNode node) {
Preconditions.checkNotNull(node.getProductPartitionId(), "Node for SET operation has no partition ID: %s", node);
Preconditions.checkArgument(node.getProductPartitionId().longValue() >= 0L, "Node for SET operation has a negative partition ID: %s", node);
AdGroupCriterionOperation setOp = new AdGroupCriterionOperation();
setOp.setOperator(Operator.SET);
setOp.setOperand(ProductPartitionNodeAdapter.createCriterionForSetBiddableUnit(node, adGroupId, getBiddingStrategyConfiguration()));
return new OperationPair(node, setOp);
}
use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation in project googleads-java-lib by googleads.
the class RemoveKeyword method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group for the keyword criterion.
* @param criterionId the ID of the keyword criterion to remove.
* @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 criterionId) throws RemoteException {
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
// Create base class criterion to avoid setting keyword specific fields.
Criterion criterion = new Criterion();
criterion.setId(criterionId);
// Create ad group criterion.
AdGroupCriterion adGroupCriterion = new AdGroupCriterion();
adGroupCriterion.setAdGroupId(adGroupId);
adGroupCriterion.setCriterion(criterion);
// Create operations.
AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
operation.setOperand(adGroupCriterion);
operation.setOperator(Operator.REMOVE);
AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] { operation };
// Remove ad group criteria.
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
// Display ad group criteria.
for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
System.out.printf("Ad group criterion with ad group ID %d, criterion ID %d, and type " + "'%s' was removed.%n", adGroupCriterionResult.getAdGroupId(), adGroupCriterionResult.getCriterion().getId(), adGroupCriterionResult.getCriterion().getCriterionType());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation 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());
}
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation in project googleads-java-lib by googleads.
the class AddKeywords method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group where the keywords will be created.
* @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 final URL failed.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws RemoteException, UnsupportedEncodingException {
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
// Create keywords.
Keyword keyword1 = new Keyword();
keyword1.setText("mars cruise");
keyword1.setMatchType(KeywordMatchType.BROAD);
Keyword keyword2 = new Keyword();
keyword2.setText("space hotel");
keyword2.setMatchType(KeywordMatchType.EXACT);
// Create biddable ad group criterion.
BiddableAdGroupCriterion keywordBiddableAdGroupCriterion1 = new BiddableAdGroupCriterion();
keywordBiddableAdGroupCriterion1.setAdGroupId(adGroupId);
keywordBiddableAdGroupCriterion1.setCriterion(keyword1);
// You can optionally provide these field(s).
keywordBiddableAdGroupCriterion1.setUserStatus(UserStatus.PAUSED);
String encodedFinalUrl = String.format("http://example.com/mars/cruise/?kw=%s", URLEncoder.encode(keyword1.getText(), UTF_8.name()));
keywordBiddableAdGroupCriterion1.setFinalUrls(new UrlList(new String[] { encodedFinalUrl }));
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
CpcBid bid = new CpcBid();
bid.setBid(new Money(null, 10000000L));
biddingStrategyConfiguration.setBids(new Bids[] { bid });
keywordBiddableAdGroupCriterion1.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
NegativeAdGroupCriterion keywordNegativeAdGroupCriterion2 = new NegativeAdGroupCriterion();
keywordNegativeAdGroupCriterion2.setAdGroupId(adGroupId);
keywordNegativeAdGroupCriterion2.setCriterion(keyword2);
// Create operations.
AdGroupCriterionOperation keywordAdGroupCriterionOperation1 = new AdGroupCriterionOperation();
keywordAdGroupCriterionOperation1.setOperand(keywordBiddableAdGroupCriterion1);
keywordAdGroupCriterionOperation1.setOperator(Operator.ADD);
AdGroupCriterionOperation keywordAdGroupCriterionOperation2 = new AdGroupCriterionOperation();
keywordAdGroupCriterionOperation2.setOperand(keywordNegativeAdGroupCriterion2);
keywordAdGroupCriterionOperation2.setOperator(Operator.ADD);
AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] { keywordAdGroupCriterionOperation1, keywordAdGroupCriterionOperation2 };
// Add keywords.
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
// Display results.
for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
System.out.printf("Keyword ad group criterion with ad group ID %d, criterion ID %d, " + "text '%s', and match type '%s' was added.%n", adGroupCriterionResult.getAdGroupId(), adGroupCriterionResult.getCriterion().getId(), ((Keyword) adGroupCriterionResult.getCriterion()).getText(), ((Keyword) adGroupCriterionResult.getCriterion()).getMatchType());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation in project googleads-java-lib by googleads.
the class ProductPartitionTreeTest method testCreateMultiNodeTreeFromScratch.
/**
* Tests creating an empty tree and then adding several levels of nodes.
*/
@Test
public void testCreateMultiNodeTreeFromScratch() {
ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, Collections.<AdGroupCriterion>emptyList());
ProductPartitionNode rootNode = tree.getRoot().asSubdivision();
ProductPartitionNode brand1 = rootNode.addChild(ProductDimensions.createBrand("google")).asSubdivision();
ProductPartitionNode brand1Offer1 = brand1.addChild(ProductDimensions.createOfferId("A")).asBiddableUnit().setBid(1000000L).putCustomParameter("param1", "value1").putCustomParameter("param2", "value2");
ProductPartitionNode brand1Offer2 = brand1.addChild(ProductDimensions.createOfferId(null)).asExcludedUnit();
ProductPartitionNode brand2 = rootNode.addChild(ProductDimensions.createBrand(null)).asExcludedUnit();
int expectedOpCount = 5;
List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
assertEquals("Number of operations is incorrect", expectedOpCount, mutateOperations.size());
List<CriterionDescriptor> nodeDescriptors = Stream.of(rootNode, brand1, brand1Offer1, brand1Offer2, brand2).map(CriterionDescriptor::new).collect(Collectors.toList());
int opNum = 0;
List<CriterionDescriptor> opDescriptors = Lists.newArrayList();
Map<Long, CriterionDescriptor> opDescriptorsById = Maps.newHashMap();
for (AdGroupCriterionOperation op : mutateOperations) {
CriterionDescriptor opDescriptor = new CriterionDescriptor(op.getOperand(), opNum++);
opDescriptors.add(opDescriptor);
opDescriptorsById.put(opDescriptor.partitionId, opDescriptor);
}
Map<Long, Map<Long, CriterionDescriptor>> opDescriptorMap = buildDescriptorMap(opDescriptors);
for (CriterionDescriptor nodeDescriptor : nodeDescriptors) {
CriterionDescriptor opDescriptor = opDescriptorMap.get(nodeDescriptor.parentPartitionId).get(nodeDescriptor.partitionId);
nodeDescriptor.assertDescriptorEquals(opDescriptor);
AdGroupCriterionOperation op = mutateOperations.get(opDescriptor.operationNumber);
assertEquals("operator is incorrect", Operator.ADD, op.getOperator());
if (nodeDescriptor.parentPartitionId != null) {
CriterionDescriptor parentOpDescriptor = opDescriptorsById.get(nodeDescriptor.parentPartitionId);
assertNotNull("no operation found for parent", parentOpDescriptor);
assertThat("operation # for parent is > operation # for child", opDescriptor.operationNumber, Matchers.greaterThan(parentOpDescriptor.operationNumber));
}
}
assertThat("Tree toString does not contain the root's detailed toString", tree.toString(), Matchers.containsString(tree.getRoot().toDetailedString()));
assertThat("Tree toString does not contain the ad group ID", tree.toString(), Matchers.containsString(tree.getAdGroupId().toString()));
}
Aggregations