Search in sources :

Example 1 with CampaignGroup

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

the class AddCampaignGroupsAndPerformanceTargets method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignIds the IDs of the campaigns to add to the campaign group.
 * @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, List<Long> campaignIds) throws RemoteException {
    CampaignGroup campaignGroup = createCampaignGroup(adWordsServices, session);
    addCampaignsToGroup(adWordsServices, session, campaignGroup, campaignIds);
    createPerformanceTarget(adWordsServices, session, campaignGroup);
}
Also used : CampaignGroup(com.google.api.ads.adwords.axis.v201809.cm.CampaignGroup)

Example 2 with CampaignGroup

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

the class AddCampaignGroupsAndPerformanceTargets method createPerformanceTarget.

/**
 * Creates a performance target for the campaign group.
 */
private static void createPerformanceTarget(AdWordsServicesInterface adWordsServices, AdWordsSession session, CampaignGroup campaignGroup) throws ApiException, RemoteException {
    // Get the CampaignGroupPerformanceTargetService.
    CampaignGroupPerformanceTargetServiceInterface campaignGroupPerformanceTargetService = adWordsServices.get(session, CampaignGroupPerformanceTargetServiceInterface.class);
    // Create the performance target.
    CampaignGroupPerformanceTarget campaignGroupPerformanceTarget = new CampaignGroupPerformanceTarget();
    campaignGroupPerformanceTarget.setCampaignGroupId(campaignGroup.getId());
    PerformanceTarget performanceTarget = new PerformanceTarget();
    // Keep the CPC for the campaigns < $3.
    performanceTarget.setEfficiencyTargetType(EfficiencyTargetType.CPC_LESS_THAN_OR_EQUAL_TO);
    performanceTarget.setEfficiencyTargetValue(3000000d);
    // Keep the maximum spend under $50.
    performanceTarget.setSpendTargetType(SpendTargetType.MAXIMUM);
    Money maxSpend = new Money();
    maxSpend.setMicroAmount(500000000L);
    performanceTarget.setSpendTarget(maxSpend);
    // Aim for at least 3000 clicks.
    performanceTarget.setVolumeTargetValue(3000L);
    performanceTarget.setVolumeGoalType(VolumeGoalType.MAXIMIZE_CLICKS);
    // Start the performance target today, and run it for the next 90 days.
    DateTime startDate = DateTime.now();
    DateTime endDate = DateTime.now().plusDays(90);
    performanceTarget.setStartDate(startDate.toString("yyyyMMdd"));
    performanceTarget.setEndDate(endDate.toString("yyyyMMdd"));
    campaignGroupPerformanceTarget.setPerformanceTarget(performanceTarget);
    // Create the operation.
    CampaignGroupPerformanceTargetOperation operation = new CampaignGroupPerformanceTargetOperation();
    operation.setOperand(campaignGroupPerformanceTarget);
    operation.setOperator(Operator.ADD);
    CampaignGroupPerformanceTarget newCampaignGroupPerformanceTarget = campaignGroupPerformanceTargetService.mutate(new CampaignGroupPerformanceTargetOperation[] { operation }).getValue(0);
    // Display the results.
    System.out.printf("Campaign group performance target with ID %d was added for campaign group ID %d.%n", newCampaignGroupPerformanceTarget.getId(), newCampaignGroupPerformanceTarget.getCampaignGroupId());
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) CampaignGroupPerformanceTargetOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupPerformanceTargetOperation) CampaignGroupPerformanceTarget(com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupPerformanceTarget) CampaignGroupPerformanceTargetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupPerformanceTargetServiceInterface) PerformanceTarget(com.google.api.ads.adwords.axis.v201809.cm.PerformanceTarget) CampaignGroupPerformanceTarget(com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupPerformanceTarget) DateTime(org.joda.time.DateTime)

Example 3 with CampaignGroup

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

the class AddCampaignGroupsAndPerformanceTargets method addCampaignsToGroup.

/**
 * Adds multiple campaigns to a campaign group.
 */
private static void addCampaignsToGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, CampaignGroup campaignGroup, List<Long> campaignIds) throws ApiException, RemoteException {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    List<CampaignOperation> operations = new ArrayList<>();
    for (Long campaignId : campaignIds) {
        Campaign campaign = new Campaign();
        campaign.setId(campaignId);
        campaign.setCampaignGroupId(campaignGroup.getId());
        CampaignOperation operation = new CampaignOperation();
        operation.setOperand(campaign);
        operation.setOperator(Operator.SET);
        operations.add(operation);
    }
    CampaignReturnValue returnValue = campaignService.mutate(operations.toArray(new CampaignOperation[operations.size()]));
    System.out.printf("The following campaign IDs were added to the campaign group with ID %d:%n", campaignGroup.getId());
    for (Campaign campaign : returnValue.getValue()) {
        System.out.printf("\t%d%n", campaign.getId());
    }
}
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) ArrayList(java.util.ArrayList)

Example 4 with CampaignGroup

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

the class AddCampaignGroupsAndPerformanceTargets method createCampaignGroup.

/**
 * Creates a campaign group.
 */
private static CampaignGroup createCampaignGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the CampaignGroupService.
    CampaignGroupServiceInterface campaignGroupService = adWordsServices.get(session, CampaignGroupServiceInterface.class);
    // Create the campaign group.
    CampaignGroup campaignGroup = new CampaignGroup();
    campaignGroup.setName("Mars campaign group #" + System.currentTimeMillis());
    // Create the operation.
    CampaignGroupOperation operation = new CampaignGroupOperation();
    operation.setOperand(campaignGroup);
    operation.setOperator(Operator.ADD);
    CampaignGroup newCampaignGroup = campaignGroupService.mutate(new CampaignGroupOperation[] { operation }).getValue(0);
    System.out.printf("Campaign group with ID %d and name '%s' was created.%n", newCampaignGroup.getId(), newCampaignGroup.getName());
    return newCampaignGroup;
}
Also used : CampaignGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupOperation) CampaignGroup(com.google.api.ads.adwords.axis.v201809.cm.CampaignGroup) CampaignGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupServiceInterface)

Aggregations

CampaignGroup (com.google.api.ads.adwords.axis.v201809.cm.CampaignGroup)2 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)1 CampaignGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupOperation)1 CampaignGroupPerformanceTarget (com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupPerformanceTarget)1 CampaignGroupPerformanceTargetOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupPerformanceTargetOperation)1 CampaignGroupPerformanceTargetServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupPerformanceTargetServiceInterface)1 CampaignGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignGroupServiceInterface)1 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)1 CampaignReturnValue (com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue)1 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)1 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)1 PerformanceTarget (com.google.api.ads.adwords.axis.v201809.cm.PerformanceTarget)1 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1