Search in sources :

Example 1 with AdGroupCriterionServiceInterface

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface in project googleads-java-lib by googleads.

the class AddDynamicSearchAdsCampaign method addWebPageCriteria.

/**
 * Adds a web page criteria to target Dynamic Search Ads.
 */
private static void addWebPageCriteria(AdWordsServicesInterface adWordsServices, AdWordsSession session, AdGroup adGroup) throws ApiException, RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    // Create a webpage criterion for special offers.
    WebpageParameter param = new WebpageParameter();
    param.setCriterionName("Special offers");
    WebpageCondition urlCondition = new WebpageCondition();
    urlCondition.setOperand(WebpageConditionOperand.URL);
    urlCondition.setArgument("/specialoffers");
    WebpageCondition titleCondition = new WebpageCondition();
    titleCondition.setOperand(WebpageConditionOperand.PAGE_TITLE);
    titleCondition.setArgument("Special Offer");
    param.setConditions(new WebpageCondition[] { urlCondition, titleCondition });
    Webpage webpage = new Webpage();
    webpage.setParameter(param);
    // Create biddable ad group criterion.
    BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
    biddableAdGroupCriterion.setAdGroupId(adGroup.getId());
    biddableAdGroupCriterion.setCriterion(webpage);
    biddableAdGroupCriterion.setUserStatus(UserStatus.PAUSED);
    // Optional: set a custom bid.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    CpcBid bid = new CpcBid();
    bid.setBid(new Money());
    bid.getBid().setMicroAmount(10000000L);
    biddingStrategyConfiguration.setBids(new Bids[] { bid });
    biddableAdGroupCriterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // Create operations.
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(biddableAdGroupCriterion);
    // Create the criterion.
    AdGroupCriterion newAdGroupCriterion = adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { operation }).getValue(0);
    System.out.printf("Webpage criterion with ID %d was added to ad group ID %d.%n", newAdGroupCriterion.getCriterion().getId(), newAdGroupCriterion.getAdGroupId());
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) Webpage(com.google.api.ads.adwords.axis.v201809.cm.Webpage) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) WebpageParameter(com.google.api.ads.adwords.axis.v201809.cm.WebpageParameter) WebpageCondition(com.google.api.ads.adwords.axis.v201809.cm.WebpageCondition)

Example 2 with AdGroupCriterionServiceInterface

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface in project googleads-java-lib by googleads.

the class AddShoppingDynamicRemarketingCampaign method attachUserList.

/**
 * Attach a user list to an ad group. The user list provides positive targeting and feed
 * information to drive the dynamic content of the ad.
 *
 * <p>Note: User lists must be attached at the ad group level for positive targeting in Shopping
 * dynamic remarketing campaigns.
 *
 * @param adGroup the ad group which will have the user list attached.
 * @param userListId the user list to use for targeting and dynamic content.
 */
private static void attachUserList(AdWordsServicesInterface services, AdWordsSession session, AdGroup adGroup, long userListId) throws RemoteException {
    AdGroupCriterionServiceInterface adGroupCriterionService = services.get(session, AdGroupCriterionServiceInterface.class);
    CriterionUserList userList = new CriterionUserList();
    userList.setUserListId(userListId);
    BiddableAdGroupCriterion adGroupCriterion = new BiddableAdGroupCriterion();
    adGroupCriterion.setCriterion(userList);
    adGroupCriterion.setAdGroupId(adGroup.getId());
    AdGroupCriterionOperation op = new AdGroupCriterionOperation();
    op.setOperand(adGroupCriterion);
    op.setOperator(Operator.ADD);
    adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { op });
}
Also used : AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) CriterionUserList(com.google.api.ads.adwords.axis.v201809.cm.CriterionUserList)

Example 3 with AdGroupCriterionServiceInterface

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface in project googleads-java-lib by googleads.

