Search in sources :

Example 36 with Campaign

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

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

the class AddCampaignTargetingCriteria method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign where targeting criteria will be added.
 * @param locationFeedId optional ID of a location targeting feed.
 * @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 campaignId, @Nullable Long locationFeedId) throws RemoteException {
    // Get the CampaignService.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    // Create locations. The IDs can be found in the documentation or
    // retrieved with the LocationCriterionService.
    Location california = new Location();
    california.setId(21137L);
    Location mexico = new Location();
    mexico.setId(2484L);
    // Create languages. The IDs can be found in the documentation or
    // retrieved with the ConstantDataService.
    Language english = new Language();
    english.setId(1000L);
    Language spanish = new Language();
    spanish.setId(1003L);
    List<Criterion> criteria = new ArrayList<>(Arrays.asList(california, mexico, english, spanish));
    // Distance targeting. Area of 10 miles around the locations in the location feed.
    if (locationFeedId != null) {
        LocationGroups radiusLocationGroup = new LocationGroups();
        radiusLocationGroup.setFeedId(locationFeedId);
        ConstantOperand radius = new ConstantOperand();
        radius.setType(ConstantOperandConstantType.DOUBLE);
        radius.setUnit(ConstantOperandUnit.MILES);
        radius.setDoubleValue(10d);
        LocationExtensionOperand distance = new LocationExtensionOperand();
        distance.setRadius(radius);
        Function radiusMatchingFunction = new Function();
        radiusMatchingFunction.setOperator(FunctionOperator.IDENTITY);
        radiusMatchingFunction.setLhsOperand(new FunctionArgumentOperand[] { distance });
        radiusLocationGroup.setMatchingFunction(radiusMatchingFunction);
        criteria.add(radiusLocationGroup);
    }
    // Create operations to add each of the criteria above.
    List<CampaignCriterionOperation> operations = new ArrayList<>();
    for (Criterion criterion : criteria) {
        CampaignCriterionOperation operation = new CampaignCriterionOperation();
        CampaignCriterion campaignCriterion = new CampaignCriterion();
        campaignCriterion.setCampaignId(campaignId);
        campaignCriterion.setCriterion(criterion);
        operation.setOperand(campaignCriterion);
        operation.setOperator(Operator.ADD);
        operations.add(operation);
    }
    // Add a negative campaign criterion.
    Keyword negativeKeyword = new Keyword();
    negativeKeyword.setText("jupiter cruise");
    negativeKeyword.setMatchType(KeywordMatchType.BROAD);
    CampaignCriterion negativeCriterion = new NegativeCampaignCriterion();
    negativeCriterion.setCampaignId(campaignId);
    negativeCriterion.setCriterion(negativeKeyword);
    CampaignCriterionOperation operation = new CampaignCriterionOperation();
    operation.setOperand(negativeCriterion);
    operation.setOperator(Operator.ADD);
    operations.add(operation);
    CampaignCriterionReturnValue result = campaignCriterionService.mutate(operations.toArray(new CampaignCriterionOperation[operations.size()]));
    // Display campaigns.
    for (CampaignCriterion campaignCriterion : result.getValue()) {
        System.out.printf("Campaign criterion with campaign ID %d, criterion ID %d, " + "and type '%s' was added.%n", campaignCriterion.getCampaignId(), campaignCriterion.getCriterion().getId(), campaignCriterion.getCriterion().getCriterionType());
    }
}
Also used : ConstantOperand(com.google.api.ads.adwords.axis.v201809.cm.ConstantOperand) CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) LocationGroups(com.google.api.ads.adwords.axis.v201809.cm.LocationGroups) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) NegativeCampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) ArrayList(java.util.ArrayList) NegativeCampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion) CampaignCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue) Function(com.google.api.ads.adwords.axis.v201809.cm.Function) Language(com.google.api.ads.adwords.axis.v201809.cm.Language) NegativeCampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) Criterion(com.google.api.ads.adwords.axis.v201809.cm.Criterion) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) LocationExtensionOperand(com.google.api.ads.adwords.axis.v201809.cm.LocationExtensionOperand) Location(com.google.api.ads.adwords.axis.v201809.cm.Location)

Example 38 with Campaign

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

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

the class GetCampaignTargetingCriteria method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @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) throws RemoteException {
    // Get the CampaignService.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    int offset = 0;
    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(CampaignCriterionField.CampaignId, CampaignCriterionField.Id, CampaignCriterionField.CriteriaType, CampaignCriterionField.PlatformName, CampaignCriterionField.LanguageName, CampaignCriterionField.LocationName, CampaignCriterionField.KeywordText).in(CampaignCriterionField.CriteriaType, "KEYWORD", "LANGUAGE", "LOCATION", "PLATFORM").offset(0).limit(PAGE_SIZE).build();
    CampaignCriterionPage page = null;
    do {
        page = campaignCriterionService.get(selector);
        if (page.getEntries() != null) {
            // Display campaigns.
            for (CampaignCriterion campaignCriterion : page.getEntries()) {
                System.out.printf("Campaign criterion with campaign ID %d, criterion ID %d, " + "and type '%s' was found.%n", campaignCriterion.getCampaignId(), campaignCriterion.getCriterion().getId(), campaignCriterion.getCriterion().getCriterionType());
            }
        } else {
            System.out.println("No campaign criteria were found.");
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
    } while (offset < page.getTotalNumEntries());
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) CampaignCriterionPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionPage) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 40 with Campaign

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

the class BatchJobHelperTest method assertDownloadResponse.

@Override
protected void assertDownloadResponse(BatchJobMutateResponse downloadResponse) {
    assertEquals("Wrong # of mutate results", 1, downloadResponse.getMutateResults().length);
    Operand operand = downloadResponse.getMutateResults()[0].getOperand();
    Campaign campaign = operand.getCampaign();
    assertEquals("ID is incorrect", Long.valueOf(12345L), campaign.getId());
    assertEquals("Status is incorrect", CampaignStatus.PAUSED, campaign.getStatus());
}
Also used : Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) Operand(com.google.api.ads.adwords.axis.v201809.cm.Operand)

Aggregations

Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)23 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)17 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)16 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)15 ArrayList (java.util.ArrayList)14 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)11 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)11 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)11 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)10 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)9 CampaignReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue)9 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)6 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)6 CampaignPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignPage)6 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)5 AdGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface)5 BudgetOperation (com.google.api.ads.adwords.axis.v201809.cm.BudgetOperation)5 CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)5 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)5 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)4