Search in sources :

Example 16 with AdGroup

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

the class AddShoppingDynamicRemarketingCampaign method runExample.

/**
 * Runs the example.
 *
 * @param services the services factory.
 * @param session the session.
 * @param merchantId the ID of the merchant center account from which to source product feed data.
 * @param budgetId the ID of a shared budget to associate with the campaign.
 * @param userListId the ID of a user list to target.
 * @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 IOException if the ad images failed to load.
 */
private static void runExample(AdWordsServicesInterface services, AdWordsSession session, long merchantId, long budgetId, long userListId) throws IOException {
    Campaign campaign = createCampaign(services, session, merchantId, budgetId);
    System.out.printf("Campaign with name '%s' and ID %d was added.%n", campaign.getName(), campaign.getId());
    AdGroup adGroup = createAdGroup(services, session, campaign);
    System.out.printf("Ad group with name '%s' and ID %d was added.%n", adGroup.getName(), adGroup.getId());
    AdGroupAd adGroupAd = createAd(services, session, adGroup);
    System.out.printf("Responsive display ad with ID %d was added.%n", adGroupAd.getAd().getId());
    attachUserList(services, session, adGroup, userListId);
    System.out.printf("User list with ID %d was attached to ad group with ID %d.%n", userListId, adGroup.getId());
}
Also used : Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup)

Example 17 with AdGroup

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

the class UpdateAdGroup method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group to update.
 * @param bidMicroAmount the optional bid amount in micros to use for the ad group bid.
 * @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, @Nullable Long bidMicroAmount) throws RemoteException {
    // Get the AdGroupService.
    AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
    // Create an ad group with the specified ID.
    AdGroup adGroup = new AdGroup();
    adGroup.setId(adGroupId);
    // Update the CPC bid if specified.
    if (bidMicroAmount != null) {
        BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
        Money cpcBidMoney = new Money();
        cpcBidMoney.setMicroAmount(bidMicroAmount);
        CpcBid cpcBid = new CpcBid();
        cpcBid.setBid(cpcBidMoney);
        biddingStrategyConfiguration.setBids(new Bids[] { cpcBid });
        adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    }
    // Pause the ad group.
    adGroup.setStatus(AdGroupStatus.PAUSED);
    // Create operations.
    AdGroupOperation operation = new AdGroupOperation();
    operation.setOperand(adGroup);
    operation.setOperator(Operator.SET);
    AdGroupOperation[] operations = new AdGroupOperation[] { operation };
    // Update ad group.
    AdGroupReturnValue result = adGroupService.mutate(operations);
    // Display ad groups.
    for (AdGroup adGroupResult : result.getValue()) {
        BiddingStrategyConfiguration biddingStrategyConfiguration = adGroupResult.getBiddingStrategyConfiguration();
        // Find the CpcBid in the bidding strategy configuration's bids collection.
        Long cpcBidMicros = null;
        if (biddingStrategyConfiguration != null) {
            if (biddingStrategyConfiguration.getBids() != null) {
                for (Bids bid : biddingStrategyConfiguration.getBids()) {
                    if (bid instanceof CpcBid) {
                        cpcBidMicros = ((CpcBid) bid).getBid().getMicroAmount();
                        break;
                    }
                }
            }
        }
        System.out.printf("Ad group with ID %d and name '%s' updated to have status '%s' and CPC bid %d%n", adGroupResult.getId(), adGroupResult.getName(), adGroupResult.getStatus(), cpcBidMicros);
    }
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) Bids(com.google.api.ads.adwords.axis.v201809.cm.Bids) AdGroupReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Example 18 with AdGroup

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

the class AddCompleteCampaignsUsingBatchJob method buildAdGroupOperations.

private static List<AdGroupOperation> buildAdGroupOperations(Iterator<Long> tempIdGenerator, String namePrefix, Iterable<CampaignOperation> campaignOperations) {
    List<AdGroupOperation> operations = new ArrayList<>();
    for (CampaignOperation campaignOperation : campaignOperations) {
        for (int i = 0; i < NUMBER_OF_ADGROUPS_TO_ADD; i++) {
            AdGroup adGroup = new AdGroup();
            adGroup.setCampaignId(campaignOperation.getOperand().getId());
            adGroup.setId(tempIdGenerator.next());
            adGroup.setName(String.format("Batch Ad Group %s.%s", namePrefix, i));
            BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
            CpcBid bid = new CpcBid();
            bid.setBid(new Money(null, 10000000L));
            biddingStrategyConfiguration.setBids(new Bids[] { bid });
            adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
            AdGroupOperation operation = new AdGroupOperation();
            operation.setOperand(adGroup);
            operation.setOperator(Operator.ADD);
            operations.add(operation);
        }
    }
    return operations;
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) ArrayList(java.util.ArrayList) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Example 19 with AdGroup

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

