use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AddDynamicPageFeed method createDsaUrlAddOperation.
/**
* Creates a {@link FeedItemOperation} to add the DSA URL.
*/
private static FeedItemOperation createDsaUrlAddOperation(DSAFeedDetails feedDetails, String url, String labelName) {
// Create the FeedItemAttributeValues for the URL and label.
FeedItemAttributeValue urlAttributeValue = new FeedItemAttributeValue();
urlAttributeValue.setFeedAttributeId(feedDetails.urlAttributeId);
// See https://support.google.com/adwords/answer/7166527 for page feed URL recommendations and
// rules.
urlAttributeValue.setStringValues(new String[] { url });
FeedItemAttributeValue labelAttributeValue = new FeedItemAttributeValue();
labelAttributeValue.setFeedAttributeId(feedDetails.labelAttributeId);
labelAttributeValue.setStringValues(new String[] { labelName });
// Create the feed item and operation.
FeedItem feedItem = new FeedItem();
feedItem.setFeedId(feedDetails.feedId);
feedItem.setAttributeValues(new FeedItemAttributeValue[] { urlAttributeValue, labelAttributeValue });
FeedItemOperation operation = new FeedItemOperation();
operation.setOperand(feedItem);
operation.setOperator(Operator.ADD);
return operation;
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AddDynamicPageFeed method createFeedMapping.
/**
* Creates the feed mapping for the DSA page feeds.
*/
private static void createFeedMapping(AdWordsServicesInterface adWordsServices, AdWordsSession session, DSAFeedDetails feedDetails) throws RemoteException {
// Get the FeedMappingService.
FeedMappingServiceInterface feedMappingService = adWordsServices.get(session, FeedMappingServiceInterface.class);
// Map the FeedAttributeIds to the fieldId constants.
AttributeFieldMapping urlFieldMapping = new AttributeFieldMapping();
urlFieldMapping.setFeedAttributeId(feedDetails.urlAttributeId);
urlFieldMapping.setFieldId(DSA_PAGE_URLS_FIELD_ID);
AttributeFieldMapping labelFieldMapping = new AttributeFieldMapping();
labelFieldMapping.setFeedAttributeId(feedDetails.labelAttributeId);
labelFieldMapping.setFieldId(DSA_LABEL_FIELD_ID);
// Create the FeedMapping and operation.
FeedMapping feedMapping = new FeedMapping();
feedMapping.setCriterionType(DSA_PAGE_FEED_CRITERION_TYPE);
feedMapping.setFeedId(feedDetails.feedId);
feedMapping.setAttributeFieldMappings(new AttributeFieldMapping[] { urlFieldMapping, labelFieldMapping });
FeedMappingOperation operation = new FeedMappingOperation();
operation.setOperand(feedMapping);
operation.setOperator(Operator.ADD);
// Add the field mapping.
FeedMapping newFeedMapping = feedMappingService.mutate(new FeedMappingOperation[] { operation }).getValue(0);
System.out.printf("Feed mapping with ID %d and criterionType %d was saved for feed with ID %d.%n", newFeedMapping.getFeedMappingId(), newFeedMapping.getCriterionType(), newFeedMapping.getFeedId());
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AddUniversalAppCampaign method setCampaignTargetingCriteria.
/**
* Sets the campaign's targeting criteria.
*/
private static void setCampaignTargetingCriteria(Campaign campaign, AdWordsServicesInterface adWordsServices, AdWordsSession session) throws ApiException, RemoteException {
// Get the CampaignCriterionService.
CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
// Create locations. The IDs can be found in the documentation or
// retrieved with the LocationCriterionService.
Location california = new Location();
california.setId(21137L);
Location mexico = new Location();
mexico.setId(2484L);
// Create languages. The IDs can be found in the documentation or
// retrieved with the ConstantDataService.
Language english = new Language();
english.setId(1000L);
Language spanish = new Language();
spanish.setId(1003L);
List<Criterion> criteria = new ArrayList<>(Arrays.asList(california, mexico, english, spanish));
// Create operations to add each of the criteria above.
List<CampaignCriterionOperation> operations = new ArrayList<>();
for (Criterion criterion : criteria) {
CampaignCriterionOperation operation = new CampaignCriterionOperation();
CampaignCriterion campaignCriterion = new CampaignCriterion();
campaignCriterion.setCampaignId(campaign.getId());
campaignCriterion.setCriterion(criterion);
operation.setOperand(campaignCriterion);
operation.setOperator(Operator.ADD);
operations.add(operation);
}
// Set the campaign targets.
CampaignCriterionReturnValue returnValue = campaignCriterionService.mutate(operations.toArray(new CampaignCriterionOperation[operations.size()]));
if (returnValue != null && returnValue.getValue() != null) {
// Display added campaign targets.
for (CampaignCriterion campaignCriterion : returnValue.getValue()) {
System.out.printf("Campaign criteria of type '%s' and ID %d was added.%n", campaignCriterion.getCriterion().getCriterionType(), campaignCriterion.getCriterion().getId());
}
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class AddUniversalAppCampaign method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @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) throws RemoteException {
// Get the CampaignService.
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
// Create the campaign.
Campaign campaign = new Campaign();
campaign.setName("Interplanetary Cruise App #" + System.currentTimeMillis());
// 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 the advertising channel and subchannel types for universal app campaigns.
campaign.setAdvertisingChannelType(AdvertisingChannelType.MULTI_CHANNEL);
campaign.setAdvertisingChannelSubType(AdvertisingChannelSubType.UNIVERSAL_APP_CAMPAIGN);
// Set the campaign's bidding strategy. universal app campaigns
// only support TARGET_CPA bidding strategy.
BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
biddingConfig.setBiddingStrategyType(BiddingStrategyType.TARGET_CPA);
// Set the target CPA to $1 / app install.
TargetCpaBiddingScheme biddingScheme = new TargetCpaBiddingScheme();
biddingScheme.setTargetCpa(new Money());
biddingScheme.getTargetCpa().setMicroAmount(1000000L);
biddingConfig.setBiddingScheme(biddingScheme);
campaign.setBiddingStrategyConfiguration(biddingConfig);
// Set the campaign's budget.
campaign.setBudget(new Budget());
campaign.getBudget().setBudgetId(createBudget(adWordsServices, session));
// 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"));
// Set the campaign's assets and ad text ideas. These values will be used to
// generate ads.
UniversalAppCampaignSetting universalAppSetting = new UniversalAppCampaignSetting();
universalAppSetting.setAppId("com.labpixies.colordrips");
universalAppSetting.setAppVendor(MobileApplicationVendor.VENDOR_GOOGLE_MARKET);
universalAppSetting.setDescription1("A cool puzzle game");
universalAppSetting.setDescription2("Remove connected blocks");
universalAppSetting.setDescription3("3 difficulty levels");
universalAppSetting.setDescription4("4 colorful fun skins");
// Optional: You can set up to 20 image assets for your campaign.
// See UploadImage.java for an example on how to upload images.
//
// universalAppSetting.setImageMediaIds(new long[] { INSERT_IMAGE_MEDIA_ID_HERE });
// Optimize this campaign for getting new users for your app.
universalAppSetting.setUniversalAppBiddingStrategyGoalType(UniversalAppBiddingStrategyGoalType.OPTIMIZE_FOR_INSTALL_CONVERSION_VOLUME);
// If you select the OPTIMIZE_FOR_IN_APP_CONVERSION_VOLUME goal type, then also specify
// your in-app conversion types so AdWords can focus your campaign on people who are
// most likely to complete the corresponding in-app actions.
// Conversion type IDs can be retrieved using ConversionTrackerService.get.
//
// campaign.selectiveOptimization = new SelectiveOptimization();
// campaign.selectiveOptimization.conversionTypeIds =
// new long[] { INSERT_CONVERSION_TYPE_ID_1_HERE, INSERT_CONVERSION_TYPE_ID_2_HERE };
// Optional: Set the campaign settings for Advanced location options.
GeoTargetTypeSetting geoSetting = new GeoTargetTypeSetting();
geoSetting.setPositiveGeoTargetType(GeoTargetTypeSettingPositiveGeoTargetType.LOCATION_OF_PRESENCE);
geoSetting.setNegativeGeoTargetType(GeoTargetTypeSettingNegativeGeoTargetType.DONT_CARE);
campaign.setSettings(new Setting[] { universalAppSetting, geoSetting });
// Create the operation.
CampaignOperation operation = new CampaignOperation();
operation.setOperand(campaign);
operation.setOperator(Operator.ADD);
CampaignOperation[] operations = new CampaignOperation[] { operation };
// Add the campaign.
CampaignReturnValue result = campaignService.mutate(operations);
// Display the results.
for (Campaign newCampaign : result.getValue()) {
System.out.printf("Universal app campaign with name '%s' and ID %d was added.%n", newCampaign.getName(), newCampaign.getId());
// Optional: Set the campaign's location and language targeting. No other targeting
// criteria can be used for universal app campaigns.
setCampaignTargetingCriteria(newCampaign, adWordsServices, session);
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class FindAndRemoveCriteriaFromSharedSet method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param campaignId the ID of the campaign to use to find shared sets.
* @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 campaignId) throws RemoteException {
// Get the CampaignSharedSetService.
CampaignSharedSetServiceInterface campaignSharedSetService = adWordsServices.get(session, CampaignSharedSetServiceInterface.class);
// First, retrieve all shared sets associated with the campaign.
int offset = 0;
SelectorBuilder selectorBuilder = new SelectorBuilder().fields(CampaignSharedSetField.SharedSetId, CampaignSharedSetField.CampaignId, CampaignSharedSetField.SharedSetName, CampaignSharedSetField.SharedSetType).equals(CampaignSharedSetField.CampaignId, campaignId.toString()).in(CampaignSharedSetField.SharedSetType, SharedSetType.NEGATIVE_KEYWORDS.getValue(), SharedSetType.NEGATIVE_PLACEMENTS.getValue()).limit(PAGE_SIZE);
List<Long> sharedSetIds = new ArrayList<>();
CampaignSharedSetPage campaignSharedSetPage;
do {
selectorBuilder.offset(offset);
campaignSharedSetPage = campaignSharedSetService.get(selectorBuilder.build());
for (CampaignSharedSet campaignSharedSet : campaignSharedSetPage.getEntries()) {
sharedSetIds.add(campaignSharedSet.getSharedSetId());
System.out.printf("Campaign shared set ID %d and name '%s' found for campaign ID %d.%n", campaignSharedSet.getSharedSetId(), campaignSharedSet.getSharedSetName(), campaignSharedSet.getCampaignId());
}
offset += PAGE_SIZE;
} while (offset < campaignSharedSetPage.getTotalNumEntries());
if (sharedSetIds.isEmpty()) {
System.out.printf("No shared sets found for campaign ID %d.%n", campaignId);
return;
}
// Next, retrieve criterion IDs for all found shared sets.
SharedCriterionServiceInterface sharedCriterionService = adWordsServices.get(session, SharedCriterionServiceInterface.class);
// Transform shared set IDs to strings.
String[] sharedSetIdStrings = Collections2.transform(sharedSetIds, Functions.toStringFunction()).toArray(new String[sharedSetIds.size()]);
offset = 0;
selectorBuilder = new SelectorBuilder().fields("SharedSetId", "Id", "KeywordText", "KeywordMatchType", "PlacementUrl").in("SharedSetId", sharedSetIdStrings).limit(PAGE_SIZE);
List<SharedCriterionOperation> removeCriterionOperations = new ArrayList<>();
SharedCriterionPage sharedCriterionPage;
do {
selectorBuilder.offset(offset);
sharedCriterionPage = sharedCriterionService.get(selectorBuilder.build());
for (SharedCriterion sharedCriterion : sharedCriterionPage.getEntries()) {
if (CriterionType.KEYWORD.equals(sharedCriterion.getCriterion().getType())) {
Keyword keyword = (Keyword) sharedCriterion.getCriterion();
System.out.printf("Shared negative keyword with ID %d and text '%s' was found.%n", keyword.getId(), keyword.getText());
} else if (CriterionType.PLACEMENT.equals(sharedCriterion.getCriterion().getType())) {
Placement placement = (Placement) sharedCriterion.getCriterion();
System.out.printf("Shared negative placement with ID %d and URL '%s' was found.%n", placement.getId(), placement.getUrl());
} else {
System.out.printf("Shared criterion with ID %d was found.%n", sharedCriterion.getCriterion().getId());
}
// Create an operation to remove this criterion.
SharedCriterionOperation removeCriterionOperation = new SharedCriterionOperation();
removeCriterionOperation.setOperator(Operator.REMOVE);
SharedCriterion sharedCriterionToRemove = new SharedCriterion();
Criterion criterionToRemove = new Criterion();
criterionToRemove.setId(sharedCriterion.getCriterion().getId());
sharedCriterionToRemove.setCriterion(criterionToRemove);
sharedCriterionToRemove.setSharedSetId(sharedCriterion.getSharedSetId());
removeCriterionOperation.setOperand(sharedCriterionToRemove);
removeCriterionOperations.add(removeCriterionOperation);
}
offset += PAGE_SIZE;
} while (offset < sharedCriterionPage.getTotalNumEntries());
// Finally, remove the criteria.
if (removeCriterionOperations.isEmpty()) {
System.out.printf("No shared criteria to remove.%n");
} else {
SharedCriterionReturnValue sharedCriterionReturnValue = sharedCriterionService.mutate(removeCriterionOperations.toArray(new SharedCriterionOperation[removeCriterionOperations.size()]));
for (SharedCriterion removedCriterion : sharedCriterionReturnValue.getValue()) {
System.out.printf("Shared criterion ID %d was successfully removed from shared set ID %d.%n", removedCriterion.getCriterion().getId(), removedCriterion.getSharedSetId());
}
}
}
Aggregations