Search in sources :

Example 31 with Criterion

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

the class UpdateKeyword method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group for the criterion.
 * @param keywordId the ID of the criterion to update.
 * @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, Long keywordId) throws RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    // Create ad group criterion with updated bid.
    Criterion criterion = new Criterion();
    criterion.setId(keywordId);
    BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
    biddableAdGroupCriterion.setAdGroupId(adGroupId);
    biddableAdGroupCriterion.setCriterion(criterion);
    // Create bids.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    CpcBid bid = new CpcBid();
    bid.setBid(new Money(null, 10000000L));
    biddingStrategyConfiguration.setBids(new Bids[] { bid });
    biddableAdGroupCriterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // Create operations.
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
    operation.setOperand(biddableAdGroupCriterion);
    operation.setOperator(Operator.SET);
    AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] { operation };
    // Update ad group criteria.
    AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
    // Display ad group criteria.
    for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
        if (adGroupCriterionResult instanceof BiddableAdGroupCriterion) {
            biddableAdGroupCriterion = (BiddableAdGroupCriterion) adGroupCriterionResult;
            CpcBid criterionCpcBid = null;
            // Find the criterion-level CpcBid among the keyword's bids.
            for (Bids bids : biddableAdGroupCriterion.getBiddingStrategyConfiguration().getBids()) {
                if (bids instanceof CpcBid) {
                    CpcBid cpcBid = (CpcBid) bids;
                    if (BidSource.CRITERION.equals(cpcBid.getCpcBidSource())) {
                        criterionCpcBid = cpcBid;
                    }
                }
            }
            System.out.printf("Ad group criterion with ad group ID %d, criterion ID %d, type " + "'%s', and bid %d was updated.%n", biddableAdGroupCriterion.getAdGroupId(), biddableAdGroupCriterion.getCriterion().getId(), biddableAdGroupCriterion.getCriterion().getCriterionType(), criterionCpcBid.getBid().getMicroAmount());
        }
    }
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) AdGroupCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) Criterion(com.google.api.ads.adwords.axis.v201809.cm.Criterion) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) Bids(com.google.api.ads.adwords.axis.v201809.cm.Bids) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid)

Example 32 with Criterion

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

the class AddDraft method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param baseCampaignId the base campaign ID for the draft.
 * @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 baseCampaignId) throws RemoteException {
    // Get the DraftService.
    DraftServiceInterface draftService = adWordsServices.get(session, DraftServiceInterface.class);
    Draft draft = new Draft();
    draft.setBaseCampaignId(baseCampaignId);
    draft.setDraftName("Test Draft #" + System.currentTimeMillis());
    DraftOperation draftOperation = new DraftOperation();
    draftOperation.setOperator(Operator.ADD);
    draftOperation.setOperand(draft);
    draft = draftService.mutate(new DraftOperation[] { draftOperation }).getValue(0);
    System.out.printf("Draft with ID %d and base campaign ID %d and draft campaign ID %d created.%n", draft.getDraftId(), draft.getBaseCampaignId(), draft.getDraftCampaignId());
    // Once the draft is created, you can modify the draft campaign as if it
    // were a real campaign. For example, you may add criteria, adjust bids,
    // or even include additional ads. Adding a criterion is shown here.
    CampaignCriterionServiceInterface campaignCriterionService = adWordsServices.get(session, CampaignCriterionServiceInterface.class);
    Language language = new Language();
    // Spanish
    language.setId(1003L);
    // Make sure to use the draftCampaignId when modifying the virtual draft campaign.
    CampaignCriterion campaignCriterion = new CampaignCriterion();
    campaignCriterion.setCampaignId(draft.getDraftCampaignId());
    campaignCriterion.setCriterion(language);
    CampaignCriterionOperation criterionOperation = new CampaignCriterionOperation();
    criterionOperation.setOperator(Operator.ADD);
    criterionOperation.setOperand(campaignCriterion);
    campaignCriterion = campaignCriterionService.mutate(new CampaignCriterionOperation[] { criterionOperation }).getValue(0);
    System.out.printf("Draft updated to include criteria in draft campaign ID %d.%n", draft.getDraftCampaignId());
}
Also used : Draft(com.google.api.ads.adwords.axis.v201809.cm.Draft) DraftOperation(com.google.api.ads.adwords.axis.v201809.cm.DraftOperation) CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) Language(com.google.api.ads.adwords.axis.v201809.cm.Language) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) DraftServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.DraftServiceInterface)

Example 33 with Criterion

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

Example 34 with Criterion

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

