Search in sources :

Example 31 with Campaign

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

the class AddSmartShoppingAd method createBudget.

/**
 * Creates a non-shared budget for a Smart Shopping campaign. Smart Shopping campaigns support
 * only non-shared budgets.
 */
private static Budget createBudget(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    BudgetServiceInterface budgetService = adWordsServices.get(session, BudgetServiceInterface.class);
    // Create a budget.
    Budget budget = new Budget();
    budget.setName("Interplanetary Cruise #" + System.currentTimeMillis());
    Money budgetAmount = new Money();
    // This budget equals 50.00 units of your account's currency, e.g.,
    // 50 USD if your currency is USD.
    budgetAmount.setMicroAmount(50_000_000L);
    budget.setAmount(budgetAmount);
    budget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
    // Non-shared budgets are required for Smart Shopping campaigns.
    budget.setIsExplicitlyShared(false);
    // Create operation.
    BudgetOperation budgetOperation = new BudgetOperation();
    budgetOperation.setOperand(budget);
    budgetOperation.setOperator(Operator.ADD);
    // Add the budget.
    Budget newBudget = budgetService.mutate(new BudgetOperation[] { budgetOperation }).getValue(0);
    System.out.printf("Budget with name '%s' and ID %d was added.%n", newBudget.getName(), newBudget.getBudgetId());
    return newBudget;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BudgetOperation(com.google.api.ads.adwords.axis.v201809.cm.BudgetOperation) BudgetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.BudgetServiceInterface) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget)

Example 32 with Campaign

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

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

the class AddExpandedTextAdWithUpgradedUrls method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group where the ad 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 adGroupId) throws RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    // Create expanded text ad with a tracking template and custom parameters.
    ExpandedTextAd expandedTextAd = new ExpandedTextAd();
    expandedTextAd.setHeadlinePart1("Luxury Cruise to Mars");
    expandedTextAd.setHeadlinePart2("Visit the Red Planet in style.");
    expandedTextAd.setDescription("Low-gravity fun for everyone!");
    // Specify a tracking url for 3rd party tracking provider. You may
    // specify one at customer, campaign, ad group, ad, criterion or
    // feed item levels.
    expandedTextAd.setTrackingUrlTemplate("http://tracker.example.com/?season={_season}&promocode={_promocode}&u={lpurl}");
    // Since your tracking url has two custom parameters, provide their
    // values too. This can be provided at campaign, ad group, ad, criterion
    // or feed item levels.
    CustomParameter seasonParameter = new CustomParameter();
    seasonParameter.setKey("season");
    seasonParameter.setValue("christmas");
    CustomParameter promoCodeParameter = new CustomParameter();
    promoCodeParameter.setKey("promocode");
    promoCodeParameter.setValue("NYC123");
    CustomParameters trackingUrlParameters = new CustomParameters();
    trackingUrlParameters.setParameters(new CustomParameter[] { seasonParameter, promoCodeParameter });
    expandedTextAd.setUrlCustomParameters(trackingUrlParameters);
    // Specify a list of final urls. This field cannot be set if url field is
    // set. This may be specified at ad, criterion, and feed item levels.
    expandedTextAd.setFinalUrls(new String[] { "http://www.example.com/cruise/space/", "http://www.example.com/locations/mars/" });
    // Specify a list of final mobile urls. This field cannot be set if url field is
    // set or finalUrls is not set. This may be specified at ad, criterion, and feed
    // item levels.
    expandedTextAd.setFinalMobileUrls(new String[] { "http://mobile.example.com/cruise/space/", "http://mobile.example.com/locations/mars/" });
    // Create ad group ad.
    AdGroupAd textAdGroupAd = new AdGroupAd();
    textAdGroupAd.setAdGroupId(adGroupId);
    textAdGroupAd.setAd(expandedTextAd);
    // Optional: Set status.
    textAdGroupAd.setStatus(AdGroupAdStatus.PAUSED);
    // Create operation.
    AdGroupAdOperation textAdGroupAdOperation = new AdGroupAdOperation();
    textAdGroupAdOperation.setOperand(textAdGroupAd);
    textAdGroupAdOperation.setOperator(Operator.ADD);
    AdGroupAdOperation[] operations = new AdGroupAdOperation[] { textAdGroupAdOperation };
    // Add ad.
    AdGroupAd adGroupAdResult = adGroupAdService.mutate(operations).getValue(0);
    // Display ad.
    System.out.printf("Ad with ID %d and tracking URL template '%s' was added.", adGroupAdResult.getAd().getId(), adGroupAdResult.getAd().getTrackingUrlTemplate());
}
Also used : AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) ExpandedTextAd(com.google.api.ads.adwords.axis.v201809.cm.ExpandedTextAd) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) CustomParameter(com.google.api.ads.adwords.axis.v201809.cm.CustomParameter) CustomParameters(com.google.api.ads.adwords.axis.v201809.cm.CustomParameters)

