Search in sources :

Example 6 with Attribute

use of com.google.api.ads.adwords.axis.v201809.o.Attribute 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)

Example 7 with Attribute

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

the class GetProductCategoryTaxonomy 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 constant data service.
    ConstantDataServiceInterface constantDataService = adWordsServices.get(session, ConstantDataServiceInterface.class);
    Selector selector = new SelectorBuilder().equals(ConstantDataField.Country, "US").build();
    ProductBiddingCategoryData[] results = constantDataService.getProductBiddingCategoryData(selector);
    // List of top level category nodes.
    List<CategoryNode> rootCategories = new ArrayList<>();
    // Map of category ID to category node for all categories found in the results.
    Map<Long, CategoryNode> biddingCategories = Maps.newHashMap();
    for (ProductBiddingCategoryData productBiddingCategoryData : results) {
        Long id = productBiddingCategoryData.getDimensionValue().getValue();
        String name = productBiddingCategoryData.getDisplayValue(0).getValue();
        CategoryNode node = biddingCategories.get(id);
        if (node == null) {
            node = new CategoryNode(id, name);
            biddingCategories.put(id, node);
        } else if (node.name == null) {
            // Ensure that the name attribute for the node is set. Name will be null for nodes added
            // to biddingCategories as a result of being a parentNode below.
            node.name = name;
        }
        if (productBiddingCategoryData.getParentDimensionValue() != null && productBiddingCategoryData.getParentDimensionValue().getValue() != null) {
            Long parentId = productBiddingCategoryData.getParentDimensionValue().getValue();
            CategoryNode parentNode = biddingCategories.get(parentId);
            if (parentNode == null) {
                parentNode = new CategoryNode(parentId);
                biddingCategories.put(parentId, parentNode);
            }
            parentNode.children.add(node);
        } else {
            rootCategories.add(node);
        }
    }
    displayCategories(rootCategories, "");
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) ArrayList(java.util.ArrayList) ConstantDataServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.ConstantDataServiceInterface) ProductBiddingCategoryData(com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategoryData) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 8 with Attribute

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

