Search in sources :

Example 1 with Campaign

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

the class AddCompleteCampaignsUsingBatchJob method buildCampaignOperations.

private static List<CampaignOperation> buildCampaignOperations(Iterator<Long> tempIdGenerator, String namePrefix, BudgetOperation budgetOperation) {
    long budgetId = budgetOperation.getOperand().getBudgetId();
    List<CampaignOperation> operations = new ArrayList<>();
    for (int i = 0; i < NUMBER_OF_CAMPAIGNS_TO_ADD; i++) {
        Campaign campaign = new Campaign();
        campaign.setName(String.format("Batch Campaign %s.%s", namePrefix, i));
        // 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);
        campaign.setId(tempIdGenerator.next());
        campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);
        Budget budget = new Budget();
        budget.setBudgetId(budgetId);
        campaign.setBudget(budget);
        BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
        biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.MANUAL_CPC);
        // You can optionally provide a bidding scheme in place of the type.
        ManualCpcBiddingScheme cpcBiddingScheme = new ManualCpcBiddingScheme();
        biddingStrategyConfiguration.setBiddingScheme(cpcBiddingScheme);
        campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
        CampaignOperation operation = new CampaignOperation();
        operation.setOperand(campaign);
        operation.setOperator(Operator.ADD);
        operations.add(operation);
    }
    return operations;
}
Also used : 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) ArrayList(java.util.ArrayList) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) ManualCpcBiddingScheme(com.google.api.ads.adwords.axis.v201809.cm.ManualCpcBiddingScheme)

Example 2 with Campaign

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

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

the class AddCampaigns 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 BudgetService.
    BudgetServiceInterface budgetService = adWordsServices.get(session, BudgetServiceInterface.class);
    // Create a budget, which can be shared by multiple campaigns.
    Budget sharedBudget = new Budget();
    sharedBudget.setName("Interplanetary Cruise #" + System.currentTimeMillis());
    Money budgetAmount = new Money();
    budgetAmount.setMicroAmount(50_000_000L);
    sharedBudget.setAmount(budgetAmount);
    sharedBudget.setDeliveryMethod(BudgetBudgetDeliveryMethod.STANDARD);
    BudgetOperation budgetOperation = new BudgetOperation();
    budgetOperation.setOperand(sharedBudget);
    budgetOperation.setOperator(Operator.ADD);
    // Add the budget
    Long budgetId = budgetService.mutate(new BudgetOperation[] { budgetOperation }).getValue(0).getBudgetId();
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create campaign.
    Campaign campaign = new Campaign();
    campaign.setName("Interplanetary Cruise #" + System.currentTimeMillis());
    // 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);
    // You can optionally provide a bidding scheme in place of the type.
    ManualCpcBiddingScheme cpcBiddingScheme = new ManualCpcBiddingScheme();
    biddingStrategyConfiguration.setBiddingScheme(cpcBiddingScheme);
    campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // You can optionally provide these field(s).
    campaign.setStartDate(DateTime.now().plusDays(1).toString("yyyyMMdd"));
    campaign.setEndDate(DateTime.now().plusDays(30).toString("yyyyMMdd"));
    campaign.setFrequencyCap(new FrequencyCap(5L, TimeUnit.DAY, Level.ADGROUP));
    // Only the budgetId should be sent, all other fields will be ignored by CampaignService.
    Budget budget = new Budget();
    budget.setBudgetId(budgetId);
    campaign.setBudget(budget);
    campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);
    // Set the campaign network options to Search and Search Network.
    NetworkSetting networkSetting = new NetworkSetting();
    networkSetting.setTargetGoogleSearch(true);
    networkSetting.setTargetSearchNetwork(true);
    networkSetting.setTargetContentNetwork(false);
    networkSetting.setTargetPartnerSearchNetwork(false);
    campaign.setNetworkSetting(networkSetting);
    // Set options that are not required.
    GeoTargetTypeSetting geoTarget = new GeoTargetTypeSetting();
    geoTarget.setPositiveGeoTargetType(GeoTargetTypeSettingPositiveGeoTargetType.DONT_CARE);
    campaign.setSettings(new Setting[] { geoTarget });
    // You can create multiple campaigns in a single request.
    Campaign campaign2 = new Campaign();
    campaign2.setName("Interplanetary Cruise banner #" + System.currentTimeMillis());
    campaign2.setStatus(CampaignStatus.PAUSED);
    BiddingStrategyConfiguration biddingStrategyConfiguration2 = new BiddingStrategyConfiguration();
    biddingStrategyConfiguration2.setBiddingStrategyType(BiddingStrategyType.MANUAL_CPC);
    campaign2.setBiddingStrategyConfiguration(biddingStrategyConfiguration2);
    Budget budget2 = new Budget();
    budget2.setBudgetId(budgetId);
    campaign2.setBudget(budget2);
    campaign2.setAdvertisingChannelType(AdvertisingChannelType.DISPLAY);
    // Create operations.
    CampaignOperation operation = new CampaignOperation();
    operation.setOperand(campaign);
    operation.setOperator(Operator.ADD);
    CampaignOperation operation2 = new CampaignOperation();
    operation2.setOperand(campaign2);
    operation2.setOperator(Operator.ADD);
    CampaignOperation[] operations = new CampaignOperation[] { operation, operation2 };
    // Add campaigns.
    CampaignReturnValue result = campaignService.mutate(operations);
    // Display campaigns.
    for (Campaign campaignResult : result.getValue()) {
        System.out.printf("Campaign with name '%s' and ID %d was added.%n", campaignResult.getName(), campaignResult.getId());
    }
}
Also used : BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) BudgetOperation(com.google.api.ads.adwords.axis.v201809.cm.BudgetOperation) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) CampaignReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue) BudgetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.BudgetServiceInterface) GeoTargetTypeSetting(com.google.api.ads.adwords.axis.v201809.cm.GeoTargetTypeSetting) ManualCpcBiddingScheme(com.google.api.ads.adwords.axis.v201809.cm.ManualCpcBiddingScheme) FrequencyCap(com.google.api.ads.adwords.axis.v201809.cm.FrequencyCap) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) NetworkSetting(com.google.api.ads.adwords.axis.v201809.cm.NetworkSetting)

