use of com.google.api.ads.adwords.axis.v201809.cm.Campaign in project googleads-java-lib by googleads.
the class AddShoppingDynamicRemarketingCampaign method createCampaign.
/**
* Creates a Shopping dynamic remarketing campaign object (not including ad group level and
* below). This creates a Display campaign with the merchant center feed attached. Merchant Center
* is used for the product information in combination with a user list which contains hits with
* {@code ecomm_prodid} specified. See <a
* href="https://developers.google.com/adwords-remarketing-tag/parameters#retail"/>for more
* detail.
*
* @param merchantId the ID of the Merchant Center account.
* @param budgetId the ID of the budget to use for the campaign.
* @return the campaign that was created.
*/
private static Campaign createCampaign(AdWordsServicesInterface services, AdWordsSession session, long merchantId, long budgetId) throws RemoteException {
CampaignServiceInterface campaignService = services.get(session, CampaignServiceInterface.class);
Campaign campaign = new Campaign();
campaign.setName("Shopping campaign #" + System.currentTimeMillis());
// Dynamic remarketing campaigns are only available on the Google Display Network.
campaign.setAdvertisingChannelType(AdvertisingChannelType.DISPLAY);
campaign.setStatus(CampaignStatus.PAUSED);
Budget budget = new Budget();
budget.setBudgetId(budgetId);
campaign.setBudget(budget);
// This example uses a Manual CPC bidding strategy, but you should select the strategy that best
// aligns with your sales goals. More details here:
// https://support.google.com/adwords/answer/2472725
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.MANUAL_CPC);
campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
ShoppingSetting setting = new ShoppingSetting();
// Campaigns with numerically higher priorities take precedence over those with lower
// priorities.
setting.setCampaignPriority(0);
// Set the Merchant Center account ID from which to source products.
setting.setMerchantId(merchantId);
// Display Network campaigns do not support partition by country. The only supported value is
// "ZZ". This signals that products from all countries are available in the campaign. The actual
// products which serve are based on the products tagged in the user list entry.
setting.setSalesCountry("ZZ");
// Optional: Enable local inventory ads (items for sale in physical stores.)
setting.setEnableLocal(true);
campaign.setSettings(new Setting[] { setting });
CampaignOperation op = new CampaignOperation();
op.setOperand(campaign);
op.setOperator(Operator.ADD);
CampaignReturnValue result = campaignService.mutate(new CampaignOperation[] { op });
return result.getValue(0);
}
use of com.google.api.ads.adwords.axis.v201809.cm.Campaign 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.Campaign 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.axis.v201809.cm.Campaign in project googleads-java-lib by googleads.
the class AddCampaignGroupsAndPerformanceTargets method addCampaignsToGroup.
/**
* Adds multiple campaigns to a campaign group.
*/
private static void addCampaignsToGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, CampaignGroup campaignGroup, List<Long> campaignIds) throws ApiException, RemoteException {
// Get the CampaignService.
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
List<CampaignOperation> operations = new ArrayList<>();
for (Long campaignId : campaignIds) {
Campaign campaign = new Campaign();
campaign.setId(campaignId);
campaign.setCampaignGroupId(campaignGroup.getId());
CampaignOperation operation = new CampaignOperation();
operation.setOperand(campaign);
operation.setOperator(Operator.SET);
operations.add(operation);
}
CampaignReturnValue returnValue = campaignService.mutate(operations.toArray(new CampaignOperation[operations.size()]));
System.out.printf("The following campaign IDs were added to the campaign group with ID %d:%n", campaignGroup.getId());
for (Campaign campaign : returnValue.getValue()) {
System.out.printf("\t%d%n", campaign.getId());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.Campaign in project googleads-java-lib by googleads.
the class AddCampaignGroupsAndPerformanceTargets method createCampaignGroup.
/**
* Creates a campaign group.
*/
private static CampaignGroup createCampaignGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
// Get the CampaignGroupService.
CampaignGroupServiceInterface campaignGroupService = adWordsServices.get(session, CampaignGroupServiceInterface.class);
// Create the campaign group.
CampaignGroup campaignGroup = new CampaignGroup();
campaignGroup.setName("Mars campaign group #" + System.currentTimeMillis());
// Create the operation.
CampaignGroupOperation operation = new CampaignGroupOperation();
operation.setOperand(campaignGroup);
operation.setOperator(Operator.ADD);
CampaignGroup newCampaignGroup = campaignGroupService.mutate(new CampaignGroupOperation[] { operation }).getValue(0);
System.out.printf("Campaign group with ID %d and name '%s' was created.%n", newCampaignGroup.getId(), newCampaignGroup.getName());
return newCampaignGroup;
}
Aggregations