Search in sources :

Example 16 with Money

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

the class GetKeywordIdeas method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the optional ID of the seed 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, @Nullable Long adGroupId) throws RemoteException {
    // Get the TargetingIdeaService.
    TargetingIdeaServiceInterface targetingIdeaService = adWordsServices.get(session, TargetingIdeaServiceInterface.class);
    // Create selector.
    TargetingIdeaSelector selector = new TargetingIdeaSelector();
    selector.setRequestType(RequestType.IDEAS);
    selector.setIdeaType(IdeaType.KEYWORD);
    selector.setRequestedAttributeTypes(new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME, AttributeType.AVERAGE_CPC, AttributeType.COMPETITION, AttributeType.CATEGORY_PRODUCTS_AND_SERVICES });
    // Set selector paging (required for targeting idea service).
    Paging paging = new Paging();
    paging.setStartIndex(0);
    paging.setNumberResults(10);
    selector.setPaging(paging);
    List<SearchParameter> searchParameters = new ArrayList<>();
    // Create related to query search parameter.
    RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
    relatedToQuerySearchParameter.setQueries(new String[] { "bakery", "pastries", "birthday cake" });
    searchParameters.add(relatedToQuerySearchParameter);
    // Language setting (optional).
    // The ID can be found in the documentation:
    // https://developers.google.com/adwords/api/docs/appendix/languagecodes
    // See the documentation for limits on the number of allowed language parameters:
    // https://developers.google.com/adwords/api/docs/reference/latest/TargetingIdeaService.LanguageSearchParameter
    LanguageSearchParameter languageParameter = new LanguageSearchParameter();
    Language english = new Language();
    english.setId(1000L);
    languageParameter.setLanguages(new Language[] { english });
    searchParameters.add(languageParameter);
    // Create network search parameter (optional).
    NetworkSetting networkSetting = new NetworkSetting();
    networkSetting.setTargetGoogleSearch(true);
    networkSetting.setTargetSearchNetwork(false);
    networkSetting.setTargetContentNetwork(false);
    networkSetting.setTargetPartnerSearchNetwork(false);
    NetworkSearchParameter networkSearchParameter = new NetworkSearchParameter();
    networkSearchParameter.setNetworkSetting(networkSetting);
    searchParameters.add(networkSearchParameter);
    // Optional: Use an existing ad group to generate ideas.
    if (adGroupId != null) {
        SeedAdGroupIdSearchParameter seedAdGroupIdSearchParameter = new SeedAdGroupIdSearchParameter();
        seedAdGroupIdSearchParameter.setAdGroupId(adGroupId);
        searchParameters.add(seedAdGroupIdSearchParameter);
    }
    selector.setSearchParameters(searchParameters.toArray(new SearchParameter[searchParameters.size()]));
    // Get keyword ideas.
    TargetingIdeaPage page = targetingIdeaService.get(selector);
    // Display keyword ideas.
    for (TargetingIdea targetingIdea : page.getEntries()) {
        Map<AttributeType, Attribute> data = Maps.toMap(targetingIdea.getData());
        StringAttribute keyword = (StringAttribute) data.get(AttributeType.KEYWORD_TEXT);
        IntegerSetAttribute categories = (IntegerSetAttribute) data.get(AttributeType.CATEGORY_PRODUCTS_AND_SERVICES);
        String categoriesString = "(none)";
        if (categories != null && categories.getValue() != null) {
            categoriesString = Joiner.on(", ").join(Ints.asList(categories.getValue()));
        }
        Long averageMonthlySearches = ((LongAttribute) data.get(AttributeType.SEARCH_VOLUME)).getValue();
        Money averageCpc = ((MoneyAttribute) data.get(AttributeType.AVERAGE_CPC)).getValue();
        Double competition = ((DoubleAttribute) data.get(AttributeType.COMPETITION)).getValue();
        System.out.printf("Keyword with text '%s', average monthly search volume %d, " + "average CPC %d, and competition %.2f " + "was found with categories: %s%n", keyword.getValue(), averageMonthlySearches, averageCpc.getMicroAmount(), competition, categoriesString);
    }
    if (page.getEntries() == null) {
        System.out.println("No related keywords were found.");
    }
}
Also used : SeedAdGroupIdSearchParameter(com.google.api.ads.adwords.axis.v201809.o.SeedAdGroupIdSearchParameter) TargetingIdea(com.google.api.ads.adwords.axis.v201809.o.TargetingIdea) DoubleAttribute(com.google.api.ads.adwords.axis.v201809.o.DoubleAttribute) Attribute(com.google.api.ads.adwords.axis.v201809.o.Attribute) LongAttribute(com.google.api.ads.adwords.axis.v201809.o.LongAttribute) MoneyAttribute(com.google.api.ads.adwords.axis.v201809.o.MoneyAttribute) StringAttribute(com.google.api.ads.adwords.axis.v201809.o.StringAttribute) IntegerSetAttribute(com.google.api.ads.adwords.axis.v201809.o.IntegerSetAttribute) ArrayList(java.util.ArrayList) StringAttribute(com.google.api.ads.adwords.axis.v201809.o.StringAttribute) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) Language(com.google.api.ads.adwords.axis.v201809.cm.Language) TargetingIdeaPage(com.google.api.ads.adwords.axis.v201809.o.TargetingIdeaPage) AttributeType(com.google.api.ads.adwords.axis.v201809.o.AttributeType) LongAttribute(com.google.api.ads.adwords.axis.v201809.o.LongAttribute) MoneyAttribute(com.google.api.ads.adwords.axis.v201809.o.MoneyAttribute) LanguageSearchParameter(com.google.api.ads.adwords.axis.v201809.o.LanguageSearchParameter) NetworkSearchParameter(com.google.api.ads.adwords.axis.v201809.o.NetworkSearchParameter) SearchParameter(com.google.api.ads.adwords.axis.v201809.o.SearchParameter) RelatedToQuerySearchParameter(com.google.api.ads.adwords.axis.v201809.o.RelatedToQuerySearchParameter) SeedAdGroupIdSearchParameter(com.google.api.ads.adwords.axis.v201809.o.SeedAdGroupIdSearchParameter) TargetingIdeaSelector(com.google.api.ads.adwords.axis.v201809.o.TargetingIdeaSelector) Paging(com.google.api.ads.adwords.axis.v201809.cm.Paging) IntegerSetAttribute(com.google.api.ads.adwords.axis.v201809.o.IntegerSetAttribute) TargetingIdeaServiceInterface(com.google.api.ads.adwords.axis.v201809.o.TargetingIdeaServiceInterface) NetworkSearchParameter(com.google.api.ads.adwords.axis.v201809.o.NetworkSearchParameter) LanguageSearchParameter(com.google.api.ads.adwords.axis.v201809.o.LanguageSearchParameter) DoubleAttribute(com.google.api.ads.adwords.axis.v201809.o.DoubleAttribute) NetworkSetting(com.google.api.ads.adwords.axis.v201809.cm.NetworkSetting) RelatedToQuerySearchParameter(com.google.api.ads.adwords.axis.v201809.o.RelatedToQuerySearchParameter)

