use of com.google.api.ads.adwords.axis.v201809.cm.DynamicSearchAdsSetting in project googleads-java-lib by googleads.
the class AddDynamicSearchAdsCampaign method createCampaign.
/**
* Creates the campaign.
*/
private static Campaign createCampaign(AdWordsServicesInterface adWordsServices, AdWordsSession session, Budget budget) throws RemoteException, ApiException {
// Get the CampaignService.
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
// Create campaign.
Campaign campaign = new Campaign();
campaign.setName("Interplanetary Cruise #" + System.currentTimeMillis());
campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);
// 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);
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.MANUAL_CPC);
campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
// Only the budgetId should be sent, all other fields will be ignored by CampaignService.
Budget campaignBudget = new Budget();
campaignBudget.setBudgetId(budget.getBudgetId());
campaign.setBudget(campaignBudget);
// Required: Set the campaign's Dynamic Search Ads settings.
DynamicSearchAdsSetting dynamicSearchAdsSetting = new DynamicSearchAdsSetting();
// Required: Set the domain name and language.
dynamicSearchAdsSetting.setDomainName("example.com");
dynamicSearchAdsSetting.setLanguageCode("en");
// Set the campaign settings.
campaign.setSettings(new Setting[] { dynamicSearchAdsSetting });
// Optional: Set the start date.
campaign.setStartDate(DateTime.now().plusDays(1).toString("yyyyMMdd"));
// Optional: Set the end date.
campaign.setEndDate(DateTime.now().plusYears(1).toString("yyyyMMdd"));
// Create the operation.
CampaignOperation operation = new CampaignOperation();
operation.setOperand(campaign);
operation.setOperator(Operator.ADD);
// Add the campaign.
Campaign newCampaign = campaignService.mutate(new CampaignOperation[] { operation }).getValue(0);
// Display the results.
System.out.printf("Campaign with name '%s' and ID %d was added.%n", newCampaign.getName(), newCampaign.getId());
return newCampaign;
}
use of com.google.api.ads.adwords.axis.v201809.cm.DynamicSearchAdsSetting in project googleads-java-lib by googleads.
the class AddDynamicSearchAdsCampaign method createExpandedDSA.
/**
* Creates the expanded Dynamic Search Ad.
*/
private static void createExpandedDSA(AdWordsServicesInterface adWordsServices, AdWordsSession session, AdGroup adGroup) throws ApiException, RemoteException {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
// Create the expanded Dynamic Search Ad. This ad will have its headline and final URL
// auto-generated at serving time according to domain name specific information provided
// by DynamicSearchAdsSetting at the campaign level.
ExpandedDynamicSearchAd expandedDSA = new ExpandedDynamicSearchAd();
// Set the ad description.
expandedDSA.setDescription("Buy your tickets now!");
expandedDSA.setDescription2("Discount ends soon");
// Create the ad group ad.
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAdGroupId(adGroup.getId());
adGroupAd.setAd(expandedDSA);
// Optional: Set the status.
adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
// Create the operation.
AdGroupAdOperation operation = new AdGroupAdOperation();
operation.setOperator(Operator.ADD);
operation.setOperand(adGroupAd);
// Create the ad.
AdGroupAd newAdGroupAd = adGroupAdService.mutate(new AdGroupAdOperation[] { operation }).getValue(0);
ExpandedDynamicSearchAd newExpandedDSA = (ExpandedDynamicSearchAd) newAdGroupAd.getAd();
System.out.printf("Expanded Dynamic Search Ad with ID %d and description '%s' and description 2 '%s' was " + "added.%n", newExpandedDSA.getId(), newExpandedDSA.getDescription(), newExpandedDSA.getDescription2());
}
use of com.google.api.ads.adwords.axis.v201809.cm.DynamicSearchAdsSetting in project googleads-java-lib by googleads.
the class AddDynamicPageFeed method updateCampaignDsaSetting.
/**
* Updates the campaign DSA setting to add DSA pagefeeds.
*/
private static void updateCampaignDsaSetting(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long campaignId, DSAFeedDetails feedDetails) throws ApiException, RemoteException {
// Get the CampaignService.
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
Selector selector = new SelectorBuilder().fields(CampaignField.Id, CampaignField.Settings).equalsId(campaignId).build();
CampaignPage campaignPage = campaignService.get(selector);
if (campaignPage.getEntries() == null || campaignPage.getTotalNumEntries() == 0) {
throw new IllegalArgumentException("No campaign found with ID: " + campaignId);
}
Campaign campaign = campaignPage.getEntries(0);
if (campaign.getSettings() == null) {
throw new IllegalArgumentException("Campaign with ID " + campaignId + " is not a DSA campaign.");
}
DynamicSearchAdsSetting dsaSetting = (DynamicSearchAdsSetting) Arrays.stream(campaign.getSettings()).filter(DynamicSearchAdsSetting.class::isInstance).findFirst().orElse(null);
if (dsaSetting == null) {
throw new IllegalArgumentException("Campaign with ID " + campaignId + " is not a DSA campaign.");
}
// Use a page feed to specify precisely which URLs to use with your
// Dynamic Search Ads.
PageFeed pageFeed = new PageFeed();
pageFeed.setFeedIds(new long[] { feedDetails.feedId });
dsaSetting.setPageFeed(pageFeed);
// Optional: Specify whether only the supplied URLs should be used with your
// Dynamic Search Ads.
dsaSetting.setUseSuppliedUrlsOnly(true);
Campaign updatedCampaign = new Campaign();
updatedCampaign.setId(campaignId);
updatedCampaign.setSettings(campaign.getSettings());
CampaignOperation operation = new CampaignOperation();
operation.setOperand(updatedCampaign);
operation.setOperator(Operator.SET);
updatedCampaign = campaignService.mutate(new CampaignOperation[] { operation }).getValue(0);
System.out.printf("DSA page feed for campaign ID %d was updated with feed ID %d.%n", updatedCampaign.getId(), feedDetails.feedId);
}
Aggregations