Search in sources :

Example 6 with Criterion

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

the class ProductPartitionNodeAdapter method createCriterionForRemove.

/**
 * Returns a new AdGroupCriterion configured for a REMOVE operation.
 *
 * @param node the node whose criterion should be removed
 * @param adGroupId the ad group ID of the criterion
 */
static AdGroupCriterion createCriterionForRemove(ProductPartitionNode node, long adGroupId) {
    Preconditions.checkNotNull(node, "Null node");
    AdGroupCriterion adGroupCriterion = new AdGroupCriterion();
    adGroupCriterion.setAdGroupId(adGroupId);
    adGroupCriterion.setCriterion(new ProductPartition());
    adGroupCriterion.getCriterion().setId(node.getProductPartitionId());
    return adGroupCriterion;
}
Also used : BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)

Example 7 with Criterion

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

the class ProductPartitionNodeAdapter method createCriterionForSetBiddableUnit.

/**
 * Returns a new AdGroupCriterion configured for a SET operation that will set the criterion's
 * bid, tracking template, and custom parameters.
 *
 * @param node the node whose criterion should be updated
 * @param adGroupId the ad group ID of the criterion
 * @param biddingConfig the bidding strategy configuration of the criterion
 */
static AdGroupCriterion createCriterionForSetBiddableUnit(ProductPartitionNode node, long adGroupId, BiddingStrategyConfiguration biddingConfig) {
    Preconditions.checkNotNull(node, "Null node");
    Preconditions.checkNotNull(biddingConfig, "Null bidding configuration");
    Preconditions.checkArgument(node.isBiddableUnit(), "Node is not a biddable unit");
    BiddableAdGroupCriterion biddableCriterion = new BiddableAdGroupCriterion();
    biddableCriterion.setAdGroupId(adGroupId);
    ProductPartition partition = new ProductPartition();
    partition.setId(node.getProductPartitionId());
    if (node.getParent() != null) {
        partition.setParentCriterionId(node.getParent().getProductPartitionId());
    }
    partition.setCaseValue(node.getDimension());
    partition.setPartitionType(ProductPartitionType.UNIT);
    biddableCriterion.setCriterion(partition);
    // Set the bidding attributes on the new ad group criterion.
    if (node.getBid() != null) {
        Money bidMoney = new Money();
        bidMoney.setMicroAmount(node.getBid());
        CpcBid cpcBid = new CpcBid();
        cpcBid.setBid(bidMoney);
        biddingConfig.setBids(new Bids[] { cpcBid });
    } else {
        biddingConfig.setBids(new Bids[0]);
    }
    biddableCriterion.setBiddingStrategyConfiguration(biddingConfig);
    // Set the upgraded URL attributes on the new ad group criterion.
    if (node.getTrackingUrlTemplate() != null) {
        biddableCriterion.setTrackingUrlTemplate(node.getTrackingUrlTemplate());
    }
    biddableCriterion.setUrlCustomParameters(createCustomParameters(node));
    return biddableCriterion;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)

Example 8 with Criterion

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

the class ProductPartitionNodeAdapter method createCriterionForAdd.

/**
 * Returns a new AdGroupCriterion configured for an ADD operation.
 *
 * @param node the node whose criterion should be added
 * @param adGroupId the ad group ID of the criterion
 * @param biddingConfig the bidding strategy configuration of the criterion
 */
