Search in sources :

Example 1 with Platform

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

the class AddAdGroupBidModifier method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group where bid modifiers 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 adGroupId) throws RemoteException {
    // Get the AdGroupBidModifierService.
    AdGroupBidModifierServiceInterface adGroupBidModifierService = adWordsServices.get(session, AdGroupBidModifierServiceInterface.class);
    // Create mobile platform. The ID can be found in the documentation.
    // https://developers.google.com/adwords/api/docs/appendix/platforms
    Platform mobile = new Platform();
    mobile.setId(30001L);
    AdGroupBidModifier adGroupBidModifier = new AdGroupBidModifier();
    adGroupBidModifier.setAdGroupId(adGroupId);
    adGroupBidModifier.setBidModifier(BID_MODIFIER);
    adGroupBidModifier.setCriterion(mobile);
    // Create ADD operation.
    AdGroupBidModifierOperation operation = new AdGroupBidModifierOperation();
    operation.setOperand(adGroupBidModifier);
    // Use 'ADD' to add a new modifier and 'SET' to update an existing one. A
    // modifier can be removed with the 'REMOVE' operator.
    operation.setOperator(Operator.ADD);
    // Update ad group bid modifier.
    AdGroupBidModifierReturnValue result = adGroupBidModifierService.mutate(new AdGroupBidModifierOperation[] { operation });
    for (AdGroupBidModifier bidModifierResult : result.getValue()) {
        System.out.printf("Campaign ID %d, ad group ID %d was updated with ad group level modifier: %.4f%n", bidModifierResult.getCampaignId(), bidModifierResult.getAdGroupId(), bidModifierResult.getBidModifier());
    }
}
Also used : AdGroupBidModifierReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierReturnValue) Platform(com.google.api.ads.adwords.axis.v201809.cm.Platform) AdGroupBidModifier(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifier) AdGroupBidModifierServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierServiceInterface) AdGroupBidModifierOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierOperation)

Example 2 with Platform

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

the class MigrateToExtensionSettings method createExtensionSetting.

/**
 * Creates the extension setting for a list of feed items.
 *
 * @param adWordsServices the AdWordsServices
 * @param session the AdWordsSession
 * @param feedItems the list of all feed items
 * @param campaignFeed the original campaign feed
 * @param feedItemIds IDs of the feed items for which extension settings should be created
 * @param platformRestrictions the platform restrictions for the new campaign extension setting
 */
private static void createExtensionSetting(AdWordsServicesInterface adWordsServices, AdWordsSession session, Map<Long, SiteLinkFromFeed> feedItems, CampaignFeed campaignFeed, Set<Long> feedItemIds, ExtensionSettingPlatform platformRestrictions) throws RemoteException {
    // Get the CampaignExtensionSettingService.
    CampaignExtensionSettingServiceInterface campaignExtensionSettingService = adWordsServices.get(session, CampaignExtensionSettingServiceInterface.class);
    CampaignExtensionSetting campaignExtensionSetting = new CampaignExtensionSetting();
    campaignExtensionSetting.setCampaignId(campaignFeed.getCampaignId());
    campaignExtensionSetting.setExtensionType(FeedType.SITELINK);
    ExtensionSetting extensionSetting = new ExtensionSetting();
    List<ExtensionFeedItem> extensionFeedItems = new ArrayList<>();
    for (Long feedItemId : feedItemIds) {
        SiteLinkFromFeed siteLinkFromFeed = feedItems.get(feedItemId);
        SitelinkFeedItem siteLinkFeedItem = new SitelinkFeedItem();
        siteLinkFeedItem.setSitelinkText(siteLinkFromFeed.text);
        if (siteLinkFromFeed.finalUrls != null && siteLinkFromFeed.finalUrls.length > 0) {
            siteLinkFeedItem.setSitelinkFinalUrls(new UrlList(siteLinkFromFeed.finalUrls));
            if (siteLinkFromFeed.finalMobileUrls != null && siteLinkFromFeed.finalMobileUrls.length > 0) {
                siteLinkFeedItem.setSitelinkFinalMobileUrls(new UrlList(siteLinkFromFeed.finalMobileUrls));
            }
            siteLinkFeedItem.setSitelinkTrackingUrlTemplate(siteLinkFromFeed.trackingUrlTemplate);
        } else {
            siteLinkFeedItem.setSitelinkUrl(siteLinkFromFeed.url);
        }
        siteLinkFeedItem.setSitelinkLine2(siteLinkFromFeed.line2);
        siteLinkFeedItem.setSitelinkLine3(siteLinkFromFeed.line3);
        extensionFeedItems.add(siteLinkFeedItem);
    }
    extensionSetting.setExtensions(extensionFeedItems.toArray(new ExtensionFeedItem[extensionFeedItems.size()]));
    extensionSetting.setPlatformRestrictions(platformRestrictions);
    campaignExtensionSetting.setExtensionSetting(extensionSetting);
    CampaignExtensionSettingOperation operation = new CampaignExtensionSettingOperation();
    operation.setOperand(campaignExtensionSetting);
    operation.setOperator(Operator.ADD);
    campaignExtensionSettingService.mutate(new CampaignExtensionSettingOperation[] { operation });
}
Also used : ExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.ExtensionSetting) CampaignExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSetting) CampaignExtensionSettingOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingOperation) ExtensionFeedItem(com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem) CampaignExtensionSetting(com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSetting) SitelinkFeedItem(com.google.api.ads.adwords.axis.v201809.cm.SitelinkFeedItem) ArrayList(java.util.ArrayList) CampaignExtensionSettingServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingServiceInterface) UrlList(com.google.api.ads.adwords.axis.v201809.cm.UrlList)

