use of com.google.api.ads.adwords.jaxws.v201809.cm.Money in project googleads-java-lib by googleads.
the class UsePortfolioBiddingStrategy method createSharedBudget.
/**
* Creates an explicit budget to be used only to create the Campaign.
*
* @param adWordsServices the user to run the example with
* @param session the AdWordsSession
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
*/
private static Budget createSharedBudget(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
// Get the BudgetService, which loads the required classes.
BudgetServiceInterface budgetService = adWordsServices.get(session, BudgetServiceInterface.class);
// Create a shared budget.
Budget budget = new Budget();
budget.setName("Shared Interplanetary Budget #" + System.currentTimeMillis());
budget.setAmount(new Money(null, 50000000L));
budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
budget.setIsExplicitlyShared(true);
BudgetOperation operation = new BudgetOperation();
operation.setOperand(budget);
operation.setOperator(Operator.ADD);
BudgetOperation[] operations = new BudgetOperation[] { operation };
// Make the mutate request.
BudgetReturnValue result = budgetService.mutate(operations);
Budget newBudget = result.getValue(0);
System.out.printf("Budget with name '%s', ID %d was created.%n", newBudget.getName(), newBudget.getBudgetId());
return newBudget;
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Money in project googleads-java-lib by googleads.
the class UpdateAdGroup method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group to update.
* @param bidMicroAmount the optional bid amount in micros to use for the ad group bid.
* @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, @Nullable Long bidMicroAmount) throws RemoteException {
// Get the AdGroupService.
AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
// Create an ad group with the specified ID.
AdGroup adGroup = new AdGroup();
adGroup.setId(adGroupId);
// Update the CPC bid if specified.
if (bidMicroAmount != null) {
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
Money cpcBidMoney = new Money();
cpcBidMoney.setMicroAmount(bidMicroAmount);
CpcBid cpcBid = new CpcBid();
cpcBid.setBid(cpcBidMoney);
biddingStrategyConfiguration.setBids(new Bids[] { cpcBid });
adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
}
// Pause the ad group.
adGroup.setStatus(AdGroupStatus.PAUSED);
// Create operations.
AdGroupOperation operation = new AdGroupOperation();
operation.setOperand(adGroup);
operation.setOperator(Operator.SET);
AdGroupOperation[] operations = new AdGroupOperation[] { operation };
// Update ad group.
AdGroupReturnValue result = adGroupService.mutate(operations);
// Display ad groups.
for (AdGroup adGroupResult : result.getValue()) {
BiddingStrategyConfiguration biddingStrategyConfiguration = adGroupResult.getBiddingStrategyConfiguration();
// Find the CpcBid in the bidding strategy configuration's bids collection.
Long cpcBidMicros = null;
if (biddingStrategyConfiguration != null) {
if (biddingStrategyConfiguration.getBids() != null) {
for (Bids bid : biddingStrategyConfiguration.getBids()) {
if (bid instanceof CpcBid) {
cpcBidMicros = ((CpcBid) bid).getBid().getMicroAmount();
break;
}
}
}
}
System.out.printf("Ad group with ID %d and name '%s' updated to have status '%s' and CPC bid %d%n", adGroupResult.getId(), adGroupResult.getName(), adGroupResult.getStatus(), cpcBidMicros);
}
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Money in project googleads-java-lib by googleads.
the class AddCampaignGroupsAndPerformanceTargets method createPerformanceTarget.
/**
* Creates a performance target for the campaign group.
*/
private static void createPerformanceTarget(AdWordsServicesInterface adWordsServices, AdWordsSession session, CampaignGroup campaignGroup) throws ApiException, RemoteException {
// Get the CampaignGroupPerformanceTargetService.
CampaignGroupPerformanceTargetServiceInterface campaignGroupPerformanceTargetService = adWordsServices.get(session, CampaignGroupPerformanceTargetServiceInterface.class);
// Create the performance target.
CampaignGroupPerformanceTarget campaignGroupPerformanceTarget = new CampaignGroupPerformanceTarget();
campaignGroupPerformanceTarget.setCampaignGroupId(campaignGroup.getId());
PerformanceTarget performanceTarget = new PerformanceTarget();
// Keep the CPC for the campaigns < $3.
performanceTarget.setEfficiencyTargetType(EfficiencyTargetType.CPC_LESS_THAN_OR_EQUAL_TO);
performanceTarget.setEfficiencyTargetValue(3000000d);
// Keep the maximum spend under $50.
performanceTarget.setSpendTargetType(SpendTargetType.MAXIMUM);
Money maxSpend = new Money();
maxSpend.setMicroAmount(500000000L);
performanceTarget.setSpendTarget(maxSpend);
// Aim for at least 3000 clicks.
performanceTarget.setVolumeTargetValue(3000L);
performanceTarget.setVolumeGoalType(VolumeGoalType.MAXIMIZE_CLICKS);
// Start the performance target today, and run it for the next 90 days.
DateTime startDate = DateTime.now();
DateTime endDate = DateTime.now().plusDays(90);
performanceTarget.setStartDate(startDate.toString("yyyyMMdd"));
performanceTarget.setEndDate(endDate.toString("yyyyMMdd"));
campaignGroupPerformanceTarget.setPerformanceTarget(performanceTarget);
// Create the operation.
CampaignGroupPerformanceTargetOperation operation = new CampaignGroupPerformanceTargetOperation();
operation.setOperand(campaignGroupPerformanceTarget);
operation.setOperator(Operator.ADD);
CampaignGroupPerformanceTarget newCampaignGroupPerformanceTarget = campaignGroupPerformanceTargetService.mutate(new CampaignGroupPerformanceTargetOperation[] { operation }).getValue(0);
// Display the results.
System.out.printf("Campaign group performance target with ID %d was added for campaign group ID %d.%n", newCampaignGroupPerformanceTarget.getId(), newCampaignGroupPerformanceTarget.getCampaignGroupId());
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Money in project googleads-java-lib by googleads.
the class EstimateKeywordTraffic 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 TrafficEstimatorService.
TrafficEstimatorServiceInterface trafficEstimatorService = adWordsServices.get(session, TrafficEstimatorServiceInterface.class);
// Create keywords. Refer to the TrafficEstimatorService documentation for the maximum
// number of keywords that can be passed in a single request.
// https://developers.google.com/adwords/api/docs/reference/latest/TrafficEstimatorService
List<Keyword> keywords = new ArrayList<Keyword>();
Keyword marsCruiseKeyword = new Keyword();
marsCruiseKeyword.setText("mars cruise");
marsCruiseKeyword.setMatchType(KeywordMatchType.BROAD);
keywords.add(marsCruiseKeyword);
Keyword cheapCruiseKeyword = new Keyword();
cheapCruiseKeyword.setText("cheap cruise");
cheapCruiseKeyword.setMatchType(KeywordMatchType.PHRASE);
keywords.add(cheapCruiseKeyword);
Keyword cruiseKeyword = new Keyword();
cruiseKeyword.setText("cruise");
cruiseKeyword.setMatchType(KeywordMatchType.EXACT);
keywords.add(cruiseKeyword);
// Create a keyword estimate request for each keyword.
List<KeywordEstimateRequest> keywordEstimateRequests = keywords.stream().map(keyword -> {
KeywordEstimateRequest keywordEstimateRequest = new KeywordEstimateRequest();
keywordEstimateRequest.setKeyword(keyword);
return keywordEstimateRequest;
}).collect(Collectors.toList());
// Add a negative keyword to the traffic estimate.
KeywordEstimateRequest negativeKeywordEstimateRequest = new KeywordEstimateRequest();
negativeKeywordEstimateRequest.setKeyword(new Keyword(null, null, null, "hiking tour", KeywordMatchType.BROAD));
negativeKeywordEstimateRequest.setIsNegative(true);
keywordEstimateRequests.add(negativeKeywordEstimateRequest);
// Create ad group estimate requests.
List<AdGroupEstimateRequest> adGroupEstimateRequests = new ArrayList<AdGroupEstimateRequest>();
AdGroupEstimateRequest adGroupEstimateRequest = new AdGroupEstimateRequest();
adGroupEstimateRequest.setKeywordEstimateRequests(keywordEstimateRequests.toArray(new KeywordEstimateRequest[] {}));
adGroupEstimateRequest.setMaxCpc(new Money(null, 1000000L));
adGroupEstimateRequests.add(adGroupEstimateRequest);
// Create campaign estimate requests.
List<CampaignEstimateRequest> campaignEstimateRequests = new ArrayList<CampaignEstimateRequest>();
CampaignEstimateRequest campaignEstimateRequest = new CampaignEstimateRequest();
campaignEstimateRequest.setAdGroupEstimateRequests(adGroupEstimateRequests.toArray(new AdGroupEstimateRequest[] {}));
Location unitedStates = new Location();
unitedStates.setId(2840L);
Language english = new Language();
english.setId(1000L);
campaignEstimateRequest.setCriteria(new Criterion[] { unitedStates, english });
campaignEstimateRequests.add(campaignEstimateRequest);
// Create selector.
TrafficEstimatorSelector selector = new TrafficEstimatorSelector();
selector.setCampaignEstimateRequests(campaignEstimateRequests.toArray(new CampaignEstimateRequest[] {}));
// Optional: Request a list of campaign level estimates segmented by platform.
selector.setPlatformEstimateRequested(true);
// Get traffic estimates.
TrafficEstimatorResult result = trafficEstimatorService.get(selector);
// Display traffic estimates.
if (result != null && result.getCampaignEstimates() != null && result.getCampaignEstimates().length > 0) {
CampaignEstimate campaignEstimate = result.getCampaignEstimates()[0];
// Display the campaign level estimates segmented by platform.
if (campaignEstimate.getPlatformEstimates() != null) {
for (PlatformCampaignEstimate platformEstimate : campaignEstimate.getPlatformEstimates()) {
String platformMessage = String.format("Results for the platform with ID %d and name '%s':%n", platformEstimate.getPlatform().getId(), platformEstimate.getPlatform().getPlatformName());
displayMeanEstimates(platformMessage, platformEstimate.getMinEstimate(), platformEstimate.getMaxEstimate());
}
}
// Display the keyword estimates.
KeywordEstimate[] keywordEstimates = campaignEstimate.getAdGroupEstimates()[0].getKeywordEstimates();
for (int i = 0; i < keywordEstimates.length; i++) {
if (Boolean.TRUE.equals(keywordEstimateRequests.get(i).getIsNegative())) {
continue;
}
Keyword keyword = keywordEstimateRequests.get(i).getKeyword();
KeywordEstimate keywordEstimate = keywordEstimates[i];
String keywordMessage = String.format("Results for the keyword with text '%s' and match type '%s':%n", keyword.getText(), keyword.getMatchType());
displayMeanEstimates(keywordMessage, keywordEstimate.getMin(), keywordEstimate.getMax());
}
} else {
System.out.println("No traffic estimates were returned.");
}
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Money in project googleads-java-lib by googleads.
the class UpdateKeyword method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group for the criterion.
* @param keywordId the ID of the criterion to update.
* @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, Long keywordId) throws RemoteException {
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
// Create ad group criterion with updated bid.
Criterion criterion = new Criterion();
criterion.setId(keywordId);
BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
biddableAdGroupCriterion.setAdGroupId(adGroupId);
biddableAdGroupCriterion.setCriterion(criterion);
// Create bids.
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
CpcBid bid = new CpcBid();
bid.setBid(new Money(null, 10000000L));
biddingStrategyConfiguration.setBids(new Bids[] { bid });
biddableAdGroupCriterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
// Create operations.
AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
operation.setOperand(biddableAdGroupCriterion);
operation.setOperator(Operator.SET);
AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] { operation };
// Update ad group criteria.
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
// Display ad group criteria.
for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
if (adGroupCriterionResult instanceof BiddableAdGroupCriterion) {
biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult;
CpcBid criterionCpcBid = null;
// Find the criterion-level CpcBid among the keyword's bids.
for (Bids bids : biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids()) {
if (bids instanceof CpcBid) {
CpcBid cpcBid = (CpcBid) bids;
if (BidSource.CRITERION.equals(cpcBid.getCpcBidSource())) {
criterionCpcBid = cpcBid;
}
}
}
System.out.printf("Ad group criterion with ad group ID %d, criterion ID %d, type " + "'%s', and bid %d was updated.%n", biddableAdGroupCriterion.getAdGroupId(), biddableAdGroupCriterion.getCriterion().getId(), biddableAdGroupCriterion.getCriterion().getCriterionType(), criterionCpcBid.getBid().getMicroAmount());
}
}
}
Aggregations