Search in sources :

Example 26 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.jaxws.v201809.cm.Campaign) Operand(com.google.api.ads.adwords.jaxws.v201809.cm.Operand)

Example 27 with Campaign

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

the class AddPrices method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign where price feed items will be added.
 * @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 ApiException, RemoteException {
    // Get the CustomerExtensionSettingService.
    CustomerExtensionSettingServiceInterface customerExtensionSettingService = adWordsServices.get(session, CustomerExtensionSettingServiceInterface.class);
    // Create the price extension feed item.
    PriceFeedItem priceFeedItem = new PriceFeedItem();
    priceFeedItem.setPriceExtensionType(PriceExtensionType.SERVICES);
    // Price qualifier is optional.
    priceFeedItem.setPriceQualifier(PriceExtensionPriceQualifier.FROM);
    priceFeedItem.setTrackingUrlTemplate("http://tracker.example.com/?u={lpurl}");
    priceFeedItem.setLanguage("en");
    FeedItemCampaignTargeting campaignTargeting = new FeedItemCampaignTargeting();
    campaignTargeting.setTargetingCampaignId(campaignId);
    priceFeedItem.setCampaignTargeting(campaignTargeting);
    priceFeedItem.setScheduling(new FeedItemScheduling(new FeedItemSchedule[] { new FeedItemSchedule(DayOfWeek.SUNDAY, 10, MinuteOfHour.ZERO, 18, MinuteOfHour.ZERO), new FeedItemSchedule(DayOfWeek.SATURDAY, 10, MinuteOfHour.ZERO, 22, MinuteOfHour.ZERO) }));
    // To create a price extension, at least three table rows are needed.
    List<PriceTableRow> priceTableRows = new ArrayList<>();
    String currencyCode = "USD";
    priceTableRows.add(createPriceTableRow("Scrubs", "Body Scrub, Salt Scrub", "http://www.example.com/scrubs", "http://m.example.com/scrubs", 60000000, currencyCode, PriceExtensionPriceUnit.PER_HOUR));
    priceTableRows.add(createPriceTableRow("Hair Cuts", "Once a month", "http://www.example.com/haircuts", "http://m.example.com/haircuts", 75000000, currencyCode, PriceExtensionPriceUnit.PER_MONTH));
    priceTableRows.add(createPriceTableRow("Skin Care Package", "Four times a month", "http://www.example.com/skincarepackage", null, 250000000, currencyCode, PriceExtensionPriceUnit.PER_MONTH));
    priceFeedItem.setTableRows(priceTableRows.toArray(new PriceTableRow[priceTableRows.size()]));
    // Create your campaign extension settings. This associates the sitelinks
    // to your campaign.
    CustomerExtensionSetting customerExtensionSetting = new CustomerExtensionSetting();
    customerExtensionSetting.setExtensionType(FeedType.PRICE);
    ExtensionSetting extensionSetting = new ExtensionSetting();
    extensionSetting.setExtensions(new ExtensionFeedItem[] { priceFeedItem });
    customerExtensionSetting.setExtensionSetting(extensionSetting);
    CustomerExtensionSettingOperation operation = new CustomerExtensionSettingOperation();
    operation.setOperand(customerExtensionSetting);
    operation.setOperator(Operator.ADD);
    // Add the extensions.
    CustomerExtensionSettingReturnValue returnValue = customerExtensionSettingService.mutate(new CustomerExtensionSettingOperation[] { operation });
    if (returnValue.getValue() != null && returnValue.getValue().length > 0) {
        CustomerExtensionSetting newExtensionSetting = returnValue.getValue(0);
        System.out.printf("Extension setting with type '%s' was added.%n", newExtensionSetting.getExtensionType().getValue());
    } else {
        System.out.println("No extension settings were created.");
    }
}
Also used : CustomerExtensionSettingServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSettingServiceInterface) ExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.ExtensionSetting) CustomerExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSetting) CustomerExtensionSettingOperation(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSettingOperation) FeedItemSchedule(com.google.api.ads.adwords.axis.v201809.cm.FeedItemSchedule) ArrayList(java.util.ArrayList) PriceTableRow(com.google.api.ads.adwords.axis.v201809.cm.PriceTableRow) FeedItemCampaignTargeting(com.google.api.ads.adwords.axis.v201809.cm.FeedItemCampaignTargeting) FeedItemScheduling(com.google.api.ads.adwords.axis.v201809.cm.FeedItemScheduling) PriceFeedItem(com.google.api.ads.adwords.axis.v201809.cm.PriceFeedItem) CustomerExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSetting) CustomerExtensionSettingReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CustomerExtensionSettingReturnValue)

