use of com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion in project googleads-java-lib by googleads.
the class JaxWsBatchJobResponseDeserializerTest method testDeserializeBatchJobResponseWithoutErrors.
/**
* Tests that a response without errors will be properly deserialized.
*/
@Test
public void testDeserializeBatchJobResponseWithoutErrors() throws Exception {
BatchJobMutateResponse response = deserializer.deserializeBatchJobMutateResults(BatchJobMutateResponse.class, JaxWsBatchJobResponseDeserializerTest.class.getResource("resources/BatchJobMutate.responseWithoutErrors.xml"));
assertNotNull(response);
// Expect: Campaign, AdGroup, BiddableAdGroupCriterion, BiddableAdGroupCriterion
assertEquals(4, response.getMutateResults().length);
assertNotNull(response.getMutateResults()[0].getOperand().getCampaign());
assertNotNull(response.getMutateResults()[1].getOperand().getAdGroup());
assertNotNull(response.getMutateResults()[2].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
assertNotNull(response.getMutateResults()[3].getOperand().getAdGroupCriterion());
assertThat(response.getMutateResults()[3].getOperand().getAdGroupCriterion(), Matchers.instanceOf(BiddableAdGroupCriterion.class));
}
use of com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion 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.BiddableAdGroupCriterion in project googleads-java-lib by googleads.
the class AddDemographicTargetingCriteria method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group where demographic targeting will be modified.
* @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) throws RemoteException {
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
// https://developers.google.com/adwords/api/docs/appendix/genders
Gender male = new Gender();
male.setId(10L);
BiddableAdGroupCriterion genderBiddableAdGroupCriterion = new BiddableAdGroupCriterion();
genderBiddableAdGroupCriterion.setAdGroupId(adGroupId);
genderBiddableAdGroupCriterion.setCriterion(male);
// https://developers.google.com/adwords/api/docs/appendix/ages
AgeRange undetermined = new AgeRange();
undetermined.setId(503999L);
NegativeAdGroupCriterion ageRangeNegativeAdGroupCriterion = new NegativeAdGroupCriterion();
ageRangeNegativeAdGroupCriterion.setAdGroupId(adGroupId);
ageRangeNegativeAdGroupCriterion.setCriterion(undetermined);
AdGroupCriterionOperation genderAdGroupCriterionOperation = new AdGroupCriterionOperation();
genderAdGroupCriterionOperation.setOperand(genderBiddableAdGroupCriterion);
genderAdGroupCriterionOperation.setOperator(Operator.ADD);
AdGroupCriterionOperation ageRangeNegativeAdGroupCriterionOperation = new AdGroupCriterionOperation();
ageRangeNegativeAdGroupCriterionOperation.setOperand(ageRangeNegativeAdGroupCriterion);
ageRangeNegativeAdGroupCriterionOperation.setOperator(Operator.ADD);
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { genderAdGroupCriterionOperation, ageRangeNegativeAdGroupCriterionOperation });
// Display campaigns.
for (AdGroupCriterion adGroupCriterion : result.getValue()) {
System.out.printf("AdGroup criterion with adGroup ID %d, criterion ID %d, " + "and type '%s' was added.%n", adGroupCriterion.getAdGroupId(), adGroupCriterion.getCriterion().getId(), adGroupCriterion.getCriterion().getCriterionType());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion in project googleads-java-lib by googleads.
the class ProductPartitionTreeImpl method createAdGroupTree.
/**
* Returns a new instance of this class based on the collection of ad group criteria provided.
* <p>NOTE: If retrieving existing criteria for use with this method, you must include all of the
* fields in {@link #REQUIRED_SELECTOR_FIELD_ENUMS} in your {@link Selector}.
*
* @param adGroupId the ID of the ad group
* @param biddingStrategyConfig the {@link BiddingStrategyConfiguration} for the ad group
* @param adGroupCriteria the non-null (but possibly empty) list of ad group criteria
*
* @throws NullPointerException if any argument is null, any element in {@code adGroupCriteria} is
* null, or any required field from {@link #REQUIRED_SELECTOR_FIELD_ENUMS} is missing from
* an element in {@code adGroupCriteria}
* @throws IllegalArgumentException if {@code adGroupCriteria} does not include the root criterion
* of the product partition tree
*/
static ProductPartitionTreeImpl createAdGroupTree(Long adGroupId, BiddingStrategyConfiguration biddingStrategyConfig, List<AdGroupCriterion> adGroupCriteria) {
Preconditions.checkNotNull(adGroupId, "Null ad group ID");
Preconditions.checkNotNull(biddingStrategyConfig, "Null bidding strategy configuration");
Preconditions.checkNotNull(adGroupCriteria, "Null criteria list");
if (adGroupCriteria.isEmpty()) {
return createEmptyAdGroupTree(adGroupId, biddingStrategyConfig);
}
ListMultimap<Long, AdGroupCriterion> parentIdMap = LinkedListMultimap.create();
for (AdGroupCriterion adGroupCriterion : adGroupCriteria) {
Preconditions.checkNotNull(adGroupCriterion.getCriterion(), "AdGroupCriterion has a null criterion");
if (adGroupCriterion instanceof BiddableAdGroupCriterion) {
BiddableAdGroupCriterion biddableCriterion = (BiddableAdGroupCriterion) adGroupCriterion;
Preconditions.checkNotNull(biddableCriterion.getUserStatus(), "User status is null for criterion ID %s", biddableCriterion.getCriterion().getId());
if (UserStatus.REMOVED.equals(biddableCriterion.getUserStatus())) {
// Skip REMOVED criteria.
continue;
}
}
if (adGroupCriterion.getCriterion() instanceof ProductPartition) {
ProductPartition partition = (ProductPartition) adGroupCriterion.getCriterion();
parentIdMap.put(partition.getParentCriterionId(), adGroupCriterion);
}
}
return createNonEmptyAdGroupTree(adGroupId, parentIdMap);
}
use of com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion 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;
}
Aggregations