Search in sources :

Example 1 with Language

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

the class AddDynamicSearchAdsCampaign method createCampaign.

/**
 * Creates the campaign.
 */
private static Campaign createCampaign(AdWordsServicesInterface adWordsServices, AdWordsSession session, Budget budget) throws RemoteException, ApiException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create campaign.
    Campaign campaign = new Campaign();
    campaign.setName("Interplanetary Cruise #" + System.currentTimeMillis());
    campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);
    // Recommendation: Set the campaign to PAUSED when creating it to prevent
    // the ads from immediately serving. Set to ENABLED once you've added
    // targeting and the ads are ready to serve.
    campaign.setStatus(CampaignStatus.PAUSED);
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.MANUAL_CPC);
    campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // Only the budgetId should be sent, all other fields will be ignored by CampaignService.
    Budget campaignBudget = new Budget();
    campaignBudget.setBudgetId(budget.getBudgetId());
    campaign.setBudget(campaignBudget);
    // Required: Set the campaign's Dynamic Search Ads settings.
    DynamicSearchAdsSetting dynamicSearchAdsSetting = new DynamicSearchAdsSetting();
    // Required: Set the domain name and language.
    dynamicSearchAdsSetting.setDomainName("example.com");
    dynamicSearchAdsSetting.setLanguageCode("en");
    // Set the campaign settings.
    campaign.setSettings(new Setting[] { dynamicSearchAdsSetting });
    // Optional: Set the start date.
    campaign.setStartDate(DateTime.now().plusDays(1).toString("yyyyMMdd"));
    // Optional: Set the end date.
    campaign.setEndDate(DateTime.now().plusYears(1).toString("yyyyMMdd"));
    // Create the operation.
    CampaignOperation operation = new CampaignOperation();
    operation.setOperand(campaign);
    operation.setOperator(Operator.ADD);
    // Add the campaign.
    Campaign newCampaign = campaignService.mutate(new CampaignOperation[] { operation }).getValue(0);
    // Display the results.
    System.out.printf("Campaign with name '%s' and ID %d was added.%n", newCampaign.getName(), newCampaign.getId());
    return newCampaign;
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) DynamicSearchAdsSetting(com.google.api.ads.adwords.axis.v201809.cm.DynamicSearchAdsSetting)

Example 2 with Language

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

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

the class AddCampaignTargetingCriteria method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign where targeting criteria will be added.
 * @param locationFeedId optional ID of a location targeting feed.
 * @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, @Nullable Long locationFeedId) throws RemoteException {
    // Get the CampaignService.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    // Create locations. The IDs can be found in the documentation or
    // retrieved with the LocationCriterionService.
    Location california = new Location();
    california.setId(21137L);
    Location mexico = new Location();
    mexico.setId(2484L);
    // Create languages. The IDs can be found in the documentation or
    // retrieved with the ConstantDataService.
    Language english = new Language();
    english.setId(1000L);
    Language spanish = new Language();
    spanish.setId(1003L);
    List<Criterion> criteria = new ArrayList<>(Arrays.asList(california, mexico, english, spanish));
    // Distance targeting. Area of 10 miles around the locations in the location feed.
    if (locationFeedId != null) {
        LocationGroups radiusLocationGroup = new LocationGroups();
        radiusLocationGroup.setFeedId(locationFeedId);
        ConstantOperand radius = new ConstantOperand();
        radius.setType(ConstantOperandConstantType.DOUBLE);
        radius.setUnit(ConstantOperandUnit.MILES);
        radius.setDoubleValue(10d);
        LocationExtensionOperand distance = new LocationExtensionOperand();
        distance.setRadius(radius);
        Function radiusMatchingFunction = new Function();
        radiusMatchingFunction.setOperator(FunctionOperator.IDENTITY);
        radiusMatchingFunction.setLhsOperand(new FunctionArgumentOperand[] { distance });
        radiusLocationGroup.setMatchingFunction(radiusMatchingFunction);
        criteria.add(radiusLocationGroup);
    }
    // Create operations to add each of the criteria above.
    List<CampaignCriterionOperation> operations = new ArrayList<>();
    for (Criterion criterion : criteria) {
        CampaignCriterionOperation operation = new CampaignCriterionOperation();
        CampaignCriterion campaignCriterion = new CampaignCriterion();
        campaignCriterion.setCampaignId(campaignId);
        campaignCriterion.setCriterion(criterion);
        operation.setOperand(campaignCriterion);
        operation.setOperator(Operator.ADD);
        operations.add(operation);
    }
    // Add a negative campaign criterion.
    Keyword negativeKeyword = new Keyword();
    negativeKeyword.setText("jupiter cruise");
    negativeKeyword.setMatchType(KeywordMatchType.BROAD);
    CampaignCriterion negativeCriterion = new NegativeCampaignCriterion();
    negativeCriterion.setCampaignId(campaignId);
    negativeCriterion.setCriterion(negativeKeyword);
    CampaignCriterionOperation operation = new CampaignCriterionOperation();
    operation.setOperand(negativeCriterion);
    operation.setOperator(Operator.ADD);
    operations.add(operation);
    CampaignCriterionReturnValue result = campaignCriterionService.mutate(operations.toArray(new CampaignCriterionOperation[operations.size()]));
    // Display campaigns.
    for (CampaignCriterion campaignCriterion : result.getValue()) {
        System.out.printf("Campaign criterion with campaign ID %d, criterion ID %d, " + "and type '%s' was added.%n", campaignCriterion.getCampaignId(), campaignCriterion.getCriterion().getId(), campaignCriterion.getCriterion().getCriterionType());
    }
}
Also used : ConstantOperand(com.google.api.ads.adwords.axis.v201809.cm.ConstantOperand) CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) LocationGroups(com.google.api.ads.adwords.axis.v201809.cm.LocationGroups) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) NegativeCampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) ArrayList(java.util.ArrayList) NegativeCampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion) CampaignCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue) Function(com.google.api.ads.adwords.axis.v201809.cm.Function) Language(com.google.api.ads.adwords.axis.v201809.cm.Language) NegativeCampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) Criterion(com.google.api.ads.adwords.axis.v201809.cm.Criterion) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) LocationExtensionOperand(com.google.api.ads.adwords.axis.v201809.cm.LocationExtensionOperand) Location(com.google.api.ads.adwords.axis.v201809.cm.Location)