Example 17 with Money

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

the class ProductPartitionTreeImpl method getBid.

/**
 * Returns the criterion-level bid, or null if no such bid exists.
 */
private static Money getBid(BiddableAdGroupCriterion biddableCriterion) {
    BiddingStrategyConfiguration biddingConfig = biddableCriterion.getBiddingStrategyConfiguration();
    Money cpcBidAmount = null;
    if (biddingConfig.getBids() != null) {
        for (Bids bid : biddingConfig.getBids()) {
            if (bid instanceof CpcBid) {
                CpcBid cpcBid = (CpcBid) bid;
                if (BidSource.CRITERION.equals(cpcBid.getCpcBidSource())) {
                    cpcBidAmount = cpcBid.getBid();
                    break;
                }
            }
        }
    }
    return cpcBidAmount;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) Bids(com.google.api.ads.adwords.axis.v201809.cm.Bids) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid)

Example 18 with Money

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

the class ProductPartitionTreeImpl method addChildNodes.

/**
 * Using the criteria in {@code parentIdMap}, recursively adds all children under the partition ID
 * of {@code parentNode} to {@code parentNode}.
 *
 * @param parentNode required
 * @param parentIdMap the multimap from parent partition ID to list of child criteria
 */
private static void addChildNodes(ProductPartitionNode parentNode, ListMultimap<Long, AdGroupCriterion> parentIdMap) {
    if (parentIdMap.containsKey(parentNode.getProductPartitionId())) {
        parentNode = parentNode.asSubdivision();
    }
    for (AdGroupCriterion adGroupCriterion : parentIdMap.get(parentNode.getProductPartitionId())) {
        ProductPartition partition = (ProductPartition) adGroupCriterion.getCriterion();
        ProductPartitionNode childNode = parentNode.addChild(partition.getCaseValue());
        childNode = childNode.setProductPartitionId(partition.getId());
        if (ProductPartitionType.SUBDIVISION.equals(partition.getPartitionType())) {
            childNode = childNode.asSubdivision();
        } else {
            if (adGroupCriterion instanceof BiddableAdGroupCriterion) {
                childNode = childNode.asBiddableUnit();
                BiddableAdGroupCriterion biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterion;
                Money cpcBidAmount = getBid(biddableAdGroupCriterion);
                if (cpcBidAmount != null) {
                    childNode = childNode.setBid(cpcBidAmount.getMicroAmount());
                }
                childNode = childNode.setTrackingUrlTemplate(biddableAdGroupCriterion.getTrackingUrlTemplate());
                childNode = copyCustomParametersToNode(biddableAdGroupCriterion, childNode);
            } else {
                childNode = childNode.asExcludedUnit();
            }
        }
        addChildNodes(childNode, parentIdMap);
    }
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) 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) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)

