Search in sources :

Example 6 with Ad

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

the class AddAdGroupBidModifier method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group where bid modifiers will be added.
 * @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) throws RemoteException {
    // Get the AdGroupBidModifierService.
    AdGroupBidModifierServiceInterface adGroupBidModifierService = adWordsServices.get(session, AdGroupBidModifierServiceInterface.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);
    AdGroupBidModifier adGroupBidModifier = new AdGroupBidModifier();
    adGroupBidModifier.setAdGroupId(adGroupId);
    adGroupBidModifier.setBidModifier(BID_MODIFIER);
    adGroupBidModifier.setCriterion(mobile);
    // Create ADD operation.
    AdGroupBidModifierOperation operation = new AdGroupBidModifierOperation();
    operation.setOperand(adGroupBidModifier);
    // Use 'ADD' to add a new modifier and 'SET' to update an existing one. A
    // modifier can be removed with the 'REMOVE' operator.
    operation.setOperator(Operator.ADD);
    // Update ad group bid modifier.
    AdGroupBidModifierReturnValue result = adGroupBidModifierService.mutate(new AdGroupBidModifierOperation[] { operation });
    for (AdGroupBidModifier bidModifierResult : result.getValue()) {
        System.out.printf("Campaign ID %d, ad group ID %d was updated with ad group level modifier: %.4f%n", bidModifierResult.getCampaignId(), bidModifierResult.getAdGroupId(), bidModifierResult.getBidModifier());
    }
}
Also used : AdGroupBidModifierReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierReturnValue) Platform(com.google.api.ads.adwords.axis.v201809.cm.Platform) AdGroupBidModifier(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifier) AdGroupBidModifierServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierServiceInterface) AdGroupBidModifierOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupBidModifierOperation)

Example 7 with Ad

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

the class AddDynamicSearchAdsCampaign method addWebPageCriteria.

/**
 * Adds a web page criteria to target Dynamic Search Ads.
 */
private static void addWebPageCriteria(AdWordsServicesInterface adWordsServices, AdWordsSession session, AdGroup adGroup) throws ApiException, RemoteException {
    // Get the AdGroupCriterionService.
    AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
    // Create a webpage criterion for special offers.
    WebpageParameter param = new WebpageParameter();
    param.setCriterionName("Special offers");
    WebpageCondition urlCondition = new WebpageCondition();
    urlCondition.setOperand(WebpageConditionOperand.URL);
    urlCondition.setArgument("/specialoffers");
    WebpageCondition titleCondition = new WebpageCondition();
    titleCondition.setOperand(WebpageConditionOperand.PAGE_TITLE);
    titleCondition.setArgument("Special Offer");
    param.setConditions(new WebpageCondition[] { urlCondition, titleCondition });
    Webpage webpage = new Webpage();
    webpage.setParameter(param);
    // Create biddable ad group criterion.
    BiddableAdGroupCriterion biddableAdGroupCriterion = new BiddableAdGroupCriterion();
    biddableAdGroupCriterion.setAdGroupId(adGroup.getId());
    biddableAdGroupCriterion.setCriterion(webpage);
    biddableAdGroupCriterion.setUserStatus(UserStatus.PAUSED);
    // Optional: set a custom bid.
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    CpcBid bid = new CpcBid();
    bid.setBid(new Money());
    bid.getBid().setMicroAmount(10000000L);
    biddingStrategyConfiguration.setBids(new Bids[] { bid });
    biddableAdGroupCriterion.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    // Create operations.
    AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(biddableAdGroupCriterion);
    // Create the criterion.
    AdGroupCriterion newAdGroupCriterion = adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { operation }).getValue(0);
    System.out.printf("Webpage criterion with ID %d was added to ad group ID %d.%n", newAdGroupCriterion.getCriterion().getId(), newAdGroupCriterion.getAdGroupId());
}
Also used : Money(com.google.api.ads.adwords.axis.v201809.cm.Money) AdGroupCriterionOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation) Webpage(com.google.api.ads.adwords.axis.v201809.cm.Webpage) AdGroupCriterionServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) BiddableAdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion) AdGroupCriterion(com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion) CpcBid(com.google.api.ads.adwords.axis.v201809.cm.CpcBid) WebpageParameter(com.google.api.ads.adwords.axis.v201809.cm.WebpageParameter) WebpageCondition(com.google.api.ads.adwords.axis.v201809.cm.WebpageCondition)

Example 8 with Ad

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

the class AddDynamicSearchAdsCampaign method createAdGroup.

/**
 * Creates the ad group.
 */
private static AdGroup createAdGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, Campaign campaign) throws ApiException, RemoteException {
    // Get the AdGroupService.
    AdGroupServiceInterface adGroupService = adWordsServices.get(session, AdGroupServiceInterface.class);
    // Create the ad group.
    AdGroup adGroup = new AdGroup();
    // Required: Set the ad group's type to Dynamic Search Ads.
    adGroup.setAdGroupType(AdGroupType.SEARCH_DYNAMIC_ADS);
    adGroup.setName("Earth to Mars Cruises #" + System.currentTimeMillis());
    adGroup.setCampaignId(campaign.getId());
    adGroup.setStatus(AdGroupStatus.PAUSED);
    // Recommended: Set a tracking URL template for your ad group if you want to use URL
    // tracking software.
    adGroup.setTrackingUrlTemplate("http://tracker.example.com/traveltracker/{escapedlpurl}");
    // Set the ad group bids.
    BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
    CpcBid cpcBid = new CpcBid();
    cpcBid.setBid(new Money());
    cpcBid.getBid().setMicroAmount(3000000L);
    biddingConfig.setBids(new Bids[] { cpcBid });
    adGroup.setBiddingStrategyConfiguration(biddingConfig);
    // Create the operation.
    AdGroupOperation operation = new AdGroupOperation();
    operation.setOperand(adGroup);
    operation.setOperator(Operator.ADD);
    AdGroup newAdGroup = adGroupService.mutate(new AdGroupOperation[] { operation }).getValue(0);
    System.out.printf("Ad group with name '%s' and ID %d was added.%n", newAdGroup.getName(), newAdGroup.getId());
    return newAdGroup;
}
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) 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 9 with Ad

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

