use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class AddSmartShoppingAd method createDefaultPartition.
/**
* Creates a default product partition as an ad group criterion.
*/
private static void createDefaultPartition(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws RemoteException {
// Create an ad group criterion for 'All products' using the ProductPartitionTree utility.
ProductPartitionTree productPartitionTree = ProductPartitionTree.createAdGroupTree(adWordsServices, session, adGroupId);
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.Ad in project googleads-java-lib by googleads.
the class AddSmartShoppingAd method createSmartShoppingAd.
/**
* Creates a Smart Shopping ad.
*/
private static void createSmartShoppingAd(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws RemoteException {
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
// Create a Smart Shopping ad (Goal-optimized Shopping ad).
GoalOptimizedShoppingAd smartShoppingAd = new GoalOptimizedShoppingAd();
// Create ad group ad.
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAdGroupId(adGroupId);
adGroupAd.setAd(smartShoppingAd);
// 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("Smart Shopping ad with ID %d was added.%n", adGroupAd.getAd().getId());
}
use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class AddSmartShoppingAd method createSmartShoppingAdGroup.
/**
* Creates a Smart Shopping ad group by setting the ad group type to SHOPPING_GOAL_OPTIMIZED_ADS.
*/
private static AdGroup createSmartShoppingAdGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, long campaignId) throws RemoteException {
// Get the AdGroupService.
AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
// Create ad group.
AdGroup adGroup = new AdGroup();
adGroup.setCampaignId(campaignId);
adGroup.setName("Smart Shopping ad group #" + System.currentTimeMillis());
// Set the ad group type to SHOPPING_GOAL_OPTIMIZED_ADS.
adGroup.setAdGroupType(AdGroupType.SHOPPING_GOAL_OPTIMIZED_ADS);
// 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("Smart Shopping ad group with name '%s' and ID %d was added.%n", adGroup.getName(), adGroup.getId());
return adGroup;
}
use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class AddAdCustomizer method createCustomizerFeedItems.
/**
* Creates FeedItems with the values to use in ad customizations for each ad group in
* <code>adGroupIds</code>.
*/
private static void createCustomizerFeedItems(AdWordsServicesInterface adWordsServices, AdWordsSession session, List<Long> adGroupIds, AdCustomizerFeed adCustomizerFeed) throws RemoteException {
// Get the FeedItemService.
FeedItemServiceInterface feedItemService = adWordsServices.get(session, FeedItemServiceInterface.class);
List<FeedItemOperation> feedItemOperations = new ArrayList<>();
DateTime now = DateTime.now();
DateTime marsDate = new DateTime(now.getYear(), now.getMonthOfYear(), 1, 0, 0);
feedItemOperations.add(createFeedItemAddOperation("Mars", "$1234.56", marsDate.toString("yyyyMMdd HHmmss"), adCustomizerFeed));
DateTime venusDate = new DateTime(now.getYear(), now.getMonthOfYear(), 15, 0, 0);
feedItemOperations.add(createFeedItemAddOperation("Venus", "$1450.00", venusDate.toString("yyyyMMdd HHmmss"), adCustomizerFeed));
FeedItemReturnValue feedItemReturnValue = feedItemService.mutate(feedItemOperations.toArray(new FeedItemOperation[feedItemOperations.size()]));
for (FeedItem addedFeedItem : feedItemReturnValue.getValue()) {
System.out.printf("Added feed item with ID %d.%n", addedFeedItem.getFeedItemId());
}
// Add feed item targeting to restrict the feed item to specific ad groups.
restrictFeedItemToAdGroup(adWordsServices, session, feedItemReturnValue.getValue(0), adGroupIds.get(0));
restrictFeedItemToAdGroup(adWordsServices, session, feedItemReturnValue.getValue(1), adGroupIds.get(1));
}
use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class AddAdCustomizer method createAdsWithCustomizations.
/**
* Creates expanded text ads that use ad customizations for the specified ad group IDs.
*/
private static void createAdsWithCustomizations(AdWordsServicesInterface adWordsServices, AdWordsSession session, List<Long> adGroupIds, String feedName) throws RemoteException {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
ExpandedTextAd textAd = new ExpandedTextAd();
textAd.setHeadlinePart1(String.format("Luxury Cruise to {=%s.Name}", feedName));
textAd.setHeadlinePart2(String.format("Only {=%s.Price}", feedName));
textAd.setDescription(String.format("Offer ends in {=countdown(%s.Date)}!", feedName));
textAd.setFinalUrls(new String[] { "http://www.example.com" });
// We add the same ad to both ad groups. When they serve, they will show different values, since
// they match different feed items.
List<AdGroupAdOperation> adGroupAdOperations = new ArrayList<>();
for (Long adGroupId : adGroupIds) {
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAdGroupId(adGroupId);
adGroupAd.setAd(textAd);
AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
adGroupAdOperation.setOperand(adGroupAd);
adGroupAdOperation.setOperator(Operator.ADD);
adGroupAdOperations.add(adGroupAdOperation);
}
AdGroupAdReturnValue adGroupAdReturnValue = adGroupAdService.mutate(adGroupAdOperations.toArray(new AdGroupAdOperation[adGroupAdOperations.size()]));
for (AdGroupAd addedAd : adGroupAdReturnValue.getValue()) {
System.out.printf("Created an ad with ID %d, type '%s' and status '%s'.%n", addedAd.getAd().getId(), addedAd.getAd().getAdType(), addedAd.getStatus());
}
}
Aggregations