use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class AddMultiAssetResponsiveDisplayAd 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 retrieve an image from a URL.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws IOException {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
List<AdGroupAdOperation> operations = new ArrayList<>();
MultiAssetResponsiveDisplayAd ad = new MultiAssetResponsiveDisplayAd();
List<AssetLink> headlines = new ArrayList<>();
headlines.add(createAssetLinkForText("Travel to Mars"));
headlines.add(createAssetLinkForText("Travel to Jupiter"));
headlines.add(createAssetLinkForText("Travel to Pluto"));
headlines.add(createAssetLinkForText("Experience the Stars"));
ad.setHeadlines(headlines.toArray(new AssetLink[0]));
List<AssetLink> descriptions = new ArrayList<>();
descriptions.add(createAssetLinkForText("Visit the planet in a luxury spaceship."));
descriptions.add(createAssetLinkForText("See the planet in style."));
ad.setDescriptions(descriptions.toArray(new AssetLink[0]));
ad.setBusinessName("Galactic Luxury Cruises");
ad.setLongHeadline(createAssetLinkForText("Visit the planet in a luxury spaceship."));
// This ad format does not allow the creation of an image asset by setting the asset.imageData
// field. An image asset must first be created using the AssetService, and asset.assetId must be
// populated when creating the ad.
ad.setMarketingImages(new AssetLink[] { createAssetLinkForImageAsset(uploadImageAsset(adWordsServices, session, "https://goo.gl/3b9Wfh")) });
ad.setSquareMarketingImages(new AssetLink[] { createAssetLinkForImageAsset(uploadImageAsset(adWordsServices, session, "https://goo.gl/mtt54n")) });
ad.setFinalUrls(new String[] { "http://www.example.com" });
// Optional: set call to action text.
ad.setCallToActionText("Shop Now");
// Set color settings using hexadecimal values. Set allowFlexibleColor to false if you want
// your ads to render by always using your colors strictly.
ad.setMainColor("#0000ff");
ad.setAccentColor("#ffff00");
ad.setAllowFlexibleColor(false);
// Set the format setting that the ad will be served in.
ad.setFormatSetting(DisplayAdFormatSetting.NON_NATIVE);
// Optional: Set dynamic display ad settings, composed of landscape logo image, promotion text,
// and price prefix.
ad.setDynamicSettingsPricePrefix("as low as");
ad.setDynamicSettingsPromoText("Free shipping!");
ad.setLogoImages(new AssetLink[] { createAssetLinkForImageAsset(uploadImageAsset(adWordsServices, session, "https://goo.gl/mtt54n")) });
// Create ad group ad.
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAdGroupId(adGroupId);
adGroupAd.setAd(ad);
// Optional: set the status.
adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
// Create the operation.
AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
adGroupAdOperation.setOperand(adGroupAd);
adGroupAdOperation.setOperator(Operator.ADD);
operations.add(adGroupAdOperation);
// Add ad.
AdGroupAdReturnValue result = adGroupAdService.mutate(operations.toArray(new AdGroupAdOperation[operations.size()]));
Arrays.stream(result.getValue()).map(adGroupAdResult -> (MultiAssetResponsiveDisplayAd) adGroupAdResult.getAd()).forEach(newAd -> System.out.printf("New responsive display ad with ID %d and long headline '%s' was added.%n", newAd.getId(), ((TextAsset) newAd.getLongHeadline().getAsset()).getAssetText()));
}
use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class AddShoppingDynamicRemarketingCampaign method attachUserList.
/**
* Attach a user list to an ad group. The user list provides positive targeting and feed
* information to drive the dynamic content of the ad.
*
* <p>Note: User lists must be attached at the ad group level for positive targeting in Shopping
* dynamic remarketing campaigns.
*
* @param adGroup the ad group which will have the user list attached.
* @param userListId the user list to use for targeting and dynamic content.
*/
private static void attachUserList(AdWordsServicesInterface services, AdWordsSession session, AdGroup adGroup, long userListId) throws RemoteException {
AdGroupCriterionServiceInterface adGroupCriterionService = services.get(session, AdGroupCriterionServiceInterface.class);
CriterionUserList userList = new CriterionUserList();
userList.setUserListId(userListId);
BiddableAdGroupCriterion adGroupCriterion = new BiddableAdGroupCriterion();
adGroupCriterion.setCriterion(userList);
adGroupCriterion.setAdGroupId(adGroup.getId());
AdGroupCriterionOperation op = new AdGroupCriterionOperation();
op.setOperand(adGroupCriterion);
op.setOperator(Operator.ADD);
adGroupCriterionService.mutate(new AdGroupCriterionOperation[] { op });
}
use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class AddShoppingDynamicRemarketingCampaign method createAd.
/**
* Creates an ad for serving dynamic content in a remarketing campaign.
*
* @param adGroup the ad group under which to create the ad.
* @return the ad that was created.
* @throws IOException if an image was not able to be loaded.
*/
private static AdGroupAd createAd(AdWordsServicesInterface services, AdWordsSession session, AdGroup adGroup) throws IOException {
AdGroupAdServiceInterface adService = services.get(session, AdGroupAdServiceInterface.class);
ResponsiveDisplayAd ad = new ResponsiveDisplayAd();
// 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.
ad.setMarketingImage(uploadImage(services, session, "https://goo.gl/3b9Wfh"));
ad.setShortHeadline("Travel");
ad.setLongHeadline("Travel the World");
ad.setDescription("Take to the air!");
ad.setBusinessName("Interplanetary Cruises");
ad.setFinalUrls(new String[] { "http://www.example.com/" });
// Optional: Call to action text.
// Valid texts: https://support.google.com/adwords/answer/7005917
ad.setCallToActionText("Apply Now");
// Optional: Set dynamic display ad settings, composed of landscape logo
// image, promotion text, and price prefix.
DynamicSettings dynamicDisplayAdSettings = createDynamicDisplayAdSettings(services, session);
ad.setDynamicDisplayAdSettings(dynamicDisplayAdSettings);
Image optionalImage = uploadImage(services, session, "https://goo.gl/mtt54n");
// Optional: Create a logo image and set it to the ad.
ad.setLogoImage(optionalImage);
// Optional: Create a square marketing image and set it to the ad.
ad.setSquareMarketingImage(optionalImage);
// Whitelisted accounts only: Set color settings using hexadecimal values.
// Set allowFlexibleColor to false if you want your ads to render by always
// using your colors strictly.
/*
ad.setMainColor("#0000ff");
ad.setAccentColor("#ffff00");
ad.setAllowFlexibleColor(false);
*/
// Whitelisted accounts only: Set the format setting that the ad will be
// served in.
/*
ad.setFormatSetting(
com.google.api.ads.adwords.axis.v201809.cm.DisplayAdFormatSetting.NON_NATIVE);
*/
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAd(ad);
adGroupAd.setAdGroupId(adGroup.getId());
AdGroupAdOperation op = new AdGroupAdOperation();
op.setOperand(adGroupAd);
op.setOperator(Operator.ADD);
AdGroupAdReturnValue result = adService.mutate(new AdGroupAdOperation[] { 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 GetAdGroupBidModifier 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 AdGroupBidModifierService.
AdGroupBidModifierServiceInterface adGroupBidModifierService = adWordsServices.get(session, AdGroupBidModifierServiceInterface.class);
// Create selector.
Selector selector = new SelectorBuilder().fields(AdGroupBidModifierField.CampaignId, AdGroupBidModifierField.AdGroupId, AdGroupBidModifierField.BidModifier, AdGroupBidModifierField.Id).offset(0).limit(PAGE_SIZE).build();
AdGroupBidModifierPage page = adGroupBidModifierService.get(selector);
if (page.getEntries() != null) {
for (AdGroupBidModifier bidModifierResult : page.getEntries()) {
String bidModifierValue = bidModifierResult.getBidModifier() != null ? bidModifierResult.getBidModifier().toString() : "unset";
System.out.printf("Campaign ID %d, AdGroup ID %d, Criterion ID %d, " + "has ad group level modifier: %s%n", bidModifierResult.getCampaignId(), bidModifierResult.getAdGroupId(), bidModifierResult.getCriterion().getId(), bidModifierValue);
}
} else {
System.out.println("No ad group level bid modifiers were found.");
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class AddExpandedTextAds 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.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws RemoteException {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
List<AdGroupAdOperation> operations = new ArrayList<>();
for (int i = 0; i < NUMBER_OF_ADS; i++) {
// Create expanded text ad.
ExpandedTextAd expandedTextAd = new ExpandedTextAd();
expandedTextAd.setHeadlinePart1(String.format("Cruise #%d to Mars", i));
expandedTextAd.setHeadlinePart2("Best Space Cruise Line");
expandedTextAd.setHeadlinePart3("For Your Loved Ones");
expandedTextAd.setDescription("Buy your tickets now!");
expandedTextAd.setDescription2("Discount ends soon");
expandedTextAd.setFinalUrls(new String[] { "http://www.example.com/" + i });
// Create ad group ad.
AdGroupAd expandedTextAdGroupAd = new AdGroupAd();
expandedTextAdGroupAd.setAdGroupId(adGroupId);
expandedTextAdGroupAd.setAd(expandedTextAd);
// Optional: set the status.
expandedTextAdGroupAd.setStatus(AdGroupAdStatus.PAUSED);
// Create the operation.
AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
adGroupAdOperation.setOperand(expandedTextAdGroupAd);
adGroupAdOperation.setOperator(Operator.ADD);
operations.add(adGroupAdOperation);
}
// Add ads.
AdGroupAdReturnValue result = adGroupAdService.mutate(operations.toArray(new AdGroupAdOperation[operations.size()]));
// Display ads.
Arrays.stream(result.getValue()).map(adGroupAdResult -> (ExpandedTextAd) adGroupAdResult.getAd()).forEach(newAd -> System.out.printf("Expanded text ad with ID %d and headline '%s | %s%s' was added.%n", newAd.getId(), newAd.getHeadlinePart1(), newAd.getHeadlinePart2(), newAd.getHeadlinePart3() == null ? "" : String.format(" | %s", newAd.getHeadlinePart3())));
}
Aggregations