use of com.google.api.ads.adwords.axis.v201809.cm.Feed 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());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.Feed 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);
}
use of com.google.api.ads.adwords.axis.v201809.cm.Feed 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.Feed in project googleads-java-lib by googleads.
the class AddDynamicPageFeed method createFeed.
/**
* Creates the feed for DSA page URLs.
*/
private static DSAFeedDetails createFeed(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws ApiException, RemoteException {
// Get the FeedService.
FeedServiceInterface feedService = adWordsServices.get(session, FeedServiceInterface.class);
// Create attributes.
FeedAttribute urlAttribute = new FeedAttribute();
urlAttribute.setType(FeedAttributeType.URL_LIST);
urlAttribute.setName("Page URL");
FeedAttribute labelAttribute = new FeedAttribute();
labelAttribute.setType(FeedAttributeType.STRING_LIST);
labelAttribute.setName("Label");
// Create the feed.
Feed dsaPageFeed = new Feed();
dsaPageFeed.setName("DSA Feed #" + System.currentTimeMillis());
dsaPageFeed.setAttributes(new FeedAttribute[] { urlAttribute, labelAttribute });
dsaPageFeed.setOrigin(FeedOrigin.USER);
// Create operation.
FeedOperation operation = new FeedOperation();
operation.setOperand(dsaPageFeed);
operation.setOperator(Operator.ADD);
// Add the feed.
Feed newFeed = feedService.mutate(new FeedOperation[] { operation }).getValue(0);
DSAFeedDetails feedDetails = new DSAFeedDetails();
feedDetails.feedId = newFeed.getId();
FeedAttribute[] savedAttributes = newFeed.getAttributes();
feedDetails.urlAttributeId = savedAttributes[0].getId();
feedDetails.labelAttributeId = savedAttributes[1].getId();
System.out.printf("Feed with name '%s' and ID %d with urlAttributeId %d" + " and labelAttributeId %d was created.%n", newFeed.getName(), feedDetails.feedId, feedDetails.urlAttributeId, feedDetails.labelAttributeId);
return feedDetails;
}
use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.
the class AddExpandedTextAdWithUpgradedUrls method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group where the ad 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 adGroupId) throws RemoteException {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
// Create expanded text ad with a tracking template and custom parameters.
ExpandedTextAd expandedTextAd = new ExpandedTextAd();
expandedTextAd.setHeadlinePart1("Luxury Cruise to Mars");
expandedTextAd.setHeadlinePart2("Visit the Red Planet in style.");
expandedTextAd.setDescription("Low-gravity fun for everyone!");
// Specify a tracking url for 3rd party tracking provider. You may
// specify one at customer, campaign, ad group, ad, criterion or
// feed item levels.
expandedTextAd.setTrackingUrlTemplate("http://tracker.example.com/?season={_season}&promocode={_promocode}&u={lpurl}");
// Since your tracking url has two custom parameters, provide their
// values too. This can be provided at campaign, ad group, ad, criterion
// or feed item levels.
CustomParameter seasonParameter = new CustomParameter();
seasonParameter.setKey("season");
seasonParameter.setValue("christmas");
CustomParameter promoCodeParameter = new CustomParameter();
promoCodeParameter.setKey("promocode");
promoCodeParameter.setValue("NYC123");
CustomParameters trackingUrlParameters = new CustomParameters();
trackingUrlParameters.setParameters(new CustomParameter[] { seasonParameter, promoCodeParameter });
expandedTextAd.setUrlCustomParameters(trackingUrlParameters);
// Specify a list of final urls. This field cannot be set if url field is
// set. This may be specified at ad, criterion, and feed item levels.
expandedTextAd.setFinalUrls(new String[] { "http://www.example.com/cruise/space/", "http://www.example.com/locations/mars/" });
// Specify a list of final mobile urls. This field cannot be set if url field is
// set or finalUrls is not set. This may be specified at ad, criterion, and feed
// item levels.
expandedTextAd.setFinalMobileUrls(new String[] { "http://mobile.example.com/cruise/space/", "http://mobile.example.com/locations/mars/" });
// Create ad group ad.
AdGroupAd textAdGroupAd = new AdGroupAd();
textAdGroupAd.setAdGroupId(adGroupId);
textAdGroupAd.setAd(expandedTextAd);
// Optional: Set status.
textAdGroupAd.setStatus(AdGroupAdStatus.PAUSED);
// Create operation.
AdGroupAdOperation textAdGroupAdOperation = new AdGroupAdOperation();
textAdGroupAdOperation.setOperand(textAdGroupAd);
textAdGroupAdOperation.setOperator(Operator.ADD);
AdGroupAdOperation[] operations = new AdGroupAdOperation[] { textAdGroupAdOperation };
// Add ad.
AdGroupAd adGroupAdResult = adGroupAdService.mutate(operations).getValue(0);
// Display ad.
System.out.printf("Ad with ID %d and tracking URL template '%s' was added.", adGroupAdResult.getAd().getId(), adGroupAdResult.getAd().getTrackingUrlTemplate());
}
Aggregations