use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class UsePortfolioBiddingStrategy method createCampaignWithBiddingStrategy.
/**
* Create a Campaign with a portfolio bidding strategy.
*
* @param adWordsServices the user to run the example with
* @param session the AdWordsSession
* @param biddingStrategyId the bidding strategy id to use
* @param sharedBudgetId the shared budget id to use
* @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 Campaign createCampaignWithBiddingStrategy(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long biddingStrategyId, Long sharedBudgetId) throws RemoteException {
// Get the CampaignService, which loads the required classes.
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
// Create campaign.
Campaign campaign = new Campaign();
campaign.setName("Interplanetary Cruise #" + 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 budget.
Budget budget = new Budget();
budget.setBudgetId(sharedBudgetId);
campaign.setBudget(budget);
// Set bidding strategy (required).
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
biddingStrategyConfiguration.setBiddingStrategyId(biddingStrategyId);
campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
// Set advertising channel type (required).
campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);
// Set network targeting (recommended).
NetworkSetting networkSetting = new NetworkSetting();
networkSetting.setTargetGoogleSearch(true);
networkSetting.setTargetSearchNetwork(true);
networkSetting.setTargetContentNetwork(true);
campaign.setNetworkSetting(networkSetting);
// Create operation.
CampaignOperation operation = new CampaignOperation();
operation.setOperand(campaign);
operation.setOperator(Operator.ADD);
CampaignReturnValue result = campaignService.mutate(new CampaignOperation[] { operation });
Campaign newCampaign = result.getValue(0);
System.out.printf("Campaign with name '%s', ID %d and bidding scheme ID %d was created.%n", newCampaign.getName(), newCampaign.getId(), newCampaign.getBiddingStrategyConfiguration().getBiddingStrategyId());
return newCampaign;
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation 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.axis.v201809.cm.Operation in project googleads-java-lib by googleads.
the class RemoveCampaign method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param campaignId the ID of the campaign to remove.
* @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 CampaignService.
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
// Create campaign with REMOVED status.
Campaign campaign = new Campaign();
campaign.setId(campaignId);
campaign.setStatus(CampaignStatus.REMOVED);
// Create operations.
CampaignOperation operation = new CampaignOperation();
operation.setOperand(campaign);
operation.setOperator(Operator.SET);
CampaignOperation[] operations = new CampaignOperation[] { operation };
// Remove campaign.
CampaignReturnValue result = campaignService.mutate(operations);
// Display campaigns.
for (Campaign campaignResult : result.getValue()) {
System.out.printf("Campaign with name '%s' and ID %d was removed.%n", campaignResult.getName(), campaignResult.getId());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.Operation 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.axis.v201809.cm.Operation 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());
}
Aggregations