Search in sources :

Example 6 with BiddingStrategyConfiguration

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

the class ProductPartitionNodeAdapterTest method testCommonAttributes.

/**
 * Asserts that the attributes of {@code adGroupCriterion} match expectations.
 *
 * @param node the node from which the criterion was built
 * @param adGroupCriterion the criterion created by {@link ProductPartitionNodeAdapter}
 * @param isForRemove if true, this method will only check the attributes required for a REMOVE
 *        operation
 */
private void testCommonAttributes(ProductPartitionNode node, AdGroupCriterion adGroupCriterion, boolean isForRemove) {
    assertEquals("Ad group ID is incorrect", adGroupId, adGroupCriterion.getAdGroupId());
    Criterion criterion = adGroupCriterion.getCriterion();
    assertTrue("Criterion should be a ProductPartition", criterion instanceof ProductPartition);
    assertEquals("Partition ID is incorrect", node.getProductPartitionId(), criterion.getId());
    if (isForRemove) {
        assertEquals("Type of AdGroupCriterion for REMOVE should be the base class", AdGroupCriterion.class, adGroupCriterion.getClass());
        // The above checks suffice for REMOVE operations.
        return;
    }
    ProductPartition partition = (ProductPartition) criterion;
    assertEquals("The caseValue of the partition does not match the dimension of the node", 0, new ProductDimensionComparator().compare(partition.getCaseValue(), node.getDimension()));
    if (node.getParent() == null) {
        assertNull("Parent ID should be null", partition.getParentCriterionId());
    } else {
        assertEquals("Parent ID does not match ID of parent node", node.getParent().getProductPartitionId(), partition.getParentCriterionId());
    }
    if (node.isBiddableUnit()) {
        assertTrue("Biddable node should be translated into a BiddableAdGroupCriterion", adGroupCriterion instanceof BiddableAdGroupCriterion);
        BiddableAdGroupCriterion biddableCriterion = (BiddableAdGroupCriterion) adGroupCriterion;
        BiddingStrategyConfiguration biddingStrategyConfig = biddableCriterion.getBiddingStrategyConfiguration();
        if (node.getBid() == null) {
            assertArrayEquals(new Bids[0], biddingStrategyConfig.getBids());
        } else {
            Bids bid = biddingStrategyConfig.getBids(0);
            assertTrue("Bid should be a CpcBid", bid instanceof CpcBid);
            CpcBid cpcBid = (CpcBid) bid;
            assertEquals("Bid amount is incorrect", node.getBid(), cpcBid.getBid().getMicroAmount());
            assertEquals("Partition is not a UNIT partition", ProductPartitionType.UNIT, partition.getPartitionType());
        }
        assertEquals("tracking URL template is incorrect", node.getTrackingUrlTemplate(), biddableCriterion.getTrackingUrlTemplate());
        // The adapter should always have a CustomParameters object, even if the node had no params.
        // This ensures that the parameters will be cleared (via doReplace=true) if all params were
        // removed from the node.
        CustomParameters customParameters = biddableCriterion.getUrlCustomParameters();
        assertNotNull("Biddable criterion does not have custom parameters", customParameters);
        assertEquals("doReplace for custom parameters should always be true", true, customParameters.getDoReplace());
        // Convert the BiddableAdGroupCriterion's custom parameters to a map to simplify comparison
        // against the node's custom parameter map.
        Map<String, String> actualCustomParameters = new HashMap<>();
        for (CustomParameter customParameter : customParameters.getParameters()) {
            actualCustomParameters.put(customParameter.getKey(), customParameter.getValue());
        }
        assertEquals("node and criterion do not have the same custom parameters", node.getCustomParameters(), actualCustomParameters);
    } else {
        assertTrue("Excluded node should be translated into a NegativeAdGroupCriterion", adGroupCriterion instanceof NegativeAdGroupCriterion);
    }
}
Also used : HashMap(java.util.HashMap) 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) ProductPartition(com.google.api.ads.adwords.axis.v201809.cm.ProductPartition) 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) Criterion(com.google.api.ads.adwords.axis.v201809.cm.Criterion) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) CustomParameter(com.google.api.ads.adwords.axis.v201809.cm.CustomParameter) CustomParameters(com.google.api.ads.adwords.axis.v201809.cm.CustomParameters) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)