the class HandlePartialFailures method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group.
 * @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 {
    // Enable partial failure.
    session.setPartialFailure(true);
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    List<AdGroupCriterionOperation> operations = new ArrayList<>();
    // Create keywords.
    String[] keywords = new String[] { "mars cruise", "inv@lid cruise", "venus cruise", "b(a)d keyword cruise" };
    for (String keywordText : keywords) {
        // Create keyword
        Keyword keyword = new Keyword();
        keyword.setText(keywordText);
        keyword.setMatchType(KeywordMatchType.BROAD);
        // Create biddable ad group criterion.
        BiddableAdGroupCriterion keywordBiddableAdGroupCriterion = new BiddableAdGroupCriterion();
        keywordBiddableAdGroupCriterion.setAdGroupId(adGroupId);
        keywordBiddableAdGroupCriterion.setCriterion(keyword);
        // Create operation.
        AdGroupCriterionOperation keywordAdGroupCriterionOperation = new AdGroupCriterionOperation();
        keywordAdGroupCriterionOperation.setOperand(keywordBiddableAdGroupCriterion);
        keywordAdGroupCriterionOperation.setOperator(Operator.ADD);
        operations.add(keywordAdGroupCriterionOperation);
    }
    // Add ad group criteria.
    AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations.toArray(new AdGroupCriterionOperation[] {}));
    // Display results.
    Arrays.stream(result.getValue()).filter(adGroupCriterionResult -> adGroupCriterionResult.getCriterion() != null).forEach(adGroupCriterionResult -> System.out.printf("Ad group criterion with ad group ID %d, and criterion ID %d, " + "and keyword '%s' was added.%n", adGroupCriterionResult.getAdGroupId(), adGroupCriterionResult.getCriterion().getId(), ((Keyword) adGroupCriterionResult.getCriterion()).getText()));
    for (ApiError apiError : result.getPartialFailureErrors()) {
        // Get the index of the failed operation from the error's field path elements.
        FieldPathElement[] fieldPathElements = apiError.getFieldPathElements();
        FieldPathElement firstFieldPathElement = null;
        if (fieldPathElements != null && fieldPathElements.length > 0) {
            firstFieldPathElement = fieldPathElements[0];
        }
        if (firstFieldPathElement != null && "operations".equals(firstFieldPathElement.getField()) && firstFieldPathElement.getIndex() != null) {
            int operationIndex = firstFieldPathElement.getIndex();
            AdGroupCriterion adGroupCriterion = operations.get(operationIndex).getOperand();
            System.out.printf("Ad group criterion with ad group ID %d and keyword '%s' " + "triggered a failure for the following reason: %s.%n", adGroupCriterion.getAdGroupId(), ((Keyword) adGroupCriterion.getCriterion()).getText(), apiError.getErrorString());
        } else {
            System.out.printf("A failure has occurred for the following reason: %s%n", apiError.getErrorString());
        }
    }
}
Also used : KeywordMatchType(com.google.api.ads.adwords.axis.v201809.cm.KeywordMatchType) Arrays(java.util.Arrays) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) Parameter(com.beust.jcommander.Parameter) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) ArrayList(java.util.ArrayList) OfflineCredentials(com.google.api.ads.common.lib.auth.OfflineCredentials) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException) FieldPathElement(com.google.api.ads.adwords.axis.v201809.cm.FieldPathElement) ArgumentNames(com.google.api.ads.adwords.lib.utils.examples.ArgumentNames) Credential(com.google.api.client.auth.oauth2.Credential) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) AdGroupCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue) AdWordsServices(com.google.api.ads.adwords.axis.factory.AdWordsServices) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) Operator(com.google.api.ads.adwords.axis.v201809.cm.Operator) CodeSampleParams(com.google.api.ads.common.lib.utils.examples.CodeSampleParams) RemoteException(java.rmi.RemoteException) DEFAULT_CONFIGURATION_FILENAME(com.google.api.ads.common.lib.utils.Builder.DEFAULT_CONFIGURATION_FILENAME) List(java.util.List) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) AdWordsServicesInterface(com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) ApiError(com.google.api.ads.adwords.axis.v201809.cm.ApiError) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) Api(com.google.api.ads.common.lib.auth.OfflineCredentials.Api) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) ArrayList(java.util.ArrayList) FieldPathElement(com.google.api.ads.adwords.axis.v201809.cm.FieldPathElement) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) AdGroupCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) ApiError(com.google.api.ads.adwords.axis.v201809.cm.ApiError)

Example 4 with AdGroupCriterionServiceInterface

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface in project googleads-java-lib by googleads.