the class AddDynamicSearchAdsCampaign method createExpandedDSA.

/**
 * Creates the expanded Dynamic Search Ad.
 */
private static void createExpandedDSA(AdWordsServicesInterface adWordsServices, AdWordsSession session, AdGroup adGroup) throws ApiException, RemoteException {
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    // Create the expanded Dynamic Search Ad. This ad will have its headline and final URL
    // auto-generated at serving time according to domain name specific information provided
    // by DynamicSearchAdsSetting at the campaign level.
    ExpandedDynamicSearchAd expandedDSA = new ExpandedDynamicSearchAd();
    // Set the ad description.
    expandedDSA.setDescription("Buy your tickets now!");
    expandedDSA.setDescription2("Discount ends soon");
    // Create the ad group ad.
    AdGroupAd adGroupAd = new AdGroupAd();
    adGroupAd.setAdGroupId(adGroup.getId());
    adGroupAd.setAd(expandedDSA);
    // Optional: Set the status.
    adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
    // Create the operation.
    AdGroupAdOperation operation = new AdGroupAdOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(adGroupAd);
    // Create the ad.
    AdGroupAd newAdGroupAd = adGroupAdService.mutate(new AdGroupAdOperation[] { operation }).getValue(0);
    ExpandedDynamicSearchAd newExpandedDSA = (ExpandedDynamicSearchAd) newAdGroupAd.getAd();
    System.out.printf("Expanded Dynamic Search Ad with ID %d and description '%s' and description 2 '%s' was " + "added.%n", newExpandedDSA.getId(), newExpandedDSA.getDescription(), newExpandedDSA.getDescription2());
}
Also used : AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) ExpandedDynamicSearchAd(com.google.api.ads.adwords.axis.v201809.cm.ExpandedDynamicSearchAd)

Example 10 with Ad

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

the class AddGmailAd method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group where the ad 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.
 * @throws IOException if unable to get media data from the URL.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws IOException {
    // This ad format does not allow the creation of an image using the
    // Image.data field. An image must first be created using the MediaService,
    // and Image.mediaId must be populated when creating the ad.
    long logoImageId = uploadImage(adWordsServices, session, "https://goo.gl/mtt54n");
    Image logoImage = new Image();
    logoImage.setMediaId(logoImageId);
    long marketingImageId = uploadImage(adWordsServices, session, "http://goo.gl/3b9Wfh");
    Image adImage = new Image();
    adImage.setMediaId(marketingImageId);
    GmailTeaser teaser = new GmailTeaser();
    teaser.setHeadline("Dream");
    teaser.setDescription("Create your own adventure");
    teaser.setBusinessName("Interplanetary Ships");
    teaser.setLogoImage(logoImage);
    // Create the Gmail ad.
    GmailAd gmailAd = new GmailAd();
    gmailAd.setTeaser(teaser);
    gmailAd.setMarketingImage(adImage);
    gmailAd.setMarketingImageHeadline("Travel");
    gmailAd.setMarketingImageDescription("Take to the skies!");
    gmailAd.setFinalUrls(new String[] { "http://www.example.com" });
    // Create ad group ad for the Gmail ad.
    AdGroupAd adGroupAd = new AdGroupAd();
    adGroupAd.setAdGroupId(adGroupId);
    adGroupAd.setAd(gmailAd);
    // Additional properties (non-required).
    adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
    // Create operation.
    AdGroupAdOperation operation = new AdGroupAdOperation();
    operation.setOperator(Operator.ADD);
    operation.setOperand(adGroupAd);
    // Get the AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    // Add Gmail ad.
    AdGroupAdReturnValue returnValue = adGroupAdService.mutate(new AdGroupAdOperation[] { operation });
    if (returnValue.getValue() != null) {
        for (AdGroupAd newAdGroupAd : returnValue.getValue()) {
            System.out.printf("New Gmail ad with ID %d and headline '%s' was added.%n", newAdGroupAd.getAd().getId(), ((GmailAd) newAdGroupAd.getAd()).getTeaser().getHeadline());
        }
    } else {
        System.out.println("No Gmail ads were added.");
    }
}
Also used : GmailAd(com.google.api.ads.adwords.axis.v201809.cm.GmailAd) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) AdGroupAdReturnValue(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) AdGroupAdOperation(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation) Image(com.google.api.ads.adwords.axis.v201809.cm.Image) GmailTeaser(com.google.api.ads.adwords.axis.v201809.cm.GmailTeaser)

Aggregations

AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)20 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)19 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)16 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)16 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)15 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)15 ArrayList (java.util.ArrayList)14 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)13 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)12 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)12 AdGroupCriterionServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionServiceInterface)12 SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)10 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)10 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)10 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)10 AdGroupServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupServiceInterface)9 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)9 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)9 ApiError (com.google.api.ads.adwords.axis.v201809.cm.ApiError)7 AdWordsSession (com.google.api.ads.adwords.lib.client.AdWordsSession)7