Example 28 with Campaign

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

the class AddSiteLinksUsingFeeds method createSiteLinksCampaignFeed.

private static void createSiteLinksCampaignFeed(AdWordsServicesInterface adWordsServices, AdWordsSession session, SiteLinksDataHolder siteLinksData, Long campaignId) throws RemoteException {
    // Get the CampaignFeedService.
    CampaignFeedServiceInterface campaignFeedService = adWordsServices.get(session, CampaignFeedServiceInterface.class);
    // Construct a matching function that associates the sitelink feed items to the campaign, and
    // sets the device preference to mobile. See the matching function guide at
    // https://developers.google.com/adwords/api/docs/guides/feed-matching-functions
    // for more details.
    String matchingFunctionString = String.format("AND( IN(FEED_ITEM_ID, {%s}), EQUALS(CONTEXT.DEVICE, 'Mobile') )", Joiner.on(',').join(siteLinksData.siteLinkFeedItemIds));
    CampaignFeed campaignFeed = new CampaignFeed();
    campaignFeed.setFeedId(siteLinksData.siteLinksFeedId);
    campaignFeed.setCampaignId(campaignId);
    Function matchingFunction = new Function();
    matchingFunction.setFunctionString(matchingFunctionString);
    campaignFeed.setMatchingFunction(matchingFunction);
    // Specifying placeholder types on the CampaignFeed allows the same feed
    // to be used for different placeholders in different Campaigns.
    campaignFeed.setPlaceholderTypes(new int[] { PLACEHOLDER_SITELINKS });
    CampaignFeedOperation operation = new CampaignFeedOperation();
    operation.setOperand(campaignFeed);
    operation.setOperator(Operator.ADD);
    CampaignFeedReturnValue result = campaignFeedService.mutate(new CampaignFeedOperation[] { operation });
    for (CampaignFeed savedCampaignFeed : result.getValue()) {
        System.out.printf("Campaign with ID %d was associated with feed with ID %d.%n", savedCampaignFeed.getCampaignId(), savedCampaignFeed.getFeedId());
    }
}
Also used : CampaignFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface) CampaignFeed(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeed) Function(com.google.api.ads.adwords.axis.v201809.cm.Function) CampaignFeedReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedReturnValue) CampaignFeedOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation)

Example 29 with Campaign

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

