Search in sources :

Example 56 with Ad

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

the class AddUniversalAppCampaign 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 CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
    // Create the campaign.
    Campaign campaign = new Campaign();
    campaign.setName("Interplanetary Cruise App #" + 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);
    // Set the advertising channel and subchannel types for universal app campaigns.
    campaign.setAdvertisingChannelType(AdvertisingChannelType.MULTI_CHANNEL);
    campaign.setAdvertisingChannelSubType(AdvertisingChannelSubType.UNIVERSAL_APP_CAMPAIGN);
    // Set the campaign's bidding strategy. universal app campaigns
    // only support TARGET_CPA bidding strategy.
    BiddingStrategyConfiguration biddingConfig = new BiddingStrategyConfiguration();
    biddingConfig.setBiddingStrategyType(BiddingStrategyType.TARGET_CPA);
    // Set the target CPA to $1 / app install.
    TargetCpaBiddingScheme biddingScheme = new TargetCpaBiddingScheme();
    biddingScheme.setTargetCpa(new Money());
    biddingScheme.getTargetCpa().setMicroAmount(1000000L);
    biddingConfig.setBiddingScheme(biddingScheme);
    campaign.setBiddingStrategyConfiguration(biddingConfig);
    // Set the campaign's budget.
    campaign.setBudget(new Budget());
    campaign.getBudget().setBudgetId(createBudget(adWordsServices, session));
    // 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"));
    // Set the campaign's assets and ad text ideas. These values will be used to
    // generate ads.
    UniversalAppCampaignSetting universalAppSetting = new UniversalAppCampaignSetting();
    universalAppSetting.setAppId("com.labpixies.colordrips");
    universalAppSetting.setAppVendor(MobileApplicationVendor.VENDOR_GOOGLE_MARKET);
    universalAppSetting.setDescription1("A cool puzzle game");
    universalAppSetting.setDescription2("Remove connected blocks");
    universalAppSetting.setDescription3("3 difficulty levels");
    universalAppSetting.setDescription4("4 colorful fun skins");
    // Optional: You can set up to 20 image assets for your campaign.
    // See UploadImage.java for an example on how to upload images.
    // 
    // universalAppSetting.setImageMediaIds(new long[] { INSERT_IMAGE_MEDIA_ID_HERE });
    // Optimize this campaign for getting new users for your app.
    universalAppSetting.setUniversalAppBiddingStrategyGoalType(UniversalAppBiddingStrategyGoalType.OPTIMIZE_FOR_INSTALL_CONVERSION_VOLUME);
    // If you select the OPTIMIZE_FOR_IN_APP_CONVERSION_VOLUME goal type, then also specify
    // your in-app conversion types so AdWords can focus your campaign on people who are
    // most likely to complete the corresponding in-app actions.
    // Conversion type IDs can be retrieved using ConversionTrackerService.get.
    // 
    // campaign.selectiveOptimization = new SelectiveOptimization();
    // campaign.selectiveOptimization.conversionTypeIds =
    // new long[] { INSERT_CONVERSION_TYPE_ID_1_HERE, INSERT_CONVERSION_TYPE_ID_2_HERE };
    // Optional: Set the campaign settings for Advanced location options.
    GeoTargetTypeSetting geoSetting = new GeoTargetTypeSetting();
    geoSetting.setPositiveGeoTargetType(GeoTargetTypeSettingPositiveGeoTargetType.LOCATION_OF_PRESENCE);
    geoSetting.setNegativeGeoTargetType(GeoTargetTypeSettingNegativeGeoTargetType.DONT_CARE);
    campaign.setSettings(new Setting[] { universalAppSetting, geoSetting });
    // Create the operation.
    CampaignOperation operation = new CampaignOperation();
    operation.setOperand(campaign);
    operation.setOperator(Operator.ADD);
    CampaignOperation[] operations = new CampaignOperation[] { operation };
    // Add the campaign.
    CampaignReturnValue result = campaignService.mutate(operations);
    // Display the results.
    for (Campaign newCampaign : result.getValue()) {
        System.out.printf("Universal app campaign with name '%s' and ID %d was added.%n", newCampaign.getName(), newCampaign.getId());
        // Optional: Set the campaign's location and language targeting. No other targeting
        // criteria can be used for universal app campaigns.
        setCampaignTargetingCriteria(newCampaign, adWordsServices, session);
    }
}
Also used : 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) UniversalAppCampaignSetting(com.google.api.ads.adwords.axis.v201809.cm.UniversalAppCampaignSetting) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) CampaignReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget) TargetCpaBiddingScheme(com.google.api.ads.adwords.axis.v201809.cm.TargetCpaBiddingScheme) GeoTargetTypeSetting(com.google.api.ads.adwords.axis.v201809.cm.GeoTargetTypeSetting)

Example 57 with Ad

use of com.google.api.ads.adwords.axis.v201809.cm.Ad 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 58 with Ad

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

the class AddShoppingDynamicRemarketingCampaign method createCampaign.

/**
 * Creates a Shopping dynamic remarketing campaign object (not including ad group level and
 * below). This creates a Display campaign with the merchant center feed attached. Merchant Center
 * is used for the product information in combination with a user list which contains hits with
 * {@code ecomm_prodid} specified. See <a
 * href="https://developers.google.com/adwords-remarketing-tag/parameters#retail"/>for more
 * detail.
 *
 * @param merchantId the ID of the Merchant Center account.
 * @param budgetId the ID of the budget to use for the campaign.
 * @return the campaign that was created.
 */
