Search in sources :

Example 16 with BiddingStrategyConfiguration

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

the class UsePortfolioBiddingStrategy method createCampaignWithBiddingStrategy.

/**
 * Create a Campaign with a portfolio bidding strategy.
 *
 * @param adWordsServices the user to run the example with
 * @param session the AdWordsSession
 * @param biddingStrategyId the bidding strategy id to use
 * @param sharedBudgetId the shared budget id to use
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 */
private static Campaign createCampaignWithBiddingStrategy(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long biddingStrategyId, Long sharedBudgetId) throws RemoteException {
    // Get the CampaignService, which loads the required classes.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create campaign.
    Campaign campaign = new Campaign();
    campaign.setName("Interplanetary Cruise #" + System.currentTimeMillis());
    // 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 the budget.
    Budget budget = new Budget();
    budget.setBudgetId(sharedBudgetId);
    campaign.setBudget(budget);
    // Set bidding strategy (required).
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    biddingStrategyConfiguration.setBiddingStrategyId(biddingStrategyId);
    campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // Set advertising channel type (required).
    campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);
    // Set network targeting (recommended).
    NetworkSetting networkSetting = new NetworkSetting();
    networkSetting.setTargetGoogleSearch(true);
    networkSetting.setTargetSearchNetwork(true);
    networkSetting.setTargetContentNetwork(true);
    campaign.setNetworkSetting(networkSetting);
    // Create operation.
    CampaignOperation operation = new CampaignOperation();
    operation.setOperand(campaign);
    operation.setOperator(Operator.ADD);
    CampaignReturnValue result = campaignService.mutate(new CampaignOperation[] { operation });
    Campaign newCampaign = result.getValue(0);
    System.out.printf("Campaign with name '%s', ID %d and bidding scheme ID %d was created.%n", newCampaign.getName(), newCampaign.getId(), newCampaign.getBiddingStrategyConfiguration().getBiddingStrategyId());
    return newCampaign;
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) 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) CampaignReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) NetworkSetting(com.google.api.ads.adwords.axis.v201809.cm.NetworkSetting)

Example 17 with BiddingStrategyConfiguration

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

the class AddShoppingDynamicRemarketingCampaign method createCampaign.

/**
 * Creates a Shopping dynamic remarketing campaign object (not including ad group level and
 * below). This creates a Display campaign with the merchant center feed attached. Merchant Center
 * is used for the product information in combination with a user list which contains hits with
 * {@code ecomm_prodid} specified. See <a
 * href="https://developers.google.com/adwords-remarketing-tag/parameters#retail"/>for more
 * detail.
 *
 * @param merchantId the ID of the Merchant Center account.
 * @param budgetId the ID of the budget to use for the campaign.
 * @return the campaign that was created.
 */
private static Campaign createCampaign(AdWordsServicesInterface services, AdWordsSession session, long merchantId, long budgetId) throws RemoteException {
    CampaignServiceInterface campaignService = services.get(session, CampaignServiceInterface.class);
    Campaign campaign = new Campaign();
    campaign.setName("Shopping campaign #" + System.currentTimeMillis());
    // Dynamic remarketing campaigns are only available on the Google Display Network.
    campaign.setAdvertisingChannelType(AdvertisingChannelType.DISPLAY);
    campaign.setStatus(CampaignStatus.PAUSED);
    Budget budget = new Budget();
    budget.setBudgetId(budgetId);
    campaign.setBudget(budget);
    // This example uses a Manual CPC bidding strategy, but you should select the strategy that best
    // aligns with your sales goals. More details here:
    // https://support.google.com/adwords/answer/2472725
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.MANUAL_CPC);
    campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    ShoppingSetting setting = new ShoppingSetting();
    // Campaigns with numerically higher priorities take precedence over those with lower
    // priorities.
    setting.setCampaignPriority(0);
    // Set the Merchant Center account ID from which to source products.
    setting.setMerchantId(merchantId);
    // Display Network campaigns do not support partition by country. The only supported value is
    // "ZZ". This signals that products from all countries are available in the campaign. The actual
    // products which serve are based on the products tagged in the user list entry.
    setting.setSalesCountry("ZZ");
    // Optional: Enable local inventory ads (items for sale in physical stores.)
    setting.setEnableLocal(true);
    campaign.setSettings(new Setting[] { setting });
    CampaignOperation op = new CampaignOperation();
    op.setOperand(campaign);
    op.setOperator(Operator.ADD);
    CampaignReturnValue result = campaignService.mutate(new CampaignOperation[] { op });
    return result.getValue(0);
}
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 18 with BiddingStrategyConfiguration

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