the class GetKeywords method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group to use to find keywords.
 * @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 AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    int offset = 0;
    boolean morePages = true;
    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(AdGroupCriterionField.Id, AdGroupCriterionField.CriteriaType, AdGroupCriterionField.KeywordMatchType, AdGroupCriterionField.KeywordText).orderAscBy(AdGroupCriterionField.KeywordText).offset(offset).limit(PAGE_SIZE).in(AdGroupCriterionField.AdGroupId, adGroupId.toString()).in(AdGroupCriterionField.CriteriaType, "KEYWORD").build();
    while (morePages) {
        // Get all ad group criteria.
        AdGroupCriterionPage page = adGroupCriterionService.get(selector);
        // Display ad group criteria.
        if (page.getEntries() != null && page.getEntries().length > 0) {
            // Display results.
            Arrays.stream(page.getEntries()).map(adGroupCriterionResult -> (Keyword) adGroupCriterionResult.getCriterion()).forEach(keyword -> System.out.printf("Keyword with text '%s', match type '%s', criteria type '%s'," + " and ID %d was found.%n", keyword.getText(), keyword.getMatchType(), keyword.getType(), keyword.getId()));
        } else {
            System.out.println("No ad group criteria were found.");
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
        morePages = offset < page.getTotalNumEntries();
    }
}
Also used : OAuthException(com.google.api.ads.common.lib.exception.OAuthException) Arrays(java.util.Arrays) Parameter(com.beust.jcommander.Parameter) AdWordsServices(com.google.api.ads.adwords.axis.factory.AdWordsServices) AdGroupCriterionPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionPage) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) CodeSampleParams(com.google.api.ads.common.lib.utils.examples.CodeSampleParams) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) RemoteException(java.rmi.RemoteException) DEFAULT_CONFIGURATION_FILENAME(com.google.api.ads.common.lib.utils.Builder.DEFAULT_CONFIGURATION_FILENAME) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) AdWordsServicesInterface(com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface) ApiError(com.google.api.ads.adwords.axis.v201809.cm.ApiError) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) OfflineCredentials(com.google.api.ads.common.lib.auth.OfflineCredentials) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException) Api(com.google.api.ads.common.lib.auth.OfflineCredentials.Api) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector) ArgumentNames(com.google.api.ads.adwords.lib.utils.examples.ArgumentNames) Credential(com.google.api.client.auth.oauth2.Credential) AdGroupCriterionField(com.google.api.ads.adwords.lib.selectorfields.v201809.cm.AdGroupCriterionField) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) AdGroupCriterionPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionPage) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 5 with AdGroupCriterionServiceInterface

use of com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface in project googleads-java-lib by googleads.

the class ProductPartitionTreeImpl method createAdGroupTree.

/**
 * Returns a new instance of this class by retrieving the product partitions of the
 * specified ad group. All parameters are required.
 */
static ProductPartitionTreeImpl createAdGroupTree(AdWordsServicesInterface services, AdWordsSession session, Long adGroupId) throws ApiException, RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface criterionService = services.get(session, AdGroupCriterionServiceInterface.class);
    SelectorBuilder selectorBuilder = new SelectorBuilder().fields(REQUIRED_SELECTOR_FIELD_ENUMS.toArray(new AdGroupCriterionField[REQUIRED_SELECTOR_FIELD_ENUMS.size()])).equals(AdGroupCriterionField.AdGroupId, adGroupId.toString()).equals(AdGroupCriterionField.CriteriaType, "PRODUCT_PARTITION").in(AdGroupCriterionField.Status, UserStatus.ENABLED.getValue(), UserStatus.PAUSED.getValue()).limit(PAGE_SIZE);
    AdGroupCriterionPage adGroupCriterionPage;
    // A multimap from each product partition ID to its direct children.
    ListMultimap<Long, AdGroupCriterion> parentIdMap = LinkedListMultimap.create();
    int offset = 0;
    do {
        // Get the next page of results.
        adGroupCriterionPage = criterionService.get(selectorBuilder.build());
        if (adGroupCriterionPage != null && adGroupCriterionPage.getEntries() != null) {
            for (AdGroupCriterion adGroupCriterion : adGroupCriterionPage.getEntries()) {
                ProductPartition partition = (ProductPartition) adGroupCriterion.getCriterion();
                parentIdMap.put(partition.getParentCriterionId(), adGroupCriterion);
            }
            offset += adGroupCriterionPage.getEntries().length;
            selectorBuilder.increaseOffsetBy(PAGE_SIZE);
        }
    } while (offset < adGroupCriterionPage.getTotalNumEntries());
    // Construct the ProductPartitionTree from the parentIdMap.
    if (!parentIdMap.containsKey(null)) {
        Preconditions.checkState(parentIdMap.isEmpty(), "No root criterion found in the tree but the tree is not empty");
        return createEmptyAdGroupTree(adGroupId, getAdGroupBiddingStrategyConfiguration(services, session, adGroupId));
    }
    return createNonEmptyAdGroupTree(adGroupId, parentIdMap);
}
Also used : AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) AdGroupCriterionPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionPage) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition) AdGroupCriterionField(com.google.api.ads.adwords.lib.selectorfields.v201809.cm.AdGroupCriterionField)

Aggregations

AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)13 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)11 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)9 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)8 AdGroupCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue)7 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)5 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)4 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)4 ProductPartitionTree (com.google.api.ads.adwords.axis.utils.v201809.shopping.ProductPartitionTree)3 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)3 Parameter (com.beust.jcommander.Parameter)2 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)2 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)2 AdGroupCriterionPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionPage)2 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)2 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)2 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)2 NegativeAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)2 Webpage (com.google.api.ads.adwords.axis.v201809.cm.Webpage)2 WebpageCondition (com.google.api.ads.adwords.axis.v201809.cm.WebpageCondition)2