Example 19 with Money

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

the class ProductPartitionTreeImpl method createNonEmptyAdGroupTree.

/**
 * Returns a new tree based on a non-empty collection of ad group criteria. All parameters
 * required.
 *
 * @param adGroupId the ID of the ad group
 * @param parentIdMap the multimap from parent product partition ID to child criteria
 * @return a new ProductPartitionTree
 */
private static ProductPartitionTreeImpl createNonEmptyAdGroupTree(Long adGroupId, ListMultimap<Long, AdGroupCriterion> parentIdMap) {
    Preconditions.checkNotNull(adGroupId, "Null ad group ID");
    Preconditions.checkArgument(!parentIdMap.isEmpty(), "parentIdMap passed for ad group ID %s is empty", adGroupId);
    Preconditions.checkArgument(parentIdMap.containsKey(null), "No root criterion found in the list of ad group criteria for ad group ID %s", adGroupId);
    AdGroupCriterion rootCriterion = Iterables.getOnlyElement(parentIdMap.get(null));
    Preconditions.checkState(rootCriterion instanceof BiddableAdGroupCriterion, "Root criterion for ad group ID %s is not a BiddableAdGroupCriterion", adGroupId);
    BiddableAdGroupCriterion biddableRootCriterion = (BiddableAdGroupCriterion) rootCriterion;
    BiddingStrategyConfiguration biddingStrategyConfig = biddableRootCriterion.getBiddingStrategyConfiguration();
    Preconditions.checkState(biddingStrategyConfig != null, "Null bidding strategy config on the root node of ad group ID %s", adGroupId);
    ProductPartitionNode rootNode = new ProductPartitionNode(null, (ProductDimension) null, rootCriterion.getCriterion().getId(), new ProductDimensionComparator());
    // Set the root's bid if a bid exists on the BiddableAdGroupCriterion.
    Money rootNodeBid = getBid(biddableRootCriterion);
    if (rootNodeBid != null) {
        rootNode = rootNode.asBiddableUnit().setBid(rootNodeBid.getMicroAmount());
    }
    rootNode = rootNode.setTrackingUrlTemplate(biddableRootCriterion.getTrackingUrlTemplate());
    rootNode = copyCustomParametersToNode(biddableRootCriterion, rootNode);
    addChildNodes(rootNode, parentIdMap);
    return new ProductPartitionTreeImpl(adGroupId, biddingStrategyConfig, rootNode);
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) 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)

Example 20 with Money

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

the class AxisBatchJobUploadBodyProviderTest method addBudgetOperation.

@Override
protected void addBudgetOperation(BatchJobMutateRequest request, long budgetId, String budgetName, long budgetAmountInMicros, String deliveryMethod) {
    Budget budget = new Budget();
    budget.setBudgetId(budgetId);
    budget.setName(budgetName);
    Money budgetAmount = new Money();
    budgetAmount.setMicroAmount(budgetAmountInMicros);
    budget.setAmount(budgetAmount);
    budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.fromString(deliveryMethod));
    BudgetOperation budgetOperation = new BudgetOperation();
    budgetOperation.setOperand(budget);
    budgetOperation.setOperator(Operator.ADD);
    request.addOperation(budgetOperation);
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BudgetOperation(com.google.api.ads.adwords.axis.v201809.cm.BudgetOperation) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget)

Aggregations

Money (com.google.api.ads.adwords.axis.v201809.cm.Money)30 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)12 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)11 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)11 BudgetOperation (com.google.api.ads.adwords.axis.v201809.cm.BudgetOperation)10 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)8 BudgetServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.BudgetServiceInterface)8 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)6 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)4 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)4 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)4 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)4 Bids (com.google.api.ads.adwords.axis.v201809.cm.Bids)4 Budget (com.google.api.ads.adwords.jaxws.v201809.cm.Budget)4 BudgetOperation (com.google.api.ads.adwords.jaxws.v201809.cm.BudgetOperation)4 Money (com.google.api.ads.adwords.jaxws.v201809.cm.Money)4 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)4 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)3 AdGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface)3 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)3