the class GetKeywordIdeas method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the optional ID of the seed ad group.
 * @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, @Nullable Long adGroupId) throws RemoteException {
    // Get the TargetingIdeaService.
    TargetingIdeaServiceInterface targetingIdeaService = adWordsServices.get(session, TargetingIdeaServiceInterface.class);
    // Create selector.
    TargetingIdeaSelector selector = new TargetingIdeaSelector();
    selector.setRequestType(RequestType.IDEAS);
    selector.setIdeaType(IdeaType.KEYWORD);
    selector.setRequestedAttributeTypes(new AttributeType[] { AttributeType.KEYWORD_TEXT, AttributeType.SEARCH_VOLUME, AttributeType.AVERAGE_CPC, AttributeType.COMPETITION, AttributeType.CATEGORY_PRODUCTS_AND_SERVICES });
    // Set selector paging (required for targeting idea service).
    Paging paging = new Paging();
    paging.setStartIndex(0);
    paging.setNumberResults(10);
    selector.setPaging(paging);
    List<SearchParameter> searchParameters = new ArrayList<>();
    // Create related to query search parameter.
    RelatedToQuerySearchParameter relatedToQuerySearchParameter = new RelatedToQuerySearchParameter();
    relatedToQuerySearchParameter.setQueries(new String[] { "bakery", "pastries", "birthday cake" });
    searchParameters.add(relatedToQuerySearchParameter);
    // Language setting (optional).
    // The ID can be found in the documentation:
    // https://developers.google.com/adwords/api/docs/appendix/languagecodes
    // See the documentation for limits on the number of allowed language parameters:
    // https://developers.google.com/adwords/api/docs/reference/latest/TargetingIdeaService.LanguageSearchParameter
    LanguageSearchParameter languageParameter = new LanguageSearchParameter();
    Language english = new Language();
    english.setId(1000L);
    languageParameter.setLanguages(new Language[] { english });
    searchParameters.add(languageParameter);
    // Create network search parameter (optional).
    NetworkSetting networkSetting = new NetworkSetting();
    networkSetting.setTargetGoogleSearch(true);
    networkSetting.setTargetSearchNetwork(false);
    networkSetting.setTargetContentNetwork(false);
    networkSetting.setTargetPartnerSearchNetwork(false);
    NetworkSearchParameter networkSearchParameter = new NetworkSearchParameter();
    networkSearchParameter.setNetworkSetting(networkSetting);
    searchParameters.add(networkSearchParameter);
    // Optional: Use an existing ad group to generate ideas.
    if (adGroupId != null) {
        SeedAdGroupIdSearchParameter seedAdGroupIdSearchParameter = new SeedAdGroupIdSearchParameter();
        seedAdGroupIdSearchParameter.setAdGroupId(adGroupId);
        searchParameters.add(seedAdGroupIdSearchParameter);
    }
    selector.setSearchParameters(searchParameters.toArray(new SearchParameter[searchParameters.size()]));
    // Get keyword ideas.
    TargetingIdeaPage page = targetingIdeaService.get(selector);
    // Display keyword ideas.
    for (TargetingIdea targetingIdea : page.getEntries()) {
        Map<AttributeType, Attribute> data = Maps.toMap(targetingIdea.getData());
        StringAttribute keyword = (StringAttribute) data.get(AttributeType.KEYWORD_TEXT);
        IntegerSetAttribute categories = (IntegerSetAttribute) data.get(AttributeType.CATEGORY_PRODUCTS_AND_SERVICES);
        String categoriesString = "(none)";
        if (categories != null && categories.getValue() != null) {
            categoriesString = Joiner.on(", ").join(Ints.asList(categories.getValue()));
        }
        Long averageMonthlySearches = ((LongAttribute) data.get(AttributeType.SEARCH_VOLUME)).getValue();
        Money averageCpc = ((MoneyAttribute) data.get(AttributeType.AVERAGE_CPC)).getValue();
        Double competition = ((DoubleAttribute) data.get(AttributeType.COMPETITION)).getValue();
        System.out.printf("Keyword with text '%s', average monthly search volume %d, " + "average CPC %d, and competition %.2f " + "was found with categories: %s%n", keyword.getValue(), averageMonthlySearches, averageCpc.getMicroAmount(), competition, categoriesString);
    }
    if (page.getEntries() == null) {
        System.out.println("No related keywords were found.");
    }
}
Also used : SeedAdGroupIdSearchParameter(com.google.api.ads.adwords.axis.v201809.o.SeedAdGroupIdSearchParameter) TargetingIdea(com.google.api.ads.adwords.axis.v201809.o.TargetingIdea) DoubleAttribute(com.google.api.ads.adwords.axis.v201809.o.DoubleAttribute) Attribute(com.google.api.ads.adwords.axis.v201809.o.Attribute) LongAttribute(com.google.api.ads.adwords.axis.v201809.o.LongAttribute) MoneyAttribute(com.google.api.ads.adwords.axis.v201809.o.MoneyAttribute) StringAttribute(com.google.api.ads.adwords.axis.v201809.o.StringAttribute) IntegerSetAttribute(com.google.api.ads.adwords.axis.v201809.o.IntegerSetAttribute) ArrayList(java.util.ArrayList) StringAttribute(com.google.api.ads.adwords.axis.v201809.o.StringAttribute) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) Language(com.google.api.ads.adwords.axis.v201809.cm.Language) TargetingIdeaPage(com.google.api.ads.adwords.axis.v201809.o.TargetingIdeaPage) AttributeType(com.google.api.ads.adwords.axis.v201809.o.AttributeType) LongAttribute(com.google.api.ads.adwords.axis.v201809.o.LongAttribute) MoneyAttribute(com.google.api.ads.adwords.axis.v201809.o.MoneyAttribute) LanguageSearchParameter(com.google.api.ads.adwords.axis.v201809.o.LanguageSearchParameter) NetworkSearchParameter(com.google.api.ads.adwords.axis.v201809.o.NetworkSearchParameter) SearchParameter(com.google.api.ads.adwords.axis.v201809.o.SearchParameter) RelatedToQuerySearchParameter(com.google.api.ads.adwords.axis.v201809.o.RelatedToQuerySearchParameter) SeedAdGroupIdSearchParameter(com.google.api.ads.adwords.axis.v201809.o.SeedAdGroupIdSearchParameter) TargetingIdeaSelector(com.google.api.ads.adwords.axis.v201809.o.TargetingIdeaSelector) Paging(com.google.api.ads.adwords.axis.v201809.cm.Paging) IntegerSetAttribute(com.google.api.ads.adwords.axis.v201809.o.IntegerSetAttribute) TargetingIdeaServiceInterface(com.google.api.ads.adwords.axis.v201809.o.TargetingIdeaServiceInterface) NetworkSearchParameter(com.google.api.ads.adwords.axis.v201809.o.NetworkSearchParameter) LanguageSearchParameter(com.google.api.ads.adwords.axis.v201809.o.LanguageSearchParameter) DoubleAttribute(com.google.api.ads.adwords.axis.v201809.o.DoubleAttribute) NetworkSetting(com.google.api.ads.adwords.axis.v201809.cm.NetworkSetting) RelatedToQuerySearchParameter(com.google.api.ads.adwords.axis.v201809.o.RelatedToQuerySearchParameter)

