Search in sources :

Example 11 with CampaignServiceInterface

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

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

the class RemoveCampaign method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign to remove.
 * @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) throws RemoteException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create campaign with REMOVED status.
    Campaign campaign = new Campaign();
    campaign.setId(campaignId);
    campaign.setStatus(CampaignStatus.REMOVED);
    // Create operations.
    CampaignOperation operation = new CampaignOperation();
    operation.setOperand(campaign);
    operation.setOperator(Operator.SET);
    CampaignOperation[] operations = new CampaignOperation[] { operation };
    // Remove campaign.
    CampaignReturnValue result = campaignService.mutate(operations);
    // Display campaigns.
    for (Campaign campaignResult : result.getValue()) {
        System.out.printf("Campaign with name '%s' and ID %d was removed.%n", campaignResult.getName(), campaignResult.getId());
    }
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) CampaignReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue)

Example 13 with CampaignServiceInterface

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

the class AddCampaignGroupsAndPerformanceTargets method addCampaignsToGroup.

/**
 * Adds multiple campaigns to a campaign group.
 */
private static void addCampaignsToGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, CampaignGroup campaignGroup, List<Long> campaignIds) throws ApiException, RemoteException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    List<CampaignOperation> operations = new ArrayList<>();
    for (Long campaignId : campaignIds) {
        Campaign campaign = new Campaign();
        campaign.setId(campaignId);
        campaign.setCampaignGroupId(campaignGroup.getId());
        CampaignOperation operation = new CampaignOperation();
        operation.setOperand(campaign);
        operation.setOperator(Operator.SET);
        operations.add(operation);
    }
    CampaignReturnValue returnValue = campaignService.mutate(operations.toArray(new CampaignOperation[operations.size()]));
    System.out.printf("The following campaign IDs were added to the campaign group with ID %d:%n", campaignGroup.getId());
    for (Campaign campaign : returnValue.getValue()) {
        System.out.printf("\t%d%n", campaign.getId());
    }
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) CampaignReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue) ArrayList(java.util.ArrayList)

Example 14 with CampaignServiceInterface

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

the class GetCampaignsWithAwql 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.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    ServiceQuery serviceQuery = new ServiceQuery.Builder().fields(CampaignField.Id, CampaignField.Name, CampaignField.Status).orderBy(CampaignField.Name).limit(0, PAGE_SIZE).build();
    CampaignPage page = null;
    do {
        serviceQuery.nextPage(page);
        // Get all campaigns.
        page = campaignService.query(serviceQuery.toString());
        // Display campaigns.
        if (page.getEntries() != null) {
            for (Campaign campaign : page.getEntries()) {
                System.out.printf("Campaign with name '%s' and ID %d was found.%n", campaign.getName(), campaign.getId());
            }
        } else {
            System.out.println("No campaigns were found.");
        }
    } while (serviceQuery.hasNext(page));
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) CampaignPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignPage) ServiceQuery(com.google.api.ads.adwords.axis.utils.v201809.ServiceQuery)

Example 15 with CampaignServiceInterface

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

the class AddCampaignLabels method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignIds the IDs of the campaigns to which the label will be added.
 * @param labelId the ID of the label to attach to campaigns.
 * @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, List<Long> campaignIds, Long labelId) throws RemoteException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create label operations.
    List<CampaignLabelOperation> operations = new ArrayList<>(campaignIds.size());
    for (Long campaignId : campaignIds) {
        CampaignLabel campaignLabel = new CampaignLabel();
        campaignLabel.setCampaignId(campaignId);
        campaignLabel.setLabelId(labelId);
        CampaignLabelOperation operation = new CampaignLabelOperation();
        operation.setOperand(campaignLabel);
        operation.setOperator(Operator.ADD);
        operations.add(operation);
    }
    // Display campaign labels.
    for (CampaignLabel campaignLabelResult : campaignService.mutateLabel(operations.toArray(new CampaignLabelOperation[operations.size()])).getValue()) {
        System.out.printf("Campaign label for campaign ID %d and label ID %d was added.%n", campaignLabelResult.getCampaignId(), campaignLabelResult.getLabelId());
    }
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) CampaignLabelOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignLabelOperation) ArrayList(java.util.ArrayList) CampaignLabel(com.google.api.ads.adwords.axis.v201809.cm.CampaignLabel)

Aggregations

CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)17 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)15 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)11 CampaignReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue)9 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)7 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)7 CampaignPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignPage)6 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)5 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)4 ShoppingSetting (com.google.api.ads.adwords.axis.v201809.cm.ShoppingSetting)3 ArrayList (java.util.ArrayList)3 DynamicSearchAdsSetting (com.google.api.ads.adwords.axis.v201809.cm.DynamicSearchAdsSetting)2 GeoTargetTypeSetting (com.google.api.ads.adwords.axis.v201809.cm.GeoTargetTypeSetting)2 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)2 NetworkSetting (com.google.api.ads.adwords.axis.v201809.cm.NetworkSetting)2 Parameter (com.beust.jcommander.Parameter)1 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)1 ServiceQuery (com.google.api.ads.adwords.axis.utils.v201809.ServiceQuery)1 ProductPartitionTree (com.google.api.ads.adwords.axis.utils.v201809.shopping.ProductPartitionTree)1 AdGroupChangeData (com.google.api.ads.adwords.axis.v201809.ch.AdGroupChangeData)1