private static Campaign createCampaign(AdWordsServicesInterface services, AdWordsSession session, long merchantId, long budgetId) throws RemoteException {
    CampaignServiceInterface campaignService = services.get(session, CampaignServiceInterface.class);
    Campaign campaign = new Campaign();
    campaign.setName("Shopping campaign #" + System.currentTimeMillis());
    // Dynamic remarketing campaigns are only available on the Google Display Network.
    campaign.setAdvertisingChannelType(AdvertisingChannelType.DISPLAY);
    campaign.setStatus(CampaignStatus.PAUSED);
    Budget budget = new Budget();
    budget.setBudgetId(budgetId);
    campaign.setBudget(budget);
    // This example uses a Manual CPC bidding strategy, but you should select the strategy that best
    // aligns with your sales goals. More details here:
    // https://support.google.com/adwords/answer/2472725
    BiddingStrategyConfiguration biddingStrategyConfiguration = new BiddingStrategyConfiguration();
    biddingStrategyConfiguration.setBiddingStrategyType(BiddingStrategyType.MANUAL_CPC);
    campaign.setBiddingStrategyConfiguration(biddingStrategyConfiguration);
    ShoppingSetting setting = new ShoppingSetting();
    // Campaigns with numerically higher priorities take precedence over those with lower
    // priorities.
    setting.setCampaignPriority(0);
    // Set the Merchant Center account ID from which to source products.
    setting.setMerchantId(merchantId);
    // Display Network campaigns do not support partition by country. The only supported value is
    // "ZZ". This signals that products from all countries are available in the campaign. The actual
    // products which serve are based on the products tagged in the user list entry.
    setting.setSalesCountry("ZZ");
    // Optional: Enable local inventory ads (items for sale in physical stores.)
    setting.setEnableLocal(true);
    campaign.setSettings(new Setting[] { setting });
    CampaignOperation op = new CampaignOperation();
    op.setOperand(campaign);
    op.setOperator(Operator.ADD);
    CampaignReturnValue result = campaignService.mutate(new CampaignOperation[] { op });
    return result.getValue(0);
}
Also used : CampaignServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface) Campaign(com.google.api.ads.adwords.axis.v201809.cm.Campaign) ShoppingSetting(com.google.api.ads.adwords.axis.v201809.cm.ShoppingSetting) BiddingStrategyConfiguration(com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration) CampaignOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation) CampaignReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignReturnValue) Budget(com.google.api.ads.adwords.axis.v201809.cm.Budget)

Example 59 with Ad

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

the class GetResponsiveSearchAds method runExample.

/**
 * Runs the example.
 *
 * @param adWordsServices the services factory.
 * @param session the session.
 * @param adGroupId the ID of the ad group to use to find expanded text ads.
 * @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 AdGroupAdService.
    AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
    int offset = 0;
    boolean morePages = true;
    // Create selector to get all of the ads for the ad group.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder.fields(AdGroupAdField.Id, AdGroupAdField.Status, AdGroupAdField.ResponsiveSearchAdHeadlines, AdGroupAdField.ResponsiveSearchAdDescriptions).orderAscBy(AdGroupAdField.Id).offset(offset).limit(PAGE_SIZE).equals(AdGroupAdField.AdGroupId, adGroupId.toString()).in(AdGroupAdField.Status, "ENABLED", "PAUSED").equals("AdType", AdType.RESPONSIVE_SEARCH_AD.getValue()).build();
    int totalEntries = 0;
    while (morePages) {
        // Get all ads.
        AdGroupAdPage page = adGroupAdService.get(selector);
        // Display ads.
        if (page.getEntries() != null && page.getEntries().length > 0) {
            totalEntries = page.getTotalNumEntries();
            for (AdGroupAd adGroupAd : page.getEntries()) {
                ResponsiveSearchAd responsiveSearchAd = (ResponsiveSearchAd) adGroupAd.getAd();
                System.out.printf("Responsive search ad with ID %d, status '%s' was found.%n", adGroupAd.getAd().getId(), adGroupAd.getStatus());
                System.out.println("Headlines:");
                for (AssetLink headline : responsiveSearchAd.getHeadlines()) {
                    ServedAssetFieldType pinning = headline.getPinnedField();
                    System.out.printf("    %s%n", ((TextAsset) headline.getAsset()).getAssetText());
                    if (pinning != null) {
                        System.out.printf("    (pinned to %s)%n", pinning);
                    }
                }
                System.out.println("Descriptions:");
                for (AssetLink description : responsiveSearchAd.getDescriptions()) {
                    ServedAssetFieldType pinning = description.getPinnedField();
                    System.out.printf("    %s%n", ((TextAsset) description.getAsset()).getAssetText());
                    if (pinning != null) {
                        System.out.printf("    (pinned to %s)%n", pinning);
                    }
                }
            }
        }
        offset += PAGE_SIZE;
        selector = builder.increaseOffsetBy(PAGE_SIZE).build();
        morePages = offset < page.getTotalNumEntries();
    }
    System.out.printf("Ad group ID %d has %d responsive search ads.%n", adGroupId, totalEntries);
}
Also used : AdGroupAdPage(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdPage) SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) AdGroupAd(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd) ServedAssetFieldType(com.google.api.ads.adwords.axis.v201809.cm.ServedAssetFieldType) AdGroupAdServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface) ResponsiveSearchAd(com.google.api.ads.adwords.axis.v201809.cm.ResponsiveSearchAd) AssetLink(com.google.api.ads.adwords.axis.v201809.cm.AssetLink) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Example 60 with Ad

use of com.google.api.ads.adwords.axis.v201809.cm.Ad 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)

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