use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.
the class AddSiteLinksUsingFeeds method createSiteLinksCampaignFeed.
private static void createSiteLinksCampaignFeed(AdWordsServicesInterface adWordsServices, AdWordsSession session, SiteLinksDataHolder siteLinksData, Long campaignId) throws RemoteException {
// Get the CampaignFeedService.
CampaignFeedServiceInterface campaignFeedService = adWordsServices.get(session, CampaignFeedServiceInterface.class);
// Construct a matching function that associates the sitelink feed items to the campaign, and
// sets the device preference to mobile. See the matching function guide at
// https://developers.google.com/adwords/api/docs/guides/feed-matching-functions
// for more details.
String matchingFunctionString = String.format("AND( IN(FEED_ITEM_ID, {%s}), EQUALS(CONTEXT.DEVICE, 'Mobile') )", Joiner.on(',').join(siteLinksData.siteLinkFeedItemIds));
CampaignFeed campaignFeed = new CampaignFeed();
campaignFeed.setFeedId(siteLinksData.siteLinksFeedId);
campaignFeed.setCampaignId(campaignId);
Function matchingFunction = new Function();
matchingFunction.setFunctionString(matchingFunctionString);
campaignFeed.setMatchingFunction(matchingFunction);
// Specifying placeholder types on the CampaignFeed allows the same feed
// to be used for different placeholders in different Campaigns.
campaignFeed.setPlaceholderTypes(new int[] { PLACEHOLDER_SITELINKS });
CampaignFeedOperation operation = new CampaignFeedOperation();
operation.setOperand(campaignFeed);
operation.setOperator(Operator.ADD);
CampaignFeedReturnValue result = campaignFeedService.mutate(new CampaignFeedOperation[] { operation });
for (CampaignFeed savedCampaignFeed : result.getValue()) {
System.out.printf("Campaign with ID %d was associated with feed with ID %d.%n", savedCampaignFeed.getCampaignId(), savedCampaignFeed.getFeedId());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.
the class AddSiteLinksUsingFeeds method createSiteLinksFeedMapping.
private static void createSiteLinksFeedMapping(AdWordsServicesInterface adWordsServices, AdWordsSession session, SiteLinksDataHolder siteLinksData) throws RemoteException {
// Get the FeedItemService.
FeedMappingServiceInterface feedMappingService = adWordsServices.get(session, FeedMappingServiceInterface.class);
// Map the FeedAttributeIds to the fieldId constants.
AttributeFieldMapping linkTextFieldMapping = new AttributeFieldMapping();
linkTextFieldMapping.setFeedAttributeId(siteLinksData.linkTextFeedAttributeId);
linkTextFieldMapping.setFieldId(PLACEHOLDER_FIELD_SITELINK_LINK_TEXT);
AttributeFieldMapping linkFinalUrlFieldMapping = new AttributeFieldMapping();
linkFinalUrlFieldMapping.setFeedAttributeId(siteLinksData.linkFinalUrlFeedAttributeId);
linkFinalUrlFieldMapping.setFieldId(PLACEHOLDER_FIELD_SITELINK_FINAL_URL);
AttributeFieldMapping line2FieldMapping = new AttributeFieldMapping();
line2FieldMapping.setFeedAttributeId(siteLinksData.line2FeedAttributeId);
line2FieldMapping.setFieldId(PLACEHOLDER_FIELD_LINE_2_TEXT);
AttributeFieldMapping line3FieldMapping = new AttributeFieldMapping();
line3FieldMapping.setFeedAttributeId(siteLinksData.line3FeedAttributeId);
line3FieldMapping.setFieldId(PLACEHOLDER_FIELD_LINE_3_TEXT);
// Create the FeedMapping and operation.
FeedMapping feedMapping = new FeedMapping();
feedMapping.setPlaceholderType(PLACEHOLDER_SITELINKS);
feedMapping.setFeedId(siteLinksData.siteLinksFeedId);
feedMapping.setAttributeFieldMappings(new AttributeFieldMapping[] { linkTextFieldMapping, linkFinalUrlFieldMapping, line2FieldMapping, line3FieldMapping });
FeedMappingOperation operation = new FeedMappingOperation();
operation.setOperand(feedMapping);
operation.setOperator(Operator.ADD);
// Save the field mapping.
FeedMappingReturnValue result = feedMappingService.mutate(new FeedMappingOperation[] { operation });
for (FeedMapping savedFeedMapping : result.getValue()) {
System.out.printf("Feed mapping with ID %d and placeholderType %d was saved for feed with ID %d.%n", savedFeedMapping.getFeedMappingId(), savedFeedMapping.getPlaceholderType(), savedFeedMapping.getFeedId());
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.
the class AddSiteLinksUsingFeeds method newSiteLinkFeedItemAddOperation.
private static FeedItemOperation newSiteLinkFeedItemAddOperation(SiteLinksDataHolder siteLinksData, String text, String finalUrl, String line2, String line3, boolean restrictToLop) {
// Create the FeedItemAttributeValues for our text values.
FeedItemAttributeValue linkTextAttributeValue = new FeedItemAttributeValue();
linkTextAttributeValue.setFeedAttributeId(siteLinksData.linkTextFeedAttributeId);
linkTextAttributeValue.setStringValue(text);
FeedItemAttributeValue linkFinalUrlAttributeValue = new FeedItemAttributeValue();
linkFinalUrlAttributeValue.setFeedAttributeId(siteLinksData.linkFinalUrlFeedAttributeId);
linkFinalUrlAttributeValue.setStringValues(new String[] { finalUrl });
FeedItemAttributeValue line2TextAttributeValue = new FeedItemAttributeValue();
line2TextAttributeValue.setFeedAttributeId(siteLinksData.line2FeedAttributeId);
line2TextAttributeValue.setStringValue(line2);
FeedItemAttributeValue line3TextAttributeValue = new FeedItemAttributeValue();
line3TextAttributeValue.setFeedAttributeId(siteLinksData.line3FeedAttributeId);
line3TextAttributeValue.setStringValue(line3);
// Create the feed item and operation.
FeedItem item = new FeedItem();
item.setFeedId(siteLinksData.siteLinksFeedId);
item.setAttributeValues(new FeedItemAttributeValue[] { linkTextAttributeValue, linkFinalUrlAttributeValue, line2TextAttributeValue, line3TextAttributeValue });
// OPTIONAL: Restrict targeting only to people physically within the location.
if (restrictToLop) {
FeedItemGeoRestriction geoTargetingRestriction = new FeedItemGeoRestriction();
geoTargetingRestriction.setGeoRestriction(GeoRestriction.LOCATION_OF_PRESENCE);
item.setGeoTargetingRestriction(geoTargetingRestriction);
}
// Optional: use item.setStartTime() and item.setEndTime() to specify the
// time period for the feed to deliver. The example below will make the feed
// start now and stop in one month.
// Make sure you specify the DateTime in the customer's time zone. You can
// retrieve this from customer.getDateTimeZone().
// item.setStartTime(new DateTime(customerTimeZone).toString("yyyyMMdd HHmmss"));
// item.setEndTime(new DateTime(customerTimeZone).plusMonths(1).toString("yyyyMMdd HHmmss"));
// Optional: use item.setScheduling() to specify time and days of the week for feed to deliver.
FeedItemOperation operation = new FeedItemOperation();
operation.setOperand(item);
operation.setOperator(Operator.ADD);
return operation;
}
use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.
the class UploadOfflineConversions method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param conversionName the name of the conversion tracker.
* @param gClid the GCLID for the conversion.
* @param conversionTime the date and time of the conversion.
* @param conversionValue the value of the conversion.
* @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, String conversionName, String gClid, String conversionTime, double conversionValue) throws RemoteException {
// Get the OfflineConversionFeedService.
OfflineConversionFeedServiceInterface offlineConversionFeedService = adWordsServices.get(session, OfflineConversionFeedServiceInterface.class);
// Associate offline conversions with the existing named conversion tracker. If this tracker
// was newly created, it may be a few hours before it can accept conversions.
OfflineConversionFeed feed = new OfflineConversionFeed();
feed.setConversionName(conversionName);
feed.setConversionTime(conversionTime);
feed.setConversionValue(conversionValue);
feed.setGoogleClickId(gClid);
OfflineConversionFeedOperation offlineConversionOperation = new OfflineConversionFeedOperation();
offlineConversionOperation.setOperator(Operator.ADD);
offlineConversionOperation.setOperand(feed);
OfflineConversionFeedReturnValue offlineConversionReturnValue = offlineConversionFeedService.mutate(new OfflineConversionFeedOperation[] { offlineConversionOperation });
OfflineConversionFeed newFeed = offlineConversionReturnValue.getValue(0);
System.out.printf("Uploaded offline conversion value of %.4f for Google Click ID '%s' to '%s'.%n", newFeed.getConversionValue(), newFeed.getGoogleClickId(), newFeed.getConversionName());
}
use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.
the class AddAdCustomizer method createCustomizerFeedItems.
/**
* Creates FeedItems with the values to use in ad customizations for each ad group in
* <code>adGroupIds</code>.
*/
private static void createCustomizerFeedItems(AdWordsServicesInterface adWordsServices, AdWordsSession session, List<Long> adGroupIds, AdCustomizerFeed adCustomizerFeed) throws RemoteException {
// Get the FeedItemService.
FeedItemServiceInterface feedItemService = adWordsServices.get(session, FeedItemServiceInterface.class);
List<FeedItemOperation> feedItemOperations = new ArrayList<>();
DateTime now = DateTime.now();
DateTime marsDate = new DateTime(now.getYear(), now.getMonthOfYear(), 1, 0, 0);
feedItemOperations.add(createFeedItemAddOperation("Mars", "$1234.56", marsDate.toString("yyyyMMdd HHmmss"), adCustomizerFeed));
DateTime venusDate = new DateTime(now.getYear(), now.getMonthOfYear(), 15, 0, 0);
feedItemOperations.add(createFeedItemAddOperation("Venus", "$1450.00", venusDate.toString("yyyyMMdd HHmmss"), adCustomizerFeed));
FeedItemReturnValue feedItemReturnValue = feedItemService.mutate(feedItemOperations.toArray(new FeedItemOperation[feedItemOperations.size()]));
for (FeedItem addedFeedItem : feedItemReturnValue.getValue()) {
System.out.printf("Added feed item with ID %d.%n", addedFeedItem.getFeedItemId());
}
// Add feed item targeting to restrict the feed item to specific ad groups.
restrictFeedItemToAdGroup(adWordsServices, session, feedItemReturnValue.getValue(0), adGroupIds.get(0));
restrictFeedItemToAdGroup(adWordsServices, session, feedItemReturnValue.getValue(1), adGroupIds.get(1));
}
Aggregations