static AdGroupCriterion createCriterionForAdd(ProductPartitionNode node, long adGroupId, BiddingStrategyConfiguration biddingConfig) {
    Preconditions.checkNotNull(node, "Null node");
    Preconditions.checkNotNull(biddingConfig, "Null bidding configuration");
    AdGroupCriterion adGroupCriterion;
    if (node.isExcludedUnit()) {
        adGroupCriterion = new NegativeAdGroupCriterion();
    } else if (node.isBiddableUnit()) {
        BiddableAdGroupCriterion biddableCriterion = new BiddableAdGroupCriterion();
        if (node.getBid() != null) {
            Money bidMoney = new Money();
            bidMoney.setMicroAmount(node.getBid());
            CpcBid cpcBid = new CpcBid();
            cpcBid.setBid(bidMoney);
            cpcBid.setCpcBidSource(BidSource.CRITERION);
            biddingConfig.setBids(new Bids[] { cpcBid });
            biddableCriterion.setBiddingStrategyConfiguration(biddingConfig);
        }
        if (node.getTrackingUrlTemplate() != null) {
            biddableCriterion.setTrackingUrlTemplate(node.getTrackingUrlTemplate());
        }
        biddableCriterion.setUrlCustomParameters(createCustomParameters(node));
        adGroupCriterion = biddableCriterion;
    } else {
        adGroupCriterion = new BiddableAdGroupCriterion();
    }
    adGroupCriterion.setAdGroupId(adGroupId);
    ProductPartition partition = new ProductPartition();
    partition.setId(node.getProductPartitionId());
    if (node.getParent() != null) {
        partition.setParentCriterionId(node.getParent().getProductPartitionId());
    }
    partition.setCaseValue(node.getDimension());
    partition.setPartitionType(node.isUnit() ? ProductPartitionType.UNIT : ProductPartitionType.SUBDIVISION);
    adGroupCriterion.setCriterion(partition);
    return adGroupCriterion;
}
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) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) Bids(com.google.api.ads.adwords.axis.v201809.cm.Bids) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)

Example 9 with Criterion

use of com.google.api.ads.adwords.axis.v201809.cm.Criterion 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)

Example 10 with Criterion

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

the class GetKeywordBidSimulations method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group.
 * @param criterionId the ID of the criterion.
 * @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, Long criterionId) throws RemoteException {
    // Get the DataService.
    DataServiceInterface dataService = adWordsServices.get(session, DataServiceInterface.class);
    // Create a query to select all keyword bid simulations for the ad group.
    ServiceQuery query = new ServiceQuery.Builder().fields(DataField.AdGroupId, DataField.CriterionId, DataField.StartDate, DataField.EndDate, DataField.Bid, DataField.BiddableConversions, DataField.BiddableConversionsValue, DataField.LocalClicks, DataField.LocalCost, DataField.LocalImpressions).where(DataField.AdGroupId).equalTo(adGroupId).where(DataField.CriterionId).equalTo(criterionId).limit(0, PAGE_SIZE).build();
    // Display bid landscapes.
    CriterionBidLandscapePage page = null;
    do {
        query.nextPage(page);
        // Retrieve keyword bid simulations one page at a time, continuing to request pages until all
        // of them have been retrieved.
        page = dataService.queryCriterionBidLandscape(query.toString());
        if (page.getEntries() != null) {
            for (CriterionBidLandscape criterionBidLandscape : page.getEntries()) {
                System.out.printf("Criterion bid landscape with ad group ID %d, criterion ID %d, " + "start date %s, end date %s, with landscape points:%n", criterionBidLandscape.getAdGroupId(), criterionBidLandscape.getCriterionId(), criterionBidLandscape.getStartDate(), criterionBidLandscape.getEndDate());
                for (BidLandscapeLandscapePoint bidLanscapePoint : criterionBidLandscape.getLandscapePoints()) {
                    System.out.printf("\t{bid: %d clicks: %d cost: %d impressions: %d, biddable conversions: %.2f, " + "biddable conversions value: %.2f}%n", bidLanscapePoint.getBid().getMicroAmount(), bidLanscapePoint.getClicks(), bidLanscapePoint.getCost().getMicroAmount(), bidLanscapePoint.getImpressions(), bidLanscapePoint.getBiddableConversions(), bidLanscapePoint.getBiddableConversionsValue());
                }
                System.out.println(" was found.");
            }
        }
    } while (query.hasNext(page));
}
Also used : CriterionBidLandscapePage(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscapePage) CriterionBidLandscape(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscape) DataServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.DataServiceInterface) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) ServiceQuery(com.google.api.ads.adwords.axis.utils.v201809.ServiceQuery)

Aggregations

AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)14 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)13 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)11 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)10 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)9 ArrayList (java.util.ArrayList)9 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)8 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)8 AdGroupCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue)7 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)7 CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)6 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)6 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)5 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)5 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)5 NegativeAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)5 ProductPartition (com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)5 BidLandscapeLandscapePoint (com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint)4 Bids (com.google.api.ads.adwords.axis.v201809.cm.Bids)4 CampaignCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue)4