Example 4 with Campaign

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

the class UpdateCampaign method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign 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 campaignId) throws RemoteException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create campaign with updated status.
    Campaign campaign = new Campaign();
    campaign.setId(campaignId);
    campaign.setStatus(CampaignStatus.PAUSED);
    // Create operations.
    CampaignOperation operation = new CampaignOperation();
    operation.setOperand(campaign);
    operation.setOperator(Operator.SET);
    CampaignOperation[] operations = new CampaignOperation[] { operation };
    // Update campaign.
    CampaignReturnValue result = campaignService.mutate(operations);
    // Display campaigns.
    for (Campaign campaignResult : result.getValue()) {
        System.out.printf("Campaign with name '%s', ID %d, and budget delivery method '%s' " + "was updated.%n", campaignResult.getName(), campaignResult.getId(), campaignResult.getBudget().getDeliveryMethod());
    }
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) CampaignReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue)

Example 5 with Campaign

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

the class AxisSerializerTest method testSerialize.

@Test
public void testSerialize() throws SAXException, IOException {
    BatchJobMutateRequest mutate = new BatchJobMutateRequest();
    List<Operation> ops = Lists.newArrayList();
    Campaign campaign = new Campaign();
    campaign.setId(-1L);
    campaign.setName("Test campaign");
    campaign.setAdvertisingChannelType(AdvertisingChannelType.SEARCH);
    ops.add(new CampaignOperation(Operator.ADD, "ADD", campaign));
    AdGroup adGroup = new AdGroup();
    adGroup.setName("Test ad group");
    adGroup.setCampaignId(campaign.getId());
    ops.add(new AdGroupOperation(Operator.ADD, "ADD", adGroup));
    mutate.setOperations(ops.toArray(new Operation[0]));
    AxisSerializer serializer = new AxisSerializer();
    StringWriter writer = new StringWriter();
    SerializationContext context = new SerializationContext(writer);
    context.setSendDecl(true);
    context.setPretty(true);
    serializer.serialize(mutate, context);
    String serializedRequest = writer.toString();
    assertNotNull("Serialized request is null", serializedRequest);
    String expectedSerializedRequest = CharStreams.toString(new InputStreamReader(AxisSerializerTest.class.getResourceAsStream("resources/BatchJobMutate.request.xml"), UTF_8));
    Diff diff = DiffBuilder.compare(expectedSerializedRequest).withTest(serializedRequest).checkForSimilar().build();
    assertFalse("Serialized request does not match expected XML", diff.hasDifferences());
}
Also used : SerializationContext(org.apache.axis.encoding.SerializationContext) BatchJobMutateRequest(com.google.api.ads.adwords.axis.utils.v201809.batchjob.BatchJobMutateRequest) InputStreamReader(java.io.InputStreamReader) Diff(org.xmlunit.diff.Diff) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) Operation(com.google.api.ads.adwords.axis.v201809.cm.Operation) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) StringWriter(java.io.StringWriter) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation) Test(org.junit.Test)

Aggregations

Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)23 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)15 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)15 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)11 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)9 CampaignReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue)9 Test (org.junit.Test)6 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)5 CampaignPage (com.google.api.ads.adwords.axis.v201809.cm.CampaignPage)5 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)4 BatchJobMutateResponse (com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse)4 BiddableAdGroupCriterion (com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion)4 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)3 ManualCpcBiddingScheme (com.google.api.ads.adwords.axis.v201809.cm.ManualCpcBiddingScheme)3 ShoppingSetting (com.google.api.ads.adwords.axis.v201809.cm.ShoppingSetting)3 Campaign (com.google.api.ads.adwords.jaxws.v201809.cm.Campaign)3 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)2 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)2 DynamicSearchAdsSetting (com.google.api.ads.adwords.axis.v201809.cm.DynamicSearchAdsSetting)2 GeoTargetTypeSetting (com.google.api.ads.adwords.axis.v201809.cm.GeoTargetTypeSetting)2