Example 9 with Attribute

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

the class AddAdCustomizer method createFeedItemAddOperation.

/**
 * Creates a FeedItemOperation that will create a FeedItem with the specified values and ad group
 * target when sent to FeedItemService.mutate.
 *
 * @param name the value for the name attribute of the FeedItem
 * @param price the value for the price attribute of the FeedItem
 * @param date the value for the date attribute of the FeedItem
 * @param adCustomizerFeed the customizer feed
 * @return a new FeedItemOperation for adding a FeedItem
 */
private static FeedItemOperation createFeedItemAddOperation(String name, String price, String date, AdCustomizerFeed adCustomizerFeed) {
    FeedItem feedItem = new FeedItem();
    feedItem.setFeedId(adCustomizerFeed.getFeedId());
    List<FeedItemAttributeValue> attributeValues = new ArrayList<>();
    // FeedAttributes appear in the same order as they were created - Name, Price, Date.
    // See the createCustomizerFeed method for details.
    FeedItemAttributeValue nameAttributeValue = new FeedItemAttributeValue();
    nameAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(0).getId());
    nameAttributeValue.setStringValue(name);
    attributeValues.add(nameAttributeValue);
    FeedItemAttributeValue priceAttributeValue = new FeedItemAttributeValue();
    priceAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(1).getId());
    priceAttributeValue.setStringValue(price);
    attributeValues.add(priceAttributeValue);
    FeedItemAttributeValue dateAttributeValue = new FeedItemAttributeValue();
    dateAttributeValue.setFeedAttributeId(adCustomizerFeed.getFeedAttributes(2).getId());
    dateAttributeValue.setStringValue(date);
    attributeValues.add(dateAttributeValue);
    feedItem.setAttributeValues(attributeValues.toArray(new FeedItemAttributeValue[attributeValues.size()]));
    FeedItemOperation feedItemOperation = new FeedItemOperation();
    feedItemOperation.setOperand(feedItem);
    feedItemOperation.setOperator(Operator.ADD);
    return feedItemOperation;
}
Also used : FeedItem(com.google.api.ads.adwords.axis.v201809.cm.FeedItem) FeedItemAttributeValue(com.google.api.ads.adwords.axis.v201809.cm.FeedItemAttributeValue) ArrayList(java.util.ArrayList) FeedItemOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation)

Example 10 with Attribute

use of com.google.api.ads.adwords.axis.v201809.o.Attribute 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)

Aggregations

ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 FeedItem (com.google.api.ads.adwords.axis.v201809.cm.FeedItem)2 FeedItemAttributeValue (com.google.api.ads.adwords.axis.v201809.cm.FeedItemAttributeValue)2 ProductCustomAttribute (com.google.api.ads.adwords.axis.v201809.cm.ProductCustomAttribute)2 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 AdGroupBidLandscapePage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidLandscapePage)1 AttributeFieldMapping (com.google.api.ads.adwords.axis.v201809.cm.AttributeFieldMapping)1 CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)1 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)1 CampaignCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue)1 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)1 ConstantDataServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.ConstantDataServiceInterface)1 CriterionBidLandscapePage (com.google.api.ads.adwords.axis.v201809.cm.CriterionBidLandscapePage)1 CustomParameter (com.google.api.ads.adwords.axis.v201809.cm.CustomParameter)1 CustomParameters (com.google.api.ads.adwords.axis.v201809.cm.CustomParameters)1 ExtensionFeedItem (com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem)1 FeedItemOperation (com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation)1 FeedMapping (com.google.api.ads.adwords.axis.v201809.cm.FeedMapping)1 FeedMappingPage (com.google.api.ads.adwords.axis.v201809.cm.FeedMappingPage)1