Example 34 with Campaign

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

the class GetAccountChanges 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);
    // Get the CustomerSyncService.
    CustomerSyncServiceInterface customerSyncService = adWordsServices.get(session, CustomerSyncServiceInterface.class);
    // Get a list of all campaign IDs.
    List<Long> campaignIds = new ArrayList<>();
    Selector selector = new SelectorBuilder().fields(CampaignField.Id).build();
    CampaignPage campaigns = campaignService.get(selector);
    if (campaigns.getEntries() != null) {
        Arrays.stream(campaigns.getEntries()).forEach(campaign -> campaignIds.add(campaign.getId()));
    }
    // Create date time range for the past 24 hours.
    DateTimeRange dateTimeRange = new DateTimeRange();
    dateTimeRange.setMin(new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24)));
    dateTimeRange.setMax(new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date()));
    // Create selector.
    CustomerSyncSelector customerSyncSelector = new CustomerSyncSelector();
    customerSyncSelector.setDateTimeRange(dateTimeRange);
    customerSyncSelector.setCampaignIds(ArrayUtils.toPrimitive(campaignIds.toArray(new Long[] {})));
    // Get all account changes for campaign.
    CustomerChangeData accountChanges = customerSyncService.get(customerSyncSelector);
    // Display changes.
    if (accountChanges != null && accountChanges.getChangedCampaigns() != null) {
        System.out.printf("Most recent change: %s%n", accountChanges.getLastChangeTimestamp());
        for (CampaignChangeData campaignChanges : accountChanges.getChangedCampaigns()) {
            System.out.printf("Campaign with ID %d was changed:%n", campaignChanges.getCampaignId());
            System.out.printf("\tCampaign changed status: '%s'%n", campaignChanges.getCampaignChangeStatus());
            if (!ChangeStatus.NEW.equals(campaignChanges.getCampaignChangeStatus())) {
                System.out.printf("\tAdded campaign criteria: %s%n", getFormattedList(campaignChanges.getAddedCampaignCriteria()));
                System.out.printf("\tRemoved campaign criteria: %s%n", getFormattedList(campaignChanges.getRemovedCampaignCriteria()));
                if (campaignChanges.getChangedAdGroups() != null) {
                    for (AdGroupChangeData adGroupChanges : campaignChanges.getChangedAdGroups()) {
                        System.out.printf("\tAd group with ID %d was changed:%n", adGroupChanges.getAdGroupId());
                        System.out.printf("\t\tAd group changed status: %s%n", adGroupChanges.getAdGroupChangeStatus());
                        if (!ChangeStatus.NEW.equals(adGroupChanges.getAdGroupChangeStatus())) {
                            System.out.printf("\t\tAds changed: %s%n", getFormattedList(adGroupChanges.getChangedAds()));
                            System.out.printf("\t\tCriteria changed: %s%n", getFormattedList(adGroupChanges.getChangedCriteria()));
                            System.out.printf("\t\tCriteria removed: %s%n", getFormattedList(adGroupChanges.getRemovedCriteria()));
                        }
                    }
                }
            }
            System.out.println("");
        }
    } else {
        System.out.println("No account changes were found.");
    }
}
Also used : CustomerChangeData(com.google.api.ads.adwords.axis.v201809.ch.CustomerChangeData) ArrayList(java.util.ArrayList) CampaignChangeData(com.google.api.ads.adwords.axis.v201809.ch.CampaignChangeData) CampaignPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignPage) Date(java.util.Date) CustomerSyncSelector(com.google.api.ads.adwords.axis.v201809.ch.CustomerSyncSelector) CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) AdGroupChangeData(com.google.api.ads.adwords.axis.v201809.ch.AdGroupChangeData) CustomerSyncServiceInterface(com.google.api.ads.adwords.axis.v201809.ch.CustomerSyncServiceInterface) DateTimeRange(com.google.api.ads.adwords.axis.v201809.cm.DateTimeRange) SimpleDateFormat(java.text.SimpleDateFormat) CustomerSyncSelector(com.google.api.ads.adwords.axis.v201809.ch.CustomerSyncSelector) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 35 with Campaign

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

the class AddSmartShoppingAd method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @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 merchantId, boolean createDefaultPartition) throws RemoteException {
    Budget budget = createBudget(adWordsServices, session);
    Campaign campaign = createSmartShoppingCampaign(adWordsServices, session, budget.getBudgetId(), merchantId);
    AdGroup adGroup = createSmartShoppingAdGroup(adWordsServices, session, campaign.getId());
    createSmartShoppingAd(adWordsServices, session, adGroup.getId());
    if (createDefaultPartition) {
        createDefaultPartition(adWordsServices, session, adGroup.getId());
    }
}
Also used : Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup)

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