use of com.google.api.ads.adwords.axis.v201809.cm.TargetingSetting in project googleads-java-lib by googleads.
the class AddAdGroups method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param campaignId the ID of the campaign where the ad groups 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 campaignId) throws RemoteException {
// Get the AdGroupService.
AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
// Create ad group.
AdGroup adGroup = new AdGroup();
adGroup.setName("Earth to Mars Cruises #" + System.currentTimeMillis());
adGroup.setStatus(AdGroupStatus.ENABLED);
adGroup.setCampaignId(campaignId);
// Optional settings.
// Targeting restriction settings. Depending on the criterionTypeGroup
// value, most TargetingSettingDetail only affect Display campaigns.
// However, the USER_INTEREST_AND_LIST value works for RLSA campaigns -
// Search campaigns targeting using a remarketing list.
TargetingSetting targeting = new TargetingSetting();
// Restricting to serve ads that match your ad group placements.
// This is equivalent to choosing "Target and bid" in the UI.
TargetingSettingDetail placements = new TargetingSettingDetail();
placements.setCriterionTypeGroup(CriterionTypeGroup.PLACEMENT);
placements.setTargetAll(Boolean.FALSE);
// Using your ad group verticals only for bidding. This is equivalent
// to choosing "Bid only" in the UI.
TargetingSettingDetail verticals = new TargetingSettingDetail();
verticals.setCriterionTypeGroup(CriterionTypeGroup.VERTICAL);
verticals.setTargetAll(Boolean.TRUE);
targeting.setDetails(new TargetingSettingDetail[] { placements, verticals });
adGroup.setSettings(new Setting[] { targeting });
// Set the rotation mode.
AdGroupAdRotationMode rotationMode = new AdGroupAdRotationMode(AdRotationMode.OPTIMIZE);
adGroup.setAdGroupAdRotationMode(rotationMode);
// Create ad group bid.
BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
Money cpcBidMoney = new Money();
cpcBidMoney.setMicroAmount(10_000_000L);
CpcBid bid = new CpcBid();
bid.setBid(cpcBidMoney);
biddingStrategyConfiguration.setBids(new Bids[] { bid });
adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
// Add as many additional ad groups as you need.
AdGroup adGroup2 = new AdGroup();
adGroup2.setName("Earth to Venus Cruises #" + System.currentTimeMillis());
adGroup2.setStatus(AdGroupStatus.ENABLED);
adGroup2.setCampaignId(campaignId);
BiddingStrategyConfiguration biddingStrategyConfiguration2 = new BiddingStrategyConfiguration();
Money cpcBidMoney2 = new Money();
cpcBidMoney2.setMicroAmount(10_000_000L);
CpcBid bid2 = new CpcBid();
bid2.setBid(cpcBidMoney2);
biddingStrategyConfiguration2.setBids(new Bids[] { bid2 });
adGroup2.setBiddingStrategyConfiguration(biddingStrategyConfiguration2);
// Create operations.
AdGroupOperation operation = new AdGroupOperation();
operation.setOperand(adGroup);
operation.setOperator(Operator.ADD);
AdGroupOperation operation2 = new AdGroupOperation();
operation2.setOperand(adGroup2);
operation2.setOperator(Operator.ADD);
AdGroupOperation[] operations = new AdGroupOperation[] { operation, operation2 };
// Add ad groups.
AdGroupReturnValue result = adGroupService.mutate(operations);
// Display new ad groups.
for (AdGroup adGroupResult : result.getValue()) {
System.out.printf("Ad group with name '%s' and ID %d was added.%n", adGroupResult.getName(), adGroupResult.getId());
}
}
Aggregations