Search in sources :

Example 6 with CampaignCriterionOperation

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

the class AddUniversalAppCampaign method setCampaignTargetingCriteria.

/**
 * Sets the campaign's targeting criteria.
 */
private static void setCampaignTargetingCriteria(Campaign campaign, AdWordsServicesInterface adWordsServices, AdWordsSession session) throws ApiException, RemoteException {
    // Get the CampaignCriterionService.
    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));
    // 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(campaign.getId());
        campaignCriterion.setCriterion(criterion);
        operation.setOperand(campaignCriterion);
        operation.setOperator(Operator.ADD);
        operations.add(operation);
    }
    // Set the campaign targets.
    CampaignCriterionReturnValue returnValue = campaignCriterionService.mutate(operations.toArray(new CampaignCriterionOperation[operations.size()]));
    if (returnValue != null && returnValue.getValue() != null) {
        // Display added campaign targets.
        for (CampaignCriterion campaignCriterion : returnValue.getValue()) {
            System.out.printf("Campaign criteria of type '%s' and ID %d was added.%n", campaignCriterion.getCriterion().getCriterionType(), campaignCriterion.getCriterion().getId());
        }
    }
}
Also used : CampaignCriterionReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue) 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) Criterion(com.google.api.ads.adwords.axis.v201809.cm.Criterion) CampaignCriterion(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion) ArrayList(java.util.ArrayList) CampaignCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface) Location(com.google.api.ads.adwords.axis.v201809.cm.Location)

Example 7 with CampaignCriterionOperation

use of com.google.api.ads.adwords.jaxws.v201809.cm.CampaignCriterionOperation 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 8 with CampaignCriterionOperation

use of com.google.api.ads.adwords.jaxws.v201809.cm.CampaignCriterionOperation 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

CampaignCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionOperation)7 CampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterion)5 CampaignCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionServiceInterface)5 CampaignCriterionReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignCriterionReturnValue)4 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)3 Language (com.google.api.ads.adwords.axis.v201809.cm.Language)3 NegativeCampaignCriterion (com.google.api.ads.adwords.axis.v201809.cm.NegativeCampaignCriterion)3 ArrayList (java.util.ArrayList)3 Criterion (com.google.api.ads.adwords.axis.v201809.cm.Criterion)2 Location (com.google.api.ads.adwords.axis.v201809.cm.Location)2 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)1 ConstantOperand (com.google.api.ads.adwords.axis.v201809.cm.ConstantOperand)1 Draft (com.google.api.ads.adwords.axis.v201809.cm.Draft)1 DraftOperation (com.google.api.ads.adwords.axis.v201809.cm.DraftOperation)1 DraftServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.DraftServiceInterface)1 Function (com.google.api.ads.adwords.axis.v201809.cm.Function)1 LocationExtensionOperand (com.google.api.ads.adwords.axis.v201809.cm.LocationExtensionOperand)1 LocationGroups (com.google.api.ads.adwords.axis.v201809.cm.LocationGroups)1 Platform (com.google.api.ads.adwords.axis.v201809.cm.Platform)1 ProductBiddingCategory (com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategory)1