Search in sources :

Example 1 with NegativeCampaignCriterion

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

the class AddCompleteCampaignsUsingBatchJob method buildCampaignCriterionOperations.

private static List<CampaignCriterionOperation> buildCampaignCriterionOperations(List<CampaignOperation> campaignOperations) {
    List<CampaignCriterionOperation> operations = new ArrayList<>();
    for (CampaignOperation campaignOperation : campaignOperations) {
        Keyword keyword = new Keyword();
        keyword.setMatchType(KeywordMatchType.BROAD);
        keyword.setText("venus");
        NegativeCampaignCriterion negativeCriterion = new NegativeCampaignCriterion();
        negativeCriterion.setCampaignId(campaignOperation.getOperand().getId());
        negativeCriterion.setCriterion(keyword);
        CampaignCriterionOperation operation = new CampaignCriterionOperation();
        operation.setOperand(negativeCriterion);
        operation.setOperator(Operator.ADD);
        operations.add(operation);
    }
    return operations;
}
Also used : CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) ArrayList(java.util.ArrayList) NegativeCampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion)

Example 2 with NegativeCampaignCriterion

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

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

the class AxisBatchJobUploadBodyProviderTest method addCampaignNegativeKeywordOperation.

@Override
protected void addCampaignNegativeKeywordOperation(BatchJobMutateRequest request, long campaignId, String keywordText, String keywordMatchType) {
    Keyword keyword = new Keyword();
    keyword.setText(keywordText);
    keyword.setMatchType(KeywordMatchType.fromString(keywordMatchType));
    NegativeCampaignCriterion negativeCriterion = new NegativeCampaignCriterion();
    negativeCriterion.setCampaignId(campaignId);
    negativeCriterion.setCriterion(keyword);
    CampaignCriterionOperation operation = new CampaignCriterionOperation();
    operation.setOperand(negativeCriterion);
    operation.setOperator(Operator.ADD);
    request.addOperation(operation);
}
Also used : CampaignCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation) Keyword(com.google.api.ads.adwords.axis.v201809.cm.Keyword) NegativeCampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion)

Example 4 with NegativeCampaignCriterion

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

the class JaxWsBatchJobUploadBodyProviderTest method addCampaignNegativeKeywordOperation.

@Override
protected void addCampaignNegativeKeywordOperation(BatchJobMutateRequest request, long campaignId, String keywordText, String keywordMatchType) {
    Keyword keyword = new Keyword();
    keyword.setText(keywordText);
    keyword.setMatchType(KeywordMatchType.valueOf(keywordMatchType));
    NegativeCampaignCriterion negativeCriterion = new NegativeCampaignCriterion();
    negativeCriterion.setCampaignId(campaignId);
    negativeCriterion.setCriterion(keyword);
    CampaignCriterionOperation operation = new CampaignCriterionOperation();
    operation.setOperand(negativeCriterion);
    operation.setOperator(Operator.ADD);
    request.addOperation(operation);
}
Also used : CampaignCriterionOperation(com.google.api.ads.adwords.jaxws.v201809.cm.CampaignCriterionOperation) Keyword(com.google.api.ads.adwords.jaxws.v201809.cm.Keyword) NegativeCampaignCriterion(com.google.api.ads.adwords.jaxws.v201809.cm.NegativeCampaignCriterion)

Aggregations

CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)3 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)3 NegativeCampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion)3 ArrayList (java.util.ArrayList)2 CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)1 CampaignCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue)1 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)1 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)1 ConstantOperand (com.google.api.ads.adwords.axis.v201809.cm.ConstantOperand)1 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)1 Function (com.google.api.ads.adwords.axis.v201809.cm.Function)1 Language (com.google.api.ads.adwords.axis.v201809.cm.Language)1 Location (com.google.api.ads.adwords.axis.v201809.cm.Location)1 LocationExtensionOperand (com.google.api.ads.adwords.axis.v201809.cm.LocationExtensionOperand)1 LocationGroups (com.google.api.ads.adwords.axis.v201809.cm.LocationGroups)1 CampaignCriterionOperation (com.google.api.ads.adwords.jaxws.v201809.cm.CampaignCriterionOperation)1 Keyword (com.google.api.ads.adwords.jaxws.v201809.cm.Keyword)1 NegativeCampaignCriterion (com.google.api.ads.adwords.jaxws.v201809.cm.NegativeCampaignCriterion)1