Example 3 with Platform

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

Example 4 with Platform

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

the class EstimateKeywordTraffic 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 TrafficEstimatorService.
    TrafficEstimatorServiceInterface trafficEstimatorService = adWordsServices.get(session, TrafficEstimatorServiceInterface.class);
    // Create keywords. Refer to the TrafficEstimatorService documentation for the maximum
    // number of keywords that can be passed in a single request.
    // https://developers.google.com/adwords/api/docs/reference/latest/TrafficEstimatorService
    List<Keyword> keywords = new ArrayList<Keyword>();
    Keyword marsCruiseKeyword = new Keyword();
    marsCruiseKeyword.setText("mars cruise");
    marsCruiseKeyword.setMatchType(KeywordMatchType.BROAD);
    keywords.add(marsCruiseKeyword);
    Keyword cheapCruiseKeyword = new Keyword();
    cheapCruiseKeyword.setText("cheap cruise");
    cheapCruiseKeyword.setMatchType(KeywordMatchType.PHRASE);
    keywords.add(cheapCruiseKeyword);
    Keyword cruiseKeyword = new Keyword();
    cruiseKeyword.setText("cruise");
    cruiseKeyword.setMatchType(KeywordMatchType.EXACT);
    keywords.add(cruiseKeyword);
    // Create a keyword estimate request for each keyword.
    List<KeywordEstimateRequest> keywordEstimateRequests = keywords.stream().map(keyword -> {
        KeywordEstimateRequest keywordEstimateRequest = new KeywordEstimateRequest();
        keywordEstimateRequest.setKeyword(keyword);
        return keywordEstimateRequest;
    }).collect(Collectors.toList());
    // Add a negative keyword to the traffic estimate.
    KeywordEstimateRequest negativeKeywordEstimateRequest = new KeywordEstimateRequest();
    negativeKeywordEstimateRequest.setKeyword(new Keyword(null, null, null, "hiking tour", KeywordMatchType.BROAD));
    negativeKeywordEstimateRequest.setIsNegative(true);
    keywordEstimateRequests.add(negativeKeywordEstimateRequest);
    // Create ad group estimate requests.
    List<AdGroupEstimateRequest> adGroupEstimateRequests = new ArrayList<AdGroupEstimateRequest>();
    AdGroupEstimateRequest adGroupEstimateRequest = new AdGroupEstimateRequest();
    adGroupEstimateRequest.setKeywordEstimateRequests(keywordEstimateRequests.toArray(new KeywordEstimateRequest[] {}));
    adGroupEstimateRequest.setMaxCpc(new Money(null, 1000000L));
    adGroupEstimateRequests.add(adGroupEstimateRequest);
    // Create campaign estimate requests.
    List<CampaignEstimateRequest> campaignEstimateRequests = new ArrayList<CampaignEstimateRequest>();
    CampaignEstimateRequest campaignEstimateRequest = new CampaignEstimateRequest();
    campaignEstimateRequest.setAdGroupEstimateRequests(adGroupEstimateRequests.toArray(new AdGroupEstimateRequest[] {}));
    Location unitedStates = new Location();
    unitedStates.setId(2840L);
    Language english = new Language();
    english.setId(1000L);
    campaignEstimateRequest.setCriteria(new Criterion[] { unitedStates, english });
    campaignEstimateRequests.add(campaignEstimateRequest);
    // Create selector.
    TrafficEstimatorSelector selector = new TrafficEstimatorSelector();
    selector.setCampaignEstimateRequests(campaignEstimateRequests.toArray(new CampaignEstimateRequest[] {}));
    // Optional: Request a list of campaign level estimates segmented by platform.
    selector.setPlatformEstimateRequested(true);
    // Get traffic estimates.
    TrafficEstimatorResult result = trafficEstimatorService.get(selector);
    // Display traffic estimates.
    if (result != null && result.getCampaignEstimates() != null && result.getCampaignEstimates().length > 0) {
        CampaignEstimate campaignEstimate = result.getCampaignEstimates()[0];
        // Display the campaign level estimates segmented by platform.
        if (campaignEstimate.getPlatformEstimates() != null) {
            for (PlatformCampaignEstimate platformEstimate : campaignEstimate.getPlatformEstimates()) {
                String platformMessage = String.format("Results for the platform with ID %d and name '%s':%n", platformEstimate.getPlatform().getId(), platformEstimate.getPlatform().getPlatformName());
                displayMeanEstimates(platformMessage, platformEstimate.getMinEstimate(), platformEstimate.getMaxEstimate());
            }
        }
        // Display the keyword estimates.
        KeywordEstimate[] keywordEstimates = campaignEstimate.getAdGroupEstimates()[0].getKeywordEstimates();
        for (int i = 0; i < keywordEstimates.length; i++) {
            if (Boolean.TRUE.equals(keywordEstimateRequests.get(i).getIsNegative())) {
                continue;
            }
            Keyword keyword = keywordEstimateRequests.get(i).getKeyword();
            KeywordEstimate keywordEstimate = keywordEstimates[i];
            String keywordMessage = String.format("Results for the keyword with text '%s' and match type '%s':%n", keyword.getText(), keyword.getMatchType());
            displayMeanEstimates(keywordMessage, keywordEstimate.getMin(), keywordEstimate.getMax());
        }
    } else {
        System.out.println("No traffic estimates were returned.");
    }
}
Also used : TrafficEstimatorServiceInterface(com.google.api.ads.adwords.axis.v201809.o.TrafficEstimatorServiceInterface) TrafficEstimatorResult(com.google.api.ads.adwords.axis.v201809.o.TrafficEstimatorResult) KeywordMatchType(com.google.api.ads.adwords.axis.v201809.cm.KeywordMatchType) AdGroupEstimateRequest(com.google.api.ads.adwords.axis.v201809.o.AdGroupEstimateRequest) ArrayList(java.util.ArrayList) CampaignEstimate(com.google.api.ads.adwords.axis.v201809.o.CampaignEstimate) OfflineCredentials(com.google.api.ads.common.lib.auth.OfflineCredentials) ApiException(com.google.api.ads.adwords.axis.v201809.cm.ApiException) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) Credential(com.google.api.client.auth.oauth2.Credential) OAuthException(com.google.api.ads.common.lib.exception.OAuthException) AdWordsServices(com.google.api.ads.adwords.axis.factory.AdWordsServices) Language(com.google.api.ads.adwords.axis.v201809.cm.Language) ConfigurationLoadException(com.google.api.ads.common.lib.conf.ConfigurationLoadException) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) Collectors(java.util.stream.Collectors) RemoteException(java.rmi.RemoteException) DEFAULT_CONFIGURATION_FILENAME(com.google.api.ads.common.lib.utils.Builder.DEFAULT_CONFIGURATION_FILENAME) List(java.util.List) AdWordsSession(com.google.api.ads.adwords.lib.client.AdWordsSession) AdWordsServicesInterface(com.google.api.ads.adwords.lib.factory.AdWordsServicesInterface) ApiError(com.google.api.ads.adwords.axis.v201809.cm.ApiError) ValidationException(com.google.api.ads.common.lib.exception.ValidationException) CampaignEstimateRequest(com.google.api.ads.adwords.axis.v201809.o.CampaignEstimateRequest) KeywordEstimate(com.google.api.ads.adwords.axis.v201809.o.KeywordEstimate) Criterion(com.google.api.ads.adwords.axis.v201809.cm.Criterion) Api(com.google.api.ads.common.lib.auth.OfflineCredentials.Api) Location(com.google.api.ads.adwords.axis.v201809.cm.Location) KeywordEstimateRequest(com.google.api.ads.adwords.axis.v201809.o.KeywordEstimateRequest) PlatformCampaignEstimate(com.google.api.ads.adwords.axis.v201809.o.PlatformCampaignEstimate) TrafficEstimatorSelector(com.google.api.ads.adwords.axis.v201809.o.TrafficEstimatorSelector) StatsEstimate(com.google.api.ads.adwords.axis.v201809.o.StatsEstimate) CampaignEstimateRequest(com.google.api.ads.adwords.axis.v201809.o.CampaignEstimateRequest) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) ArrayList(java.util.ArrayList) AdGroupEstimateRequest(com.google.api.ads.adwords.axis.v201809.o.AdGroupEstimateRequest) KeywordEstimateRequest(com.google.api.ads.adwords.axis.v201809.o.KeywordEstimateRequest) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) PlatformCampaignEstimate(com.google.api.ads.adwords.axis.v201809.o.PlatformCampaignEstimate) Language(com.google.api.ads.adwords.axis.v201809.cm.Language) CampaignEstimate(com.google.api.ads.adwords.axis.v201809.o.CampaignEstimate) PlatformCampaignEstimate(com.google.api.ads.adwords.axis.v201809.o.PlatformCampaignEstimate) TrafficEstimatorServiceInterface(com.google.api.ads.adwords.axis.v201809.o.TrafficEstimatorServiceInterface) TrafficEstimatorResult(com.google.api.ads.adwords.axis.v201809.o.TrafficEstimatorResult) TrafficEstimatorSelector(com.google.api.ads.adwords.axis.v201809.o.TrafficEstimatorSelector) Location(com.google.api.ads.adwords.axis.v201809.cm.Location) KeywordEstimate(com.google.api.ads.adwords.axis.v201809.o.KeywordEstimate)