Example 4 with Language

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

the class GetTargetableLanguagesAndCarriers 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 ConstantDataService.
    ConstantDataServiceInterface constantDataService = adWordsServices.get(session, ConstantDataServiceInterface.class);
    // Get all carriers.
    Carrier[] carriers = constantDataService.getCarrierCriterion();
    // Display results.
    for (Carrier carrier : carriers) {
        System.out.printf("Carrier with name '%s', ID %d, and country code '%s' was found.%n", carrier.getName(), carrier.getId(), carrier.getCountryCode());
    }
    // Get all languages.
    Language[] languages = constantDataService.getLanguageCriterion();
    // Display results.
    for (Language language : languages) {
        System.out.printf("Language with name '%s' and ID %d was found.%n", language.getName(), language.getId());
    }
}
Also used : Language(com.google.api.ads.adwords.axis.v201809.cm.Language) Carrier(com.google.api.ads.adwords.axis.v201809.cm.Carrier) ConstantDataServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.ConstantDataServiceInterface)

Example 5 with Language

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

the class GetCampaignTargetingCriteria 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.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    int offset = 0;
    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(CampaignCriterionField.CampaignId, CampaignCriterionField.Id, CampaignCriterionField.CriteriaType, CampaignCriterionField.PlatformName, CampaignCriterionField.LanguageName, CampaignCriterionField.LocationName, CampaignCriterionField.KeywordText).in(CampaignCriterionField.CriteriaType, "KEYWORD", "LANGUAGE", "LOCATION", "PLATFORM").offset(0).limit(PAGE_SIZE).build();
    CampaignCriterionPage page = null;
    do {
        page = campaignCriterionService.get(selector);
        if (page.getEntries() != null) {
            // Display campaigns.
            for (CampaignCriterion campaignCriterion : page.getEntries()) {
                System.out.printf("Campaign criterion with campaign ID %d, criterion ID %d, " + "and type '%s' was found.%n", campaignCriterion.getCampaignId(), campaignCriterion.getCriterion().getId(), campaignCriterion.getCriterion().getCriterionType());
            }
        } else {
            System.out.println("No campaign criteria were found.");
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
    } while (offset < page.getTotalNumEntries());
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) CampaignCriterionPage(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionPage) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Aggregations

Language (com.google.api.ads.adwords.axis.v201809.cm.Language)6 CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)4 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)4 ArrayList (java.util.ArrayList)4 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)3 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)3 Location (com.google.api.ads.adwords.axis.v201809.cm.Location)3 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)3 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)2 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)2 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)2 CampaignCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue)2 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)2 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)2 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)2 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)1 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)1 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)1 CampaignCriterionPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionPage)1