use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface in project googleads-java-lib by googleads.
the class AddDynamicSearchAdsCampaign method createAdGroup.
/**
* Creates the ad group.
*/
private static AdGroup createAdGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, Campaign campaign) throws ApiException, RemoteException {
// Get the AdGroupService.
AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
// Create the ad group.
AdGroup adGroup = new AdGroup();
// Required: Set the ad group's type to Dynamic Search Ads.
adGroup.setAdGroupType(AdGroupType.SEARCH_DYNAMIC_ADS);
adGroup.setName("Earth to Mars Cruises #" + System.currentTimeMillis());
adGroup.setCampaignId(campaign.getId());
adGroup.setStatus(AdGroupStatus.PAUSED);
// Recommended: Set a tracking URL template for your ad group if you want to use URL
// tracking software.
adGroup.setTrackingUrlTemplate("http://tracker.example.com/traveltracker/{escapedlpurl}");
// Set the ad group bids.
BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
CpcBid cpcBid = new CpcBid();
cpcBid.setBid(new Money());
cpcBid.getBid().setMicroAmount(3000000L);
biddingConfig.setBids(new Bids[] { cpcBid });
adGroup.setBiddingStrategyConfiguration(biddingConfig);
// Create the operation.
AdGroupOperation operation = new AdGroupOperation();
operation.setOperand(adGroup);
operation.setOperator(Operator.ADD);
AdGroup newAdGroup = adGroupService.mutate(new AdGroupOperation[] { operation }).getValue(0);
System.out.printf("Ad group with name '%s' and ID %d was added.%n", newAdGroup.getName(), newAdGroup.getId());
return newAdGroup;
}
use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface in project googleads-java-lib by googleads.
the class GetAdGroups 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 ad groups.
* @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);
int offset = 0;
boolean morePages = true;
// Create selector.
SelectorBuilder builder = new SelectorBuilder();
Selector selector = builder.fields(AdGroupField.Id, AdGroupField.Name).orderAscBy(AdGroupField.Name).offset(offset).limit(PAGE_SIZE).equals(AdGroupField.CampaignId, campaignId.toString()).build();
while (morePages) {
// Get all ad groups.
AdGroupPage page = adGroupService.get(selector);
// Display ad groups.
if (page.getEntries() != null) {
for (AdGroup adGroup : page.getEntries()) {
System.out.printf("Ad group with name '%s' and ID %d was found.%n", adGroup.getName(), adGroup.getId());
}
} else {
System.out.println("No ad groups were found.");
}
offset += PAGE_SIZE;
selector = builder.increaseOffsetBy(PAGE_SIZE).build();
morePages = offset < page.getTotalNumEntries();
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface in project googleads-java-lib by googleads.
the class AddShoppingDynamicRemarketingCampaign method createAdGroup.
/**
* Creates an ad group in the specified campaign.
*
* @param campaign the campaign to which the ad group should be attached.
* @return the ad group that was created.
*/
private static AdGroup createAdGroup(AdWordsServicesInterface services, AdWordsSession session, Campaign campaign) throws RemoteException {
AdGroupServiceInterface adGroupService = services.get(session, AdGroupServiceInterface.class);
AdGroup group = new AdGroup();
group.setName("Dynamic remarketing ad group");
group.setCampaignId(campaign.getId());
group.setStatus(AdGroupStatus.ENABLED);
AdGroupOperation op = new AdGroupOperation();
op.setOperand(group);
op.setOperator(Operator.ADD);
AdGroupReturnValue result = adGroupService.mutate(new AdGroupOperation[] { op });
return result.getValue(0);
}
use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface in project googleads-java-lib by googleads.
the class RemoveAdGroup method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group 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 adGroupId) throws RemoteException {
// Get the AdGroupService.
AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
// Create ad group with REMOVED status.
AdGroup adGroup = new AdGroup();
adGroup.setId(adGroupId);
adGroup.setStatus(AdGroupStatus.REMOVED);
// Create operations.
AdGroupOperation operation = new AdGroupOperation();
operation.setOperand(adGroup);
operation.setOperator(Operator.SET);
AdGroupOperation[] operations = new AdGroupOperation[] { operation };
// Remove ad group.
AdGroupReturnValue result = adGroupService.mutate(operations);
// Display ad groups.
for (AdGroup adGroupResult : result.getValue()) {
System.out.printf("Ad group with name '%s' and ID %d was removed.%n", adGroupResult.getName(), adGroupResult.getId());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface in project googleads-java-lib by googleads.
the class AddSmartShoppingAd method createSmartShoppingAdGroup.
/**
* Creates a Smart Shopping ad group by setting the ad group type to SHOPPING_GOAL_OPTIMIZED_ADS.
*/
private static AdGroup createSmartShoppingAdGroup(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.setCampaignId(campaignId);
adGroup.setName("Smart Shopping ad group #" + System.currentTimeMillis());
// Set the ad group type to SHOPPING_GOAL_OPTIMIZED_ADS.
adGroup.setAdGroupType(AdGroupType.SHOPPING_GOAL_OPTIMIZED_ADS);
// Create operation.
AdGroupOperation adGroupOperation = new AdGroupOperation();
adGroupOperation.setOperand(adGroup);
adGroupOperation.setOperator(Operator.ADD);
// Make the mutate request.
AdGroupReturnValue adGroupAddResult = adGroupService.mutate(new AdGroupOperation[] { adGroupOperation });
// Display result.
adGroup = adGroupAddResult.getValue(0);
System.out.printf("Smart Shopping ad group with name '%s' and ID %d was added.%n", adGroup.getName(), adGroup.getId());
return adGroup;
}
Aggregations