Example 7 with BiddingStrategyConfiguration

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

the class AxisBatchJobUploadBodyProviderTest method addCampaignOperation.

@Override
protected void addCampaignOperation(BatchJobMutateRequest request, long campaignId, String campaignName, String status, String advertisingChannelType, long budgetId, String biddingStrategyType, boolean enhancedCpcEnabled) {
    Campaign campaign = new Campaign();
    campaign.setId(campaignId);
    campaign.setName(campaignName);
    campaign.setStatus(CampaignStatus.fromString(status));
    campaign.setAdvertisingChannelType(AdvertisingChannelType.fromString(advertisingChannelType));
    Budget budget = new Budget();
    budget.setBudgetId(budgetId);
    campaign.setBudget(budget);
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.fromString(biddingStrategyType));
    ManualCpcBiddingScheme cpcBiddingScheme = new ManualCpcBiddingScheme();
    cpcBiddingScheme.setEnhancedCpcEnabled(enhancedCpcEnabled);
    biddingStrategyConfiguration.setBiddingScheme(cpcBiddingScheme);
    campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    CampaignOperation operation = new CampaignOperation();
    operation.setOperand(campaign);
    operation.setOperator(Operator.ADD);
    request.addOperation(operation);
}
Also used : Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) ManualCpcBiddingScheme(com.google.api.ads.adwords.axis.v201809.cm.ManualCpcBiddingScheme)

Example 8 with BiddingStrategyConfiguration

use of com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration 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 9 with BiddingStrategyConfiguration

use of com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration 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 10 with BiddingStrategyConfiguration

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

the class AddDynamicPageFeed method addDsaTargeting.

/**
 * Sets custom targeting for the page feed URLs based on a list of labels.
 *
 * @param adWordsServices
 * @param session
 * @param adGroupId
 * @param dsaPageUrlLabel
 */
private static void addDsaTargeting(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long adGroupId, String dsaPageUrlLabel) throws ApiException, RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    // Create a webpage criterion.
    Webpage webpage = new Webpage();
    WebpageParameter parameter = new WebpageParameter();
    parameter.setCriterionName("Test criterion");
    webpage.setParameter(parameter);
    // Add a condition for label=specified_label_name.
    WebpageCondition condition = new WebpageCondition();
    condition.setOperand(WebpageConditionOperand.CUSTOM_LABEL);
    condition.setArgument(dsaPageUrlLabel);
    parameter.setConditions(new WebpageCondition[] { condition });
    BiddableAdGroupCriterion criterion = new BiddableAdGroupCriterion();
    criterion.setAdGroupId(adGroupId);
    criterion.setCriterion(webpage);
    // Set a custom bid for this criterion.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    CpcBid cpcBid = new CpcBid();
    Money money = new Money();
    money.setMicroAmount(1_500_000L);
    cpcBid.setBid(money);
    biddingStrategyConfiguration.setBids(new Bids[] { cpcBid });
    criterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
    operation.setOperand(criterion);
    operation.setOperator(Operator.ADD);
    BiddableAdGroupCriterion newCriterion = (BiddableAdGroupCriterion) adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { operation }).getValue(0);
    System.out.printf("Web page criterion with ID %d and status '%s' was created.%n", newCriterion.getCriterion().getId(), newCriterion.getUserStatus());
}
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) 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)

Aggregations

BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)21 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)14 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)12 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)10 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)9 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)9 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)9 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)8 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)7 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)6 CampaignReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue)6 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)5 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)5 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)5 AdGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface)5 Bids (com.google.api.ads.adwords.axis.v201809.cm.Bids)5 ProductPartition (com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)4 AdGroupCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue)3 AdGroupReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue)3 ManualCpcBiddingScheme (com.google.api.ads.adwords.axis.v201809.cm.ManualCpcBiddingScheme)3