Search in sources :

Example 11 with CampaignOperation

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

the class AddDynamicPageFeed method updateCampaignDsaSetting.

/**
 * Updates the campaign DSA setting to add DSA pagefeeds.
 */
private static void updateCampaignDsaSetting(AdWordsServicesInterface adWordsServices, AdWordsSession session, Long campaignId, DSAFeedDetails feedDetails) throws ApiException, RemoteException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    Selector selector = new SelectorBuilder().fields(CampaignField.Id, CampaignField.Settings).equalsId(campaignId).build();
    CampaignPage campaignPage = campaignService.get(selector);
    if (campaignPage.getEntries() == null || campaignPage.getTotalNumEntries() == 0) {
        throw new IllegalArgumentException("No campaign found with ID: " + campaignId);
    }
    Campaign campaign = campaignPage.getEntries(0);
    if (campaign.getSettings() == null) {
        throw new IllegalArgumentException("Campaign with ID " + campaignId + " is not a DSA campaign.");
    }
    DynamicSearchAdsSetting dsaSetting = (DynamicSearchAdsSetting) Arrays.stream(campaign.getSettings()).filter(DynamicSearchAdsSetting.class::isInstance).findFirst().orElse(null);
    if (dsaSetting == null) {
        throw new IllegalArgumentException("Campaign with ID " + campaignId + " is not a DSA campaign.");
    }
    // Use a page feed to specify precisely which URLs to use with your
    // Dynamic Search Ads.
    PageFeed pageFeed = new PageFeed();
    pageFeed.setFeedIds(new long[] { feedDetails.feedId });
    dsaSetting.setPageFeed(pageFeed);
    // Optional: Specify whether only the supplied URLs should be used with your
    // Dynamic Search Ads.
    dsaSetting.setUseSuppliedUrlsOnly(true);
    Campaign updatedCampaign = new Campaign();
    updatedCampaign.setId(campaignId);
    updatedCampaign.setSettings(campaign.getSettings());
    CampaignOperation operation = new CampaignOperation();
    operation.setOperand(updatedCampaign);
    operation.setOperator(Operator.SET);
    updatedCampaign = campaignService.mutate(new CampaignOperation[] { operation }).getValue(0);
    System.out.printf("DSA page feed for campaign ID %d was updated with feed ID %d.%n", updatedCampaign.getId(), feedDetails.feedId);
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) PageFeed(com.google.api.ads.adwords.axis.v201809.cm.PageFeed) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) CampaignPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignPage) DynamicSearchAdsSetting(com.google.api.ads.adwords.axis.v201809.cm.DynamicSearchAdsSetting) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 12 with CampaignOperation

use of com.google.api.ads.adwords.jaxws.v201809.cm.CampaignOperation 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 13 with CampaignOperation

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

Example 14 with CampaignOperation

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

the class BatchJobHelperTest method getPauseCampaignOperation.

@Override
protected Operation getPauseCampaignOperation(Long campaignId) {
    CampaignOperation op = new CampaignOperation();
    Campaign campaign = new Campaign();
    campaign.setId(campaignId);
    campaign.setStatus(CampaignStatus.PAUSED);
    op.setOperand(campaign);
    op.setOperator(Operator.SET);
    return op;
}
Also used : Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)

Example 15 with CampaignOperation

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

the class JaxWsBatchJobUploadBodyProviderTest 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.valueOf(status));
    campaign.setAdvertisingChannelType(AdvertisingChannelType.valueOf(advertisingChannelType));
    Budget budget = new Budget();
    budget.setBudgetId(budgetId);
    campaign.setBudget(budget);
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.valueOf(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.jaxws.v201809.cm.Campaign) BiddingStrategyConfiguration(com.google.api.ads.adwords.jaxws.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.jaxws.v201809.cm.CampaignOperation) Budget(com.google.api.ads.adwords.jaxws.v201809.cm.Budget) ManualCpcBiddingScheme(com.google.api.ads.adwords.jaxws.v201809.cm.ManualCpcBiddingScheme)

Aggregations

CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)18 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)15 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)11 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)10 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)9 CampaignReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue)9 ArrayList (java.util.ArrayList)5 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)4 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)3 ManualCpcBiddingScheme (com.google.api.ads.adwords.axis.v201809.cm.ManualCpcBiddingScheme)3 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)3 ShoppingSetting (com.google.api.ads.adwords.axis.v201809.cm.ShoppingSetting)3 Campaign (com.google.api.ads.adwords.jaxws.v201809.cm.Campaign)3 CampaignOperation (com.google.api.ads.adwords.jaxws.v201809.cm.CampaignOperation)3 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)2 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)2 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)2 BudgetOperation (com.google.api.ads.adwords.axis.v201809.cm.BudgetOperation)2 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)2 DynamicSearchAdsSetting (com.google.api.ads.adwords.axis.v201809.cm.DynamicSearchAdsSetting)2