use of com.google.api.ads.adwords.axis.v201809.cm.ShoppingSetting in project googleads-java-lib by googleads.
the class AddSmartShoppingAd method createSmartShoppingCampaign.
/**
* Creates a Smart Shopping campaign.
*/
private static Campaign createSmartShoppingCampaign(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long budgetId, long merchantId) throws RemoteException {
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
// Create a campaign with required and optional settings.
Campaign campaign = new Campaign();
campaign.setName("Smart Shopping campaign #" + System.currentTimeMillis());
// The advertisingChannelType is what makes this a Shopping campaign.
campaign.setAdvertisingChannelType(AdvertisingChannelType.SHOPPING);
// Sets the advertisingChannelSubType to SHOPPING_GOAL_OPTIMIZED_ADS to
// make this a Smart Shopping campaign.
campaign.setAdvertisingChannelSubType(AdvertisingChannelSubType.SHOPPING_GOAL_OPTIMIZED_ADS);
// Recommendation: Set the campaign to PAUSED when creating it to stop
// 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 a budget.
Budget budget = new Budget();
budget.setBudgetId(budgetId);
campaign.setBudget(budget);
// Set bidding strategy. Only MAXIMIZE_CONVERSION_VALUE is supported.
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.MAXIMIZE_CONVERSION_VALUE);
campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
// All Shopping campaigns need a ShoppingSetting.
ShoppingSetting shoppingSetting = new ShoppingSetting();
shoppingSetting.setSalesCountry("US");
shoppingSetting.setMerchantId(merchantId);
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("Smart Shopping campaign with name '%s' and ID %d was added.%n", campaign.getName(), campaign.getId());
return campaign;
}
use of com.google.api.ads.adwords.axis.v201809.cm.ShoppingSetting 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.ShoppingSetting in project googleads-java-lib by googleads.
the class AddShoppingDynamicRemarketingCampaign method createCampaign.
/**
* Creates a Shopping dynamic remarketing campaign object (not including ad group level and
* below). This creates a Display campaign with the merchant center feed attached. Merchant Center
* is used for the product information in combination with a user list which contains hits with
* {@code ecomm_prodid} specified. See <a
* href="https://developers.google.com/adwords-remarketing-tag/parameters#retail"/>for more
* detail.
*
* @param merchantId the ID of the Merchant Center account.
* @param budgetId the ID of the budget to use for the campaign.
* @return the campaign that was created.
*/
private static Campaign createCampaign(AdWordsServicesInterface services, AdWordsSession session, long merchantId, long budgetId) throws RemoteException {
CampaignServiceInterface campaignService = services.get(session, CampaignServiceInterface.class);
Campaign campaign = new Campaign();
campaign.setName("Shopping campaign #" + System.currentTimeMillis());
// Dynamic remarketing campaigns are only available on the Google Display Network.
campaign.setAdvertisingChannelType(AdvertisingChannelType.DISPLAY);
campaign.setStatus(CampaignStatus.PAUSED);
Budget budget = new Budget();
budget.setBudgetId(budgetId);
campaign.setBudget(budget);
// This example uses a Manual CPC bidding strategy, but you should select the strategy that best
// aligns with your sales goals. More details here:
// https://support.google.com/adwords/answer/2472725
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.MANUAL_CPC);
campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
ShoppingSetting setting = new ShoppingSetting();
// Campaigns with numerically higher priorities take precedence over those with lower
// priorities.
setting.setCampaignPriority(0);
// Set the Merchant Center account ID from which to source products.
setting.setMerchantId(merchantId);
// Display Network campaigns do not support partition by country. The only supported value is
// "ZZ". This signals that products from all countries are available in the campaign. The actual
// products which serve are based on the products tagged in the user list entry.
setting.setSalesCountry("ZZ");
// Optional: Enable local inventory ads (items for sale in physical stores.)
setting.setEnableLocal(true);
campaign.setSettings(new Setting[] { setting });
CampaignOperation op = new CampaignOperation();
op.setOperand(campaign);
op.setOperator(Operator.ADD);
CampaignReturnValue result = campaignService.mutate(new CampaignOperation[] { op });
return result.getValue(0);
}
Aggregations