Search in sources :

Example 6 with BiddingStrategyConfiguration

use of com.google.api.ads.adwords.jaxws.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.jaxws.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.jaxws.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)

Example 9 with BiddingStrategyConfiguration

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

the class AddSmartShoppingAd method createSmartShoppingCampaign.

/**
 * Creates a Smart Shopping campaign.
 */
private static Campaign createSmartShoppingCampaign(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long budgetId, long merchantId) throws RemoteException {
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create a campaign with required and optional settings.
    Campaign campaign = new Campaign();
    campaign.setName("Smart Shopping campaign #" + System.currentTimeMillis());
    // The advertisingChannelType is what makes this a Shopping campaign.
    campaign.setAdvertisingChannelType(AdvertisingChannelType.SHOPPING);
    // Sets the advertisingChannelSubType to SHOPPING_GOAL_OPTIMIZED_ADS to
    // make this a Smart Shopping campaign.
    campaign.setAdvertisingChannelSubType(AdvertisingChannelSubType.SHOPPING_GOAL_OPTIMIZED_ADS);
    // Recommendation: Set the campaign to PAUSED when creating it to stop
    // the ads from immediately serving. Set to ENABLED once you've added
    // targeting and the ads are ready to serve.
    campaign.setStatus(CampaignStatus.PAUSED);
    // Set a budget.
    Budget budget = new Budget();
    budget.setBudgetId(budgetId);
    campaign.setBudget(budget);
    // Set bidding strategy. Only MAXIMIZE_CONVERSION_VALUE is supported.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.MAXIMIZE_CONVERSION_VALUE);
    campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // All Shopping campaigns need a ShoppingSetting.
    ShoppingSetting shoppingSetting = new ShoppingSetting();
    shoppingSetting.setSalesCountry("US");
    shoppingSetting.setMerchantId(merchantId);
    campaign.setSettings(new Setting[] { shoppingSetting });
    // Create operation.
    CampaignOperation campaignOperation = new CampaignOperation();
    campaignOperation.setOperand(campaign);
    campaignOperation.setOperator(Operator.ADD);
    // Make the mutate request.
    CampaignReturnValue campaignAddResult = campaignService.mutate(new CampaignOperation[] { campaignOperation });
    // Display result.
    campaign = campaignAddResult.getValue(0);
    System.out.printf("Smart Shopping campaign with name '%s' and ID %d was added.%n", campaign.getName(), campaign.getId());
    return campaign;
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) ShoppingSetting(com.google.api.ads.adwords.axis.v201809.cm.ShoppingSetting) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) CampaignReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget)

Example 10 with BiddingStrategyConfiguration

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

the class AddShoppingCampaign method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param budgetId the budget ID to use for the new campaign.
 * @param merchantId the Merchant Center ID for the new campaign.
 * @param createDefaultPartition if true, a default product partition for all products will be
 *     created.
 * @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 budgetId, Long merchantId, boolean createDefaultPartition) throws RemoteException {
    // Get the CampaignService
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create campaign.
    Campaign campaign = new Campaign();
    campaign.setName("Shopping campaign #" + System.currentTimeMillis());
    // The advertisingChannelType is what makes this a Shopping campaign
    campaign.setAdvertisingChannelType(AdvertisingChannelType.SHOPPING);
    // Recommendation: Set the campaign to PAUSED when creating it to prevent
    // the ads from immediately serving. Set to ENABLED once you've added
    // targeting and the ads are ready to serve.
    campaign.setStatus(CampaignStatus.PAUSED);
    // Set shared budget (required).
    Budget budget = new Budget();
    budget.setBudgetId(budgetId);
    campaign.setBudget(budget);
    // Set bidding strategy (required).
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.MANUAL_CPC);
    campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // All Shopping campaigns need a ShoppingSetting.
    ShoppingSetting shoppingSetting = new ShoppingSetting();
    shoppingSetting.setSalesCountry("US");
    shoppingSetting.setCampaignPriority(0);
    shoppingSetting.setMerchantId(merchantId);
    // Set to 'true' to enable Local Inventory Ads in your campaign.
    shoppingSetting.setEnableLocal(true);
    campaign.setSettings(new Setting[] { shoppingSetting });
    // Create operation.
    CampaignOperation campaignOperation = new CampaignOperation();
    campaignOperation.setOperand(campaign);
    campaignOperation.setOperator(Operator.ADD);
    // Make the mutate request.
    CampaignReturnValue campaignAddResult = campaignService.mutate(new CampaignOperation[] { campaignOperation });
    // Display result.
    campaign = campaignAddResult.getValue(0);
    System.out.printf("Campaign with name '%s' and ID %d was added.%n", campaign.getName(), campaign.getId());
    // Get the AdGroupService.
    AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
    // Create ad group.
    AdGroup adGroup = new AdGroup();
    adGroup.setCampaignId(campaign.getId());
    adGroup.setName("Ad Group #" + System.currentTimeMillis());
    // 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("Ad group with name '%s' and ID %d was added.%n", adGroup.getName(), adGroup.getId());
    // Create product ad.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    ProductAd productAd = new ProductAd();
    // Create ad group ad.
    AdGroupAd adGroupAd = new AdGroupAd();
    adGroupAd.setAdGroupId(adGroup.getId());
    adGroupAd.setAd(productAd);
    // Create operation.
    AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
    adGroupAdOperation.setOperand(adGroupAd);
    adGroupAdOperation.setOperator(Operator.ADD);
    // Make the mutate request.
    AdGroupAdReturnValue adGroupAdAddResult = adGroupAdService.mutate(new AdGroupAdOperation[] { adGroupAdOperation });
    // Display result.
    adGroupAd = adGroupAdAddResult.getValue(0);
    System.out.printf("Product ad with ID %d was added.%n", adGroupAd.getAd().getId());
    if (createDefaultPartition) {
        // Create an ad group criterion for 'All products' using the ProductPartitionTree utility.
        ProductPartitionTree productPartitionTree = ProductPartitionTree.createAdGroupTree(adWordsServices, session, adGroup.getId());
        productPartitionTree.getRoot().asBiddableUnit().setBid(500000L);
        List<AdGroupCriterionOperation> mutateOperations = productPartitionTree.getMutateOperations();
        // Make the mutate request.
        AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
        AdGroupCriterionReturnValue adGroupCriterionResult = adGroupCriterionService.mutate(mutateOperations.toArray(new AdGroupCriterionOperation[0]));
        // Display result.
        for (AdGroupCriterion adGroupCriterion : adGroupCriterionResult.getValue()) {
            System.out.printf("Ad group criterion with ID %d in ad group with ID %d was added.%n", adGroupCriterion.getCriterion().getId(), adGroupCriterion.getAdGroupId());
        }
    }
}
Also used : ShoppingSetting(com.google.api.ads.adwords.axis.v201809.cm.ShoppingSetting) AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) ProductPartitionTree(com.google.api.ads.adwords.axis.utils.v201809.shopping.ProductPartitionTree) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) AdGroupAdReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) CampaignReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) ProductAd(com.google.api.ads.adwords.axis.v201809.cm.ProductAd) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) AdGroupCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) AdGroupReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Aggregations

BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)21 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)12 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)10 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)10 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)9 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)9 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)7 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)6 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)6 CampaignReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue)6 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)5 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)4 Bids (com.google.api.ads.adwords.axis.v201809.cm.Bids)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 ShoppingSetting (com.google.api.ads.adwords.axis.v201809.cm.ShoppingSetting)3