the class UpdateAdGroup method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group to update.
 * @param bidMicroAmount the optional bid amount in micros to use for the ad group bid.
 * @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, @Nullable Long bidMicroAmount) throws RemoteException {
    // Get the AdGroupService.
    AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
    // Create an ad group with the specified ID.
    AdGroup adGroup = new AdGroup();
    adGroup.setId(adGroupId);
    // Update the CPC bid if specified.
    if (bidMicroAmount != null) {
        BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
        Money cpcBidMoney = new Money();
        cpcBidMoney.setMicroAmount(bidMicroAmount);
        CpcBid cpcBid = new CpcBid();
        cpcBid.setBid(cpcBidMoney);
        biddingStrategyConfiguration.setBids(new Bids[] { cpcBid });
        adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    }
    // Pause the ad group.
    adGroup.setStatus(AdGroupStatus.PAUSED);
    // Create operations.
    AdGroupOperation operation = new AdGroupOperation();
    operation.setOperand(adGroup);
    operation.setOperator(Operator.SET);
    AdGroupOperation[] operations = new AdGroupOperation[] { operation };
    // Update ad group.
    AdGroupReturnValue result = adGroupService.mutate(operations);
    // Display ad groups.
    for (AdGroup adGroupResult : result.getValue()) {
        BiddingStrategyConfiguration biddingStrategyConfiguration = adGroupResult.getBiddingStrategyConfiguration();
        // Find the CpcBid in the bidding strategy configuration's bids collection.
        Long cpcBidMicros = null;
        if (biddingStrategyConfiguration != null) {
            if (biddingStrategyConfiguration.getBids() != null) {
                for (Bids bid : biddingStrategyConfiguration.getBids()) {
                    if (bid instanceof CpcBid) {
                        cpcBidMicros = ((CpcBid) bid).getBid().getMicroAmount();
                        break;
                    }
                }
            }
        }
        System.out.printf("Ad group with ID %d and name '%s' updated to have status '%s' and CPC bid %d%n", adGroupResult.getId(), adGroupResult.getName(), adGroupResult.getStatus(), cpcBidMicros);
    }
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) Bids(com.google.api.ads.adwords.axis.v201809.cm.Bids) AdGroupReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Example 19 with BiddingStrategyConfiguration

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

the class UpdateKeyword method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group for the criterion.
 * @param keywordId the ID of the criterion to update.
 * @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 keywordId) throws RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    // Create ad group criterion with updated bid.
    Criterion criterion = new Criterion();
    criterion.setId(keywordId);
    BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
    biddableAdGroupCriterion.setAdGroupId(adGroupId);
    biddableAdGroupCriterion.setCriterion(criterion);
    // Create bids.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    CpcBid bid = new CpcBid();
    bid.setBid(new Money(null, 10000000L));
    biddingStrategyConfiguration.setBids(new Bids[] { bid });
    biddableAdGroupCriterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // Create operations.
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
    operation.setOperand(biddableAdGroupCriterion);
    operation.setOperator(Operator.SET);
    AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] { operation };
    // Update ad group criteria.
    AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
    // Display ad group criteria.
    for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
        if (adGroupCriterionResult instanceof BiddableAdGroupCriterion) {
            biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult;
            CpcBid criterionCpcBid = null;
            // Find the criterion-level CpcBid among the keyword's bids.
            for (Bids bids : biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids()) {
                if (bids instanceof CpcBid) {
                    CpcBid cpcBid = (CpcBid) bids;
                    if (BidSource.CRITERION.equals(cpcBid.getCpcBidSource())) {
                        criterionCpcBid = cpcBid;
                    }
                }
            }
            System.out.printf("Ad group criterion with ad group ID %d, criterion ID %d, type " + "'%s', and bid %d was updated.%n", biddableAdGroupCriterion.getAdGroupId(), biddableAdGroupCriterion.getCriterion().getId(), biddableAdGroupCriterion.getCriterion().getCriterionType(), criterionCpcBid.getBid().getMicroAmount());
        }
    }
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) AdGroupCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) 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) 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) Bids(com.google.api.ads.adwords.axis.v201809.cm.Bids) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid)

Example 20 with BiddingStrategyConfiguration

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

the class AddCompleteCampaignsUsingBatchJob method buildAdGroupOperations.

private static List<AdGroupOperation> buildAdGroupOperations(Iterator<Long> tempIdGenerator, String namePrefix, Iterable<CampaignOperation> campaignOperations) {
    List<AdGroupOperation> operations = new ArrayList<>();
    for (CampaignOperation campaignOperation : campaignOperations) {
        for (int i = 0; i < NUMBER_OF_ADGROUPS_TO_ADD; i++) {
            AdGroup adGroup = new AdGroup();
            adGroup.setCampaignId(campaignOperation.getOperand().getId());
            adGroup.setId(tempIdGenerator.next());
            adGroup.setName(String.format("Batch Ad Group %s.%s", namePrefix, i));
            BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
            CpcBid bid = new CpcBid();
            bid.setBid(new Money(null, 10000000L));
            biddingStrategyConfiguration.setBids(new Bids[] { bid });
            adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
            AdGroupOperation operation = new AdGroupOperation();
            operation.setOperand(adGroup);
            operation.setOperator(Operator.ADD);
            operations.add(operation);
        }
    }
    return operations;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) ArrayList(java.util.ArrayList) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) 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