the class GetCampaignCriterionBidModifierSimulations method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign.
 * @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 DataService.
    DataServiceInterface dataService = adWordsServices.get(session, DataServiceInterface.class);
    // Create selector.
    Selector selector = new SelectorBuilder().fields(DataField.BidModifier, DataField.CampaignId, DataField.CriterionId, DataField.StartDate, DataField.EndDate, DataField.LocalClicks, DataField.LocalCost, DataField.LocalImpressions, DataField.TotalLocalClicks, DataField.TotalLocalCost, DataField.TotalLocalImpressions, DataField.RequiredBudget).equals(DataField.CampaignId, campaignId.toString()).limit(PAGE_SIZE).build();
    // Display bid landscapes.
    int landscapePointsInPreviousPage = 0;
    int startIndex = 0;
    do {
        // Offset the start index by the number of landscape points in the last retrieved page,
        // NOT the number of entries (bid landscapes) in the page.
        startIndex += landscapePointsInPreviousPage;
        selector.getPaging().setStartIndex(startIndex);
        // Reset the count of landscape points in preparation for processing the next page.
        landscapePointsInPreviousPage = 0;
        // Request the next page of bid landscapes.
        CriterionBidLandscapePage page = dataService.getCampaignCriterionBidLandscape(selector);
        if (page.getEntries() != null) {
            for (CriterionBidLandscape criterionBidLandscape : page.getEntries()) {
                System.out.printf("Found campaign-level criterion bid modifier landscape for" + " criterion with ID %d, start date '%s', end date '%s', and" + " landscape points:%n", criterionBidLandscape.getCriterionId(), criterionBidLandscape.getStartDate(), criterionBidLandscape.getEndDate());
                for (BidLandscapeLandscapePoint bidLandscapePoint : criterionBidLandscape.getLandscapePoints()) {
                    landscapePointsInPreviousPage++;
                    System.out.printf("  {bid modifier: %.2f => clicks: %d, cost: %d, impressions: %d, " + "total clicks: %d, total cost: %d, total impressions: %d, and " + "required budget: %d%n", bidLandscapePoint.getBidModifier(), bidLandscapePoint.getClicks(), bidLandscapePoint.getCost().getMicroAmount(), bidLandscapePoint.getImpressions(), bidLandscapePoint.getTotalLocalClicks(), bidLandscapePoint.getTotalLocalCost().getMicroAmount(), bidLandscapePoint.getTotalLocalImpressions(), bidLandscapePoint.getRequiredBudget().getMicroAmount());
                }
            }
        }
    } while (landscapePointsInPreviousPage >= PAGE_SIZE);
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) CriterionBidLandscapePage(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscapePage) CriterionBidLandscape(com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscape) DataServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.DataServiceInterface) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) BidLandscapeLandscapePoint(com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 30 with Campaign

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

the class AddProductScope method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the shopping campaign.
 * @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 campaign criterion service.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    ProductScope productScope = new ProductScope();
    // This set of dimensions is for demonstration purposes only. It would be
    // extremely unlikely that you want to include so many dimensions in your
    // product scope.
    ProductBrand productBrand = new ProductBrand();
    productBrand.setValue("Nexus");
    ProductCanonicalCondition productCanonicalCondition = new ProductCanonicalCondition();
    productCanonicalCondition.setCondition(ProductCanonicalConditionCondition.NEW);
    ProductCustomAttribute productCustomAttribute = new ProductCustomAttribute();
    productCustomAttribute.setType(ProductDimensionType.CUSTOM_ATTRIBUTE_0);
    productCustomAttribute.setValue("my attribute value");
    ProductOfferId productOfferId = new ProductOfferId();
    productOfferId.setValue("book1");
    ProductType productTypeLevel1Media = new ProductType();
    productTypeLevel1Media.setType(ProductDimensionType.PRODUCT_TYPE_L1);
    productTypeLevel1Media.setValue("Media");
    ProductType productTypeLevel2Books = new ProductType();
    productTypeLevel2Books.setType(ProductDimensionType.PRODUCT_TYPE_L2);
    productTypeLevel2Books.setValue("Books");
    // The value for the bidding category is a fixed ID for the 'Luggage & Bags'
    // category. You can retrieve IDs for categories from the ConstantDataService.
    // See the 'GetProductCategoryTaxonomy' example for more details.
    ProductBiddingCategory productBiddingCategory = new ProductBiddingCategory();
    productBiddingCategory.setType(ProductDimensionType.BIDDING_CATEGORY_L1);
    productBiddingCategory.setValue(-5914235892932915235L);
    productScope.setDimensions(new ProductDimension[] { productBrand, productCanonicalCondition, productCustomAttribute, productOfferId, productTypeLevel1Media, productTypeLevel2Books, productBiddingCategory });
    CampaignCriterion campaignCriterion = new CampaignCriterion();
    campaignCriterion.setCampaignId(campaignId);
    campaignCriterion.setCriterion(productScope);
    // Create operation.
    CampaignCriterionOperation criterionOperation = new CampaignCriterionOperation();
    criterionOperation.setOperand(campaignCriterion);
    criterionOperation.setOperator(Operator.ADD);
    // Make the mutate request.
    CampaignCriterionReturnValue result = campaignCriterionService.mutate(new CampaignCriterionOperation[] { criterionOperation });
    // Display the result.
    System.out.printf("Created a ProductScope criterion with ID %d.%n", result.getValue(0).getCriterion().getId());
}
Also used : CampaignCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue) ProductBrand(com.google.api.ads.adwords.axis.v201809.cm.ProductBrand) ProductOfferId(com.google.api.ads.adwords.axis.v201809.cm.ProductOfferId) CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) ProductCanonicalCondition(com.google.api.ads.adwords.axis.v201809.cm.ProductCanonicalCondition) ProductScope(com.google.api.ads.adwords.axis.v201809.cm.ProductScope) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) ProductCustomAttribute(com.google.api.ads.adwords.axis.v201809.cm.ProductCustomAttribute) ProductType(com.google.api.ads.adwords.axis.v201809.cm.ProductType) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) ProductBiddingCategory(com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategory)

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