Example 5 with Platform

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

the class SetBidModifier 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 CampaignCriterionService.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    // Create mobile platform. The ID can be found in the documentation.
    // https://developers.google.com/adwords/api/docs/appendix/platforms
    Platform mobile = new Platform();
    mobile.setId(30001L);
    // Create criterion with modified bid.
    CampaignCriterion campaignCriterion = new CampaignCriterion();
    campaignCriterion.setCampaignId(campaignId);
    campaignCriterion.setCriterion(mobile);
    campaignCriterion.setBidModifier(BID_MODIFIER);
    // Create SET operation.
    CampaignCriterionOperation operation = new CampaignCriterionOperation();
    operation.setOperand(campaignCriterion);
    operation.setOperator(Operator.SET);
    // Update campaign criterion.
    CampaignCriterionReturnValue result = campaignCriterionService.mutate(new CampaignCriterionOperation[] { operation });
    for (CampaignCriterion campaignCriterionResult : result.getValue()) {
        System.out.printf("Campaign criterion with campaign ID %d, criterion ID %d, " + "and type '%s' was modified with bid %.4f.%n", campaignCriterionResult.getCampaignId(), campaignCriterionResult.getCriterion().getId(), campaignCriterionResult.getCriterion().getType(), campaignCriterionResult.getBidModifier());
    }
}
Also used : CampaignCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue) CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) Platform(com.google.api.ads.adwords.axis.v201809.cm.Platform) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)

Aggregations

CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)2 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)2 Platform (com.google.api.ads.adwords.axis.v201809.cm.Platform)2 ArrayList (java.util.ArrayList)2 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)1 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 AdGroupBidModifier (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifier)1 AdGroupBidModifierOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierOperation)1 AdGroupBidModifierReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierReturnValue)1 AdGroupBidModifierServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierServiceInterface)1 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)1 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)1 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)1 CampaignCriterionPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionPage)1 CampaignCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue)1 CampaignExtensionSetting (com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSetting)1 CampaignExtensionSettingOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingOperation)1 CampaignExtensionSettingServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignExtensionSettingServiceInterface)1 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)1 ExtensionFeedItem (com.google.api.ads.adwords.axis.v201809.cm.ExtensionFeedItem)1