use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation 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.AdGroupCriterionOperation 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.AdGroupCriterionOperation in project googleads-java-lib by googleads.
the class AddProductPartitionTree method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group.
* @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 {
// Build a new ProductPartitionTree using the ad group's current set of criteria.
ProductPartitionTree partitionTree = ProductPartitionTree.createAdGroupTree(adWordsServices, session, adGroupId);
System.out.printf("Original tree:%n%s%n", partitionTree);
// Clear out any existing criteria.
ProductPartitionNode rootNode = partitionTree.getRoot().removeAllChildren();
// Make the root node a subdivision.
rootNode = rootNode.asSubdivision();
// Add a unit node for condition = NEW.
rootNode.addChild(ProductDimensions.createCanonicalCondition(ProductCanonicalConditionCondition.NEW)).asBiddableUnit().setBid(200000L);
// Add a unit node for condition = USED.
rootNode.addChild(ProductDimensions.createCanonicalCondition(ProductCanonicalConditionCondition.USED)).asBiddableUnit().setBid(100000L);
// Add a subdivision node for condition = null (everything else).
ProductPartitionNode otherConditionNode = rootNode.addChild(ProductDimensions.createCanonicalCondition(null)).asSubdivision();
// Add a unit node under condition = null for brand = "CoolBrand".
otherConditionNode.addChild(ProductDimensions.createBrand("CoolBrand")).asBiddableUnit().setBid(900000L);
// Add a unit node under condition = null for brand = "CheapBrand".
otherConditionNode.addChild(ProductDimensions.createBrand("CheapBrand")).asBiddableUnit().setBid(10000L);
// Add a subdivision node under condition = null for brand = null (everything else).
ProductPartitionNode otherBrandNode = otherConditionNode.addChild(ProductDimensions.createBrand(null)).asSubdivision();
// Add unit nodes under condition = null/brand = null.
// The value for each bidding category is a fixed ID for a specific
// category. You can retrieve IDs for categories from the ConstantDataService.
// See the 'GetProductCategoryTaxonomy' example for more details.
// Add a unit node under condition = null/brand = null for product type
// level 1 = 'Luggage & Bags'.
otherBrandNode.addChild(ProductDimensions.createBiddingCategory(ProductDimensionType.BIDDING_CATEGORY_L1, -5914235892932915235L)).asBiddableUnit().setBid(750000L);
// Add a unit node under condition = null/brand = null for product type
// level 1 = null (everything else).
otherBrandNode.addChild(ProductDimensions.createBiddingCategory(ProductDimensionType.BIDDING_CATEGORY_L1, null)).asBiddableUnit().setBid(110000L);
// Get the ad group criterion service.
AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
// Make the mutate request, using the operations returned by the ProductPartitionTree.
List<AdGroupCriterionOperation> mutateOperations = partitionTree.getMutateOperations();
if (mutateOperations.isEmpty()) {
System.out.println("Skipping the mutate call because the original tree and the current tree " + "are logically identical.");
} else {
adGroupCriterionService.mutate(mutateOperations.toArray(new AdGroupCriterionOperation[0]));
}
// The request was successful, so create a new ProductPartitionTree based on the updated state
// of the ad group.
partitionTree = ProductPartitionTree.createAdGroupTree(adWordsServices, session, adGroupId);
// Show the tree
System.out.printf("Updated tree:%n%s%n", partitionTree);
}
use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation in project googleads-java-lib by googleads.
the class AddShoppingCampaign method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param budgetId the budget ID to use for the new campaign.
* @param merchantId the Merchant Center ID for the new campaign.
* @param createDefaultPartition if true, a default product partition for all products 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.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long budgetId, Long merchantId, boolean createDefaultPartition) throws RemoteException {
// Get the CampaignService
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
// Create campaign.
Campaign campaign = new Campaign();
campaign.setName("Shopping campaign #" + System.currentTimeMillis());
// The advertisingChannelType is what makes this a Shopping campaign
campaign.setAdvertisingChannelType(AdvertisingChannelType.SHOPPING);
// Recommendation: Set the campaign to PAUSED when creating it to prevent
// the ads from immediately serving. Set to ENABLED once you've added
// targeting and the ads are ready to serve.
campaign.setStatus(CampaignStatus.PAUSED);
// Set shared budget (required).
Budget budget = new Budget();
budget.setBudgetId(budgetId);
campaign.setBudget(budget);
// Set bidding strategy (required).
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.MANUAL_CPC);
campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
// All Shopping campaigns need a ShoppingSetting.
ShoppingSetting shoppingSetting = new ShoppingSetting();
shoppingSetting.setSalesCountry("US");
shoppingSetting.setCampaignPriority(0);
shoppingSetting.setMerchantId(merchantId);
// Set to 'true' to enable Local Inventory Ads in your campaign.
shoppingSetting.setEnableLocal(true);
campaign.setSettings(new Setting[] { shoppingSetting });
// Create operation.
CampaignOperation campaignOperation = new CampaignOperation();
campaignOperation.setOperand(campaign);
campaignOperation.setOperator(Operator.ADD);
// Make the mutate request.
CampaignReturnValue campaignAddResult = campaignService.mutate(new CampaignOperation[] { campaignOperation });
// Display result.
campaign = campaignAddResult.getValue(0);
System.out.printf("Campaign with name '%s' and ID %d was added.%n", campaign.getName(), campaign.getId());
// Get the AdGroupService.
AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
// Create ad group.
AdGroup adGroup = new AdGroup();
adGroup.setCampaignId(campaign.getId());
adGroup.setName("Ad Group #" + System.currentTimeMillis());
// Create operation.
AdGroupOperation adGroupOperation = new AdGroupOperation();
adGroupOperation.setOperand(adGroup);
adGroupOperation.setOperator(Operator.ADD);
// Make the mutate request.
AdGroupReturnValue adGroupAddResult = adGroupService.mutate(new AdGroupOperation[] { adGroupOperation });
// Display result.
adGroup = adGroupAddResult.getValue(0);
System.out.printf("Ad group with name '%s' and ID %d was added.%n", adGroup.getName(), adGroup.getId());
// Create product ad.
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
ProductAd productAd = new ProductAd();
// Create ad group ad.
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAdGroupId(adGroup.getId());
adGroupAd.setAd(productAd);
// Create operation.
AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
adGroupAdOperation.setOperand(adGroupAd);
adGroupAdOperation.setOperator(Operator.ADD);
// Make the mutate request.
AdGroupAdReturnValue adGroupAdAddResult = adGroupAdService.mutate(new AdGroupAdOperation[] { adGroupAdOperation });
// Display result.
adGroupAd = adGroupAdAddResult.getValue(0);
System.out.printf("Product ad with ID %d was added.%n", adGroupAd.getAd().getId());
if (createDefaultPartition) {
// Create an ad group criterion for 'All products' using the ProductPartitionTree utility.
ProductPartitionTree productPartitionTree = ProductPartitionTree.createAdGroupTree(adWordsServices, session, adGroup.getId());
productPartitionTree.getRoot().asBiddableUnit().setBid(500000L);
List<AdGroupCriterionOperation> mutateOperations = productPartitionTree.getMutateOperations();
// Make the mutate request.
AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
AdGroupCriterionReturnValue adGroupCriterionResult = adGroupCriterionService.mutate(mutateOperations.toArray(new AdGroupCriterionOperation[0]));
// Display result.
for (AdGroupCriterion adGroupCriterion : adGroupCriterionResult.getValue()) {
System.out.printf("Ad group criterion with ID %d in ad group with ID %d was added.%n", adGroupCriterion.getCriterion().getId(), adGroupCriterion.getAdGroupId());
}
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation in project googleads-java-lib by googleads.
the class ProductPartitionTreeImpl method createAddOperations.
/**
* Creates ADD operations for the node and ALL of its children and adds them to the provided
* operations list.
*/
private List<OperationPair> createAddOperations(ProductPartitionNode node) {
AdGroupCriterionOperation addOp = new AdGroupCriterionOperation();
addOp.setOperator(Operator.ADD);
// Set the node's ID to a new temporary ID.
node.setProductPartitionId(idGenerator.next());
addOp.setOperand(ProductPartitionNodeAdapter.createCriterionForAdd(node, adGroupId, getBiddingStrategyConfiguration()));
List<OperationPair> operationsList = Lists.newArrayList();
operationsList.add(new OperationPair(node, addOp));
// Recursively add all of this node's children to the operations list.
for (ProductPartitionNode child : node.getChildren()) {
operationsList.addAll(createAddOperations(child));
}
return operationsList;
}
Aggregations