use of com.google.api.ads.adwords.axis.v201809.cm.DynamicSettings 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.DynamicSettings in project googleads-java-lib by googleads.
the class AddResponsiveDisplayAd method createDynamicDisplayAdSettings.
private static DynamicSettings createDynamicDisplayAdSettings(MediaServiceInterface mediaService) throws IOException {
long logoImageMediaId = uploadImage(mediaService, "https://goo.gl/dEvQeF");
Image logo = new Image();
logo.setMediaId(logoImageMediaId);
DynamicSettings dynamicSettings = new DynamicSettings();
dynamicSettings.setLandscapeLogoImage(logo);
dynamicSettings.setPricePrefix("as low as");
dynamicSettings.setPromoText("Free shipping!");
return dynamicSettings;
}
use of com.google.api.ads.adwords.axis.v201809.cm.DynamicSettings in project googleads-java-lib by googleads.
the class AddResponsiveDisplayAd 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 uploading an image failed.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session, long adGroupId) throws IOException {
// Get the MediaService.
MediaServiceInterface mediaService = adWordsServices.get(session, MediaServiceInterface.class);
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
// Create a responsive display ad.
ResponsiveDisplayAd responsiveDisplayAd = 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.
long marketingImageMediaId = uploadImage(mediaService, "https://goo.gl/3b9Wfh");
Image marketingImage = new Image();
marketingImage.setMediaId(marketingImageMediaId);
responsiveDisplayAd.setMarketingImage(marketingImage);
responsiveDisplayAd.setShortHeadline("Travel");
responsiveDisplayAd.setLongHeadline("Travel the World");
responsiveDisplayAd.setDescription("Take to the air!");
responsiveDisplayAd.setBusinessName("Interplanetary Cruises");
responsiveDisplayAd.setFinalUrls(new String[] { "http://www.example.com/" });
// Optional: Create a square marketing image using MediaService, and set it
// to the ad.
long squareMarketingImageMediaId = uploadImage(mediaService, "https://goo.gl/mtt54n");
Image squareMarketingImage = new Image();
squareMarketingImage.setMediaId(squareMarketingImageMediaId);
responsiveDisplayAd.setSquareMarketingImage(squareMarketingImage);
// Optional: set call to action text.
responsiveDisplayAd.setCallToActionText("Shop Now");
// Optional: Set dynamic display ad settings, composed of landscape logo
// image, promotion text, and price prefix.
DynamicSettings dynamicDisplayAdSettings = createDynamicDisplayAdSettings(mediaService);
responsiveDisplayAd.setDynamicDisplayAdSettings(dynamicDisplayAdSettings);
// 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.
/*
responsiveDisplayAd.setMainColor("#0000ff");
responsiveDisplayAd.setAccentColor("#ffff00");
responsiveDisplayAd.setAllowFlexibleColor(false);
*/
// Whitelisted accounts only: Set the format setting that the ad will be
// served in.
/*
responsiveDisplayAd.setFormatSetting(
com.google.api.ads.adwords.axis.v201809.cm.DisplayAdFormatSetting.NON_NATIVE);
*/
// Create ad group ad for the responsive display ad.
AdGroupAd adGroupAd = new AdGroupAd();
adGroupAd.setAdGroupId(adGroupId);
adGroupAd.setAd(responsiveDisplayAd);
// Optional: set the status.
adGroupAd.setStatus(AdGroupAdStatus.PAUSED);
// Create the operation.
AdGroupAdOperation adGroupAdOperation = new AdGroupAdOperation();
adGroupAdOperation.setOperand(adGroupAd);
adGroupAdOperation.setOperator(Operator.ADD);
// Make the mutate request.
AdGroupAdReturnValue result = adGroupAdService.mutate(new AdGroupAdOperation[] { adGroupAdOperation });
// Display ads.
Arrays.stream(result.getValue()).map(adGroupAdResult -> (ResponsiveDisplayAd) adGroupAdResult.getAd()).forEach(newAd -> System.out.printf("Responsive display ad with ID %d and short headline '%s' was added.%n", newAd.getId(), newAd.getShortHeadline()));
}
use of com.google.api.ads.adwords.axis.v201809.cm.DynamicSettings in project googleads-java-lib by googleads.
the class AddShoppingDynamicRemarketingCampaign method createDynamicDisplayAdSettings.
/**
* Creates the additional content (images, promo text, etc.) supported by dynamic ads.
*
* @return the DynamicSettings object to be used.
*/
private static DynamicSettings createDynamicDisplayAdSettings(AdWordsServicesInterface services, AdWordsSession session) throws IOException {
Image logo = uploadImage(services, session, "https://goo.gl/dEvQeF");
DynamicSettings dynamicSettings = new DynamicSettings();
dynamicSettings.setLandscapeLogoImage(logo);
dynamicSettings.setPricePrefix("as low as");
dynamicSettings.setPromoText("Free shipping!");
return dynamicSettings;
}
Aggregations