the class SetAdParameters method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group of the keyword.
 * @param keywordId the ID of the keyword.
 * @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, Long keywordId) throws RemoteException {
    // Get the AdParamService.
    AdParamServiceInterface adParamService = adWordsServices.get(session, AdParamServiceInterface.class);
    // Create ad params.
    AdParam adParam1 = new AdParam();
    adParam1.setAdGroupId(adGroupId);
    adParam1.setCriterionId(keywordId);
    adParam1.setInsertionText("100");
    adParam1.setParamIndex(1);
    AdParam adParam2 = new AdParam();
    adParam2.setAdGroupId(adGroupId);
    adParam2.setCriterionId(keywordId);
    adParam2.setInsertionText("$40");
    adParam2.setParamIndex(2);
    // Create operations.
    AdParamOperation adParamOperation1 = new AdParamOperation();
    adParamOperation1.setOperand(adParam1);
    adParamOperation1.setOperator(Operator.SET);
    AdParamOperation adParamOperation2 = new AdParamOperation();
    adParamOperation2.setOperand(adParam2);
    adParamOperation2.setOperator(Operator.SET);
    AdParamOperation[] operations = new AdParamOperation[] { adParamOperation1, adParamOperation2 };
    // Set ad parameters.
    AdParam[] adParams = adParamService.mutate(operations);
    // Display ad parameters.
    for (AdParam adParam : adParams) {
        System.out.printf("Ad parameter with ad group ID %d, criterion ID %d, insertion text " + "'%s', and parameter index %d was set.%n", adParam.getAdGroupId(), adParam.getCriterionId(), adParam.getInsertionText(), adParam.getParamIndex());
    }
}
Also used : AdParam(com.google.api.ads.adwords.axis.v201809.cm.AdParam) AdParamOperation(com.google.api.ads.adwords.axis.v201809.cm.AdParamOperation) AdParamServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdParamServiceInterface)

Example 35 with Criterion

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

the class AddKeywords method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group where the keywords will be created.
 * @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 UnsupportedEncodingException if encoding the final URL failed.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws RemoteException, UnsupportedEncodingException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    // Create keywords.
    Keyword keyword1 = new Keyword();
    keyword1.setText("mars cruise");
    keyword1.setMatchType(KeywordMatchType.BROAD);
    Keyword keyword2 = new Keyword();
    keyword2.setText("space hotel");
    keyword2.setMatchType(KeywordMatchType.EXACT);
    // Create biddable ad group criterion.
    BiddableAdGroupCriterion keywordBiddableAdGroupCriterion1 = new BiddableAdGroupCriterion();
    keywordBiddableAdGroupCriterion1.setAdGroupId(adGroupId);
    keywordBiddableAdGroupCriterion1.setCriterion(keyword1);
    // You can optionally provide these field(s).
    keywordBiddableAdGroupCriterion1.setUserStatus(UserStatus.PAUSED);
    String encodedFinalUrl = String.format("http://example.com/mars/cruise/?kw=%s", URLEncoder.encode(keyword1.getText(), UTF_8.name()));
    keywordBiddableAdGroupCriterion1.setFinalUrls(new UrlList(new String[] { encodedFinalUrl }));
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    CpcBid bid = new CpcBid();
    bid.setBid(new Money(null, 10000000L));
    biddingStrategyConfiguration.setBids(new Bids[] { bid });
    keywordBiddableAdGroupCriterion1.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    NegativeAdGroupCriterion keywordNegativeAdGroupCriterion2 = new NegativeAdGroupCriterion();
    keywordNegativeAdGroupCriterion2.setAdGroupId(adGroupId);
    keywordNegativeAdGroupCriterion2.setCriterion(keyword2);
    // Create operations.
    AdGroupCriterionOperation keywordAdGroupCriterionOperation1 = new AdGroupCriterionOperation();
    keywordAdGroupCriterionOperation1.setOperand(keywordBiddableAdGroupCriterion1);
    keywordAdGroupCriterionOperation1.setOperator(Operator.ADD);
    AdGroupCriterionOperation keywordAdGroupCriterionOperation2 = new AdGroupCriterionOperation();
    keywordAdGroupCriterionOperation2.setOperand(keywordNegativeAdGroupCriterion2);
    keywordAdGroupCriterionOperation2.setOperator(Operator.ADD);
    AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] { keywordAdGroupCriterionOperation1, keywordAdGroupCriterionOperation2 };
    // Add keywords.
    AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);
    // Display results.
    for (AdGroupCriterion adGroupCriterionResult : result.getValue()) {
        System.out.printf("Keyword ad group criterion with ad group ID %d, criterion ID %d, " + "text '%s', and match type '%s' was added.%n", adGroupCriterionResult.getAdGroupId(), adGroupCriterionResult.getCriterion().getId(), ((Keyword) adGroupCriterionResult.getCriterion()).getText(), ((Keyword) adGroupCriterionResult.getCriterion()).getMatchType());
    }
}
Also used : AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) AdGroupCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) UrlList(com.google.api.ads.adwords.axis.v201809.cm.UrlList) NegativeAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)

Aggregations

AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)14 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)13 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)11 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)10 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)9 ArrayList (java.util.ArrayList)9 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)8 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)8 AdGroupCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionReturnValue)7 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)7 CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)6 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)6 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)5 CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)5 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)5 NegativeAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeAdGroupCriterion)5 ProductPartition (com.google.api.ads.adwords.axis.v201809.cm.ProductPartition)5 BidLandscapeLandscapePoint (com.google.api.ads.adwords.axis.v201809.cm.BidLandscapeLandscapePoint)4 Bids (com.google.api.ads.adwords.axis.v201809.cm.Bids)4 CampaignCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue)4