Search in sources :

Example 31 with Feed

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

the class AddShoppingDynamicRemarketingCampaign method runExample.

/**
 * Runs the example.
 *
 * @param services the services factory.
 * @param session the session.
 * @param merchantId the ID of the merchant center account from which to source product feed data.
 * @param budgetId the ID of a shared budget to associate with the campaign.
 * @param userListId the ID of a user list to target.
 * @throws ApiException if the API request failed with one or more service errors.
 * @throws RemoteException if the API request failed due to other errors.
 * @throws IOException if the ad images failed to load.
 */
private static void runExample(AdWordsServicesInterface services, AdWordsSession session, long merchantId, long budgetId, long userListId) throws IOException {
    Campaign campaign = createCampaign(services, session, merchantId, budgetId);
    System.out.printf("Campaign with name '%s' and ID %d was added.%n", campaign.getName(), campaign.getId());
    AdGroup adGroup = createAdGroup(services, session, campaign);
    System.out.printf("Ad group with name '%s' and ID %d was added.%n", adGroup.getName(), adGroup.getId());
    AdGroupAd adGroupAd = createAd(services, session, adGroup);
    System.out.printf("Responsive display ad with ID %d was added.%n", adGroupAd.getAd().getId());
    attachUserList(services, session, adGroup, userListId);
    System.out.printf("User list with ID %d was attached to ad group with ID %d.%n", userListId, adGroup.getId());
}
Also used : Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup)

Example 32 with Feed

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

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

the class MigrateToExtensionSettings method deleteCampaignFeed.

/**
 * Deletes a campaign feed.
 */
private static CampaignFeed deleteCampaignFeed(AdWordsServicesInterface adWordsServices, AdWordsSession session, CampaignFeed campaignFeed) throws RemoteException {
    // Get the CampaignFeedService.
    CampaignFeedServiceInterface campaignFeedService = adWordsServices.get(session, CampaignFeedServiceInterface.class);
    CampaignFeedOperation operation = new CampaignFeedOperation();
    operation.setOperand(campaignFeed);
    operation.setOperator(Operator.REMOVE);
    return campaignFeedService.mutate(new CampaignFeedOperation[] { operation }).getValue(0);
}
Also used : CampaignFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface) CampaignFeedOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation)

Example 34 with Feed

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

the class MigrateToExtensionSettings method getFeedMapping.

/**
 * Gets the feed mapping for a feed.
 *
 * @return a multimap from feed attribute ID to the set of field IDs mapped to the attribute
 */
private static Multimap<Long, Integer> getFeedMapping(AdWordsServicesInterface adWordsServices, AdWordsSession session, Feed feed, long placeholderType) throws RemoteException {
    // Get the FeedMappingService.
    FeedMappingServiceInterface feedMappingService = adWordsServices.get(session, FeedMappingServiceInterface.class);
    String query = String.format("SELECT FeedMappingId, AttributeFieldMappings WHERE FeedId = %d and PlaceholderType = %d " + "AND Status = 'ENABLED'", feed.getId(), placeholderType);
    Multimap<Long, Integer> attributeMappings = HashMultimap.create();
    int offset = 0;
    FeedMappingPage feedMappingPage;
    do {
        String pageQuery = String.format(query + " LIMIT %d, %d", offset, PAGE_SIZE);
        feedMappingPage = feedMappingService.query(pageQuery);
        if (feedMappingPage.getEntries() != null) {
            // than one field if needed.
            for (FeedMapping feedMapping : feedMappingPage.getEntries()) {
                for (AttributeFieldMapping attributeMapping : feedMapping.getAttributeFieldMappings()) {
                    attributeMappings.put(attributeMapping.getFeedAttributeId(), attributeMapping.getFieldId());
                }
            }
        }
        offset += PAGE_SIZE;
    } while (offset < feedMappingPage.getTotalNumEntries());
    return attributeMappings;
}
Also used : FeedMappingPage(com.google.api.ads.adwords.axis.v201809.cm.FeedMappingPage) AttributeFieldMapping(com.google.api.ads.adwords.axis.v201809.cm.AttributeFieldMapping) FeedMappingServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface) FeedMapping(com.google.api.ads.adwords.axis.v201809.cm.FeedMapping)

Example 35 with Feed

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

the class MigrateToExtensionSettings method getFeedItems.

/**
 * Returns the feed items for a feed.
 */
private static List<FeedItem> getFeedItems(AdWordsServicesInterface adWordsServices, AdWordsSession session, Feed feed) throws RemoteException {
    // Get the FeedItemService.
    FeedItemServiceInterface feedItemService = adWordsServices.get(session, FeedItemServiceInterface.class);
    String query = String.format("SELECT FeedItemId, AttributeValues WHERE Status = 'ENABLED' AND FeedId = %d", feed.getId());
    List<FeedItem> feedItems = new ArrayList<>();
    int offset = 0;
    FeedItemPage feedItemPage;
    do {
        String pageQuery = String.format(query + " LIMIT %d, %d", offset, PAGE_SIZE);
        feedItemPage = feedItemService.query(pageQuery);
        if (feedItemPage.getEntries() != null) {
            feedItems.addAll(Arrays.asList(feedItemPage.getEntries()));
        }
        offset += PAGE_SIZE;
    } while (offset < feedItemPage.getTotalNumEntries());
    return feedItems;
}
Also used : FeedItem(com.google.api.ads.adwords.axis.v201809.cm.FeedItem) ExtensionFeedItem(com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem) SitelinkFeedItem(com.google.api.ads.adwords.axis.v201809.cm.SitelinkFeedItem) FeedItemServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface) ArrayList(java.util.ArrayList) FeedItemPage(com.google.api.ads.adwords.axis.v201809.cm.FeedItemPage)

Aggregations

ArrayList (java.util.ArrayList)11 FeedItem (com.google.api.ads.adwords.axis.v201809.cm.FeedItem)9 FeedItemOperation (com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation)7 CampaignFeed (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeed)6 CampaignFeedServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface)6 Feed (com.google.api.ads.adwords.axis.v201809.cm.Feed)6 ExtensionFeedItem (com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem)5 FeedItemAttributeValue (com.google.api.ads.adwords.axis.v201809.cm.FeedItemAttributeValue)5 FeedItemServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedItemServiceInterface)5 SitelinkFeedItem (com.google.api.ads.adwords.axis.v201809.cm.SitelinkFeedItem)5 AttributeFieldMapping (com.google.api.ads.adwords.axis.v201809.cm.AttributeFieldMapping)4 CampaignFeedOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation)4 FeedMapping (com.google.api.ads.adwords.axis.v201809.cm.FeedMapping)4 FeedMappingServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface)4 FeedServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.FeedServiceInterface)4 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)3 CampaignFeedPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedPage)3 ConstantOperand (com.google.api.ads.adwords.axis.v201809.cm.ConstantOperand)3 ExtensionSetting (com.google.api.ads.adwords.axis.v201809.cm.ExtensionSetting)3 Function (com.google.api.ads.adwords.axis.v201809.cm.Function)3