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);
}
}
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());
}
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);
}
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);
}
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);
}
}
Aggregations