the class AddAdGroups method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param campaignId the ID of the campaign where the ad groups 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.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, long campaignId) throws RemoteException {
    // Get the AdGroupService.
    AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
    // Create ad group.
    AdGroup adGroup = new AdGroup();
    adGroup.setName("Earth to Mars Cruises #" + System.currentTimeMillis());
    adGroup.setStatus(AdGroupStatus.ENABLED);
    adGroup.setCampaignId(campaignId);
    // Optional settings.
    // Targeting restriction settings. Depending on the criterionTypeGroup
    // value, most TargetingSettingDetail only affect Display campaigns.
    // However, the USER_INTEREST_AND_LIST value works for RLSA campaigns -
    // Search campaigns targeting using a remarketing list.
    TargetingSetting targeting = new TargetingSetting();
    // Restricting to serve ads that match your ad group placements.
    // This is equivalent to choosing "Target and bid" in the UI.
    TargetingSettingDetail placements = new TargetingSettingDetail();
    placements.setCriterionTypeGroup(CriterionTypeGroup.PLACEMENT);
    placements.setTargetAll(Boolean.FALSE);
    // Using your ad group verticals only for bidding. This is equivalent
    // to choosing "Bid only" in the UI.
    TargetingSettingDetail verticals = new TargetingSettingDetail();
    verticals.setCriterionTypeGroup(CriterionTypeGroup.VERTICAL);
    verticals.setTargetAll(Boolean.TRUE);
    targeting.setDetails(new TargetingSettingDetail[] { placements, verticals });
    adGroup.setSettings(new Setting[] { targeting });
    // Set the rotation mode.
    AdGroupAdRotationMode rotationMode = new AdGroupAdRotationMode(AdRotationMode.OPTIMIZE);
    adGroup.setAdGroupAdRotationMode(rotationMode);
    // Create ad group bid.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    Money cpcBidMoney = new Money();
    cpcBidMoney.setMicroAmount(10_000_000L);
    CpcBid bid = new CpcBid();
    bid.setBid(cpcBidMoney);
    biddingStrategyConfiguration.setBids(new Bids[] { bid });
    adGroup.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // Add as many additional ad groups as you need.
    AdGroup adGroup2 = new AdGroup();
    adGroup2.setName("Earth to Venus Cruises #" + System.currentTimeMillis());
    adGroup2.setStatus(AdGroupStatus.ENABLED);
    adGroup2.setCampaignId(campaignId);
    BiddingStrategyConfiguration biddingStrategyConfiguration2 = new BiddingStrategyConfiguration();
    Money cpcBidMoney2 = new Money();
    cpcBidMoney2.setMicroAmount(10_000_000L);
    CpcBid bid2 = new CpcBid();
    bid2.setBid(cpcBidMoney2);
    biddingStrategyConfiguration2.setBids(new Bids[] { bid2 });
    adGroup2.setBiddingStrategyConfiguration(biddingStrategyConfiguration2);
    // Create operations.
    AdGroupOperation operation = new AdGroupOperation();
    operation.setOperand(adGroup);
    operation.setOperator(Operator.ADD);
    AdGroupOperation operation2 = new AdGroupOperation();
    operation2.setOperand(adGroup2);
    operation2.setOperator(Operator.ADD);
    AdGroupOperation[] operations = new AdGroupOperation[] { operation, operation2 };
    // Add ad groups.
    AdGroupReturnValue result = adGroupService.mutate(operations);
    // Display new ad groups.
    for (AdGroup adGroupResult : result.getValue()) {
        System.out.printf("Ad group with name '%s' and ID %d was added.%n", adGroupResult.getName(), adGroupResult.getId());
    }
}
Also used : TargetingSettingDetail(com.google.api.ads.adwords.axis.v201809.cm.TargetingSettingDetail) Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface) TargetingSetting(com.google.api.ads.adwords.axis.v201809.cm.TargetingSetting) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) AdGroupReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue) AdGroup(com.google.api.ads.adwords.axis.v201809.cm.AdGroup) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) AdGroupAdRotationMode(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdRotationMode) AdGroupOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)

Aggregations

AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)14 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)9 AdGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface)9 AdGroupReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupReturnValue)6 Test (org.junit.Test)6 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)5 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)5 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)4 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)4 BatchJobMutateResponse (com.google.api.ads.adwords.jaxws.utils.v201809.batchjob.BatchJobMutateResponse)4 BiddableAdGroupCriterion (com.google.api.ads.adwords.jaxws.v201809.cm.BiddableAdGroupCriterion)4 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)3 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)3 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)2 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)2 AdGroupPage (com.google.api.ads.adwords.axis.v201809.cm.AdGroupPage)2 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)2 CriterionError (com.google.api.ads.adwords.jaxws.v201809.cm.CriterionError)2 InputStreamReader (java.io.InputStreamReader)2 Source (javax.xml.transform.Source)2