use of com.google.api.ads.adwords.axis.v201809.cm.Feed 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.Feed in project googleads-java-lib by googleads.
the class MigrateToExtensionSettings 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 all of the feeds for the session's account.
List<Feed> feeds = getFeeds(adWordsServices, session);
for (Feed feed : feeds) {
// Retrieve all the sitelinks from the current feed.
Map<Long, SiteLinkFromFeed> feedItems = getSiteLinksFromFeed(adWordsServices, session, feed);
// Get all the instances where a sitelink from this feed has been added to a campaign.
List<CampaignFeed> campaignFeeds = getCampaignFeeds(adWordsServices, session, feed, PLACEHOLDER_SITELINKS);
Set<Long> allFeedItemsToDelete = Sets.newHashSet();
for (CampaignFeed campaignFeed : campaignFeeds) {
// Retrieve the sitelinks that have been associated with this campaign.
Set<Long> feedItemIds = getFeedItemIdsForCampaign(campaignFeed);
ExtensionSettingPlatform platformRestrictions = getPlatformRestictionsForCampaign(campaignFeed);
if (feedItemIds.isEmpty()) {
System.out.printf("Migration skipped for campaign feed with campaign ID %d " + "and feed ID %d because no mapped feed item IDs were found in the " + "campaign feed's matching function.%n", campaignFeed.getCampaignId(), campaignFeed.getFeedId());
} else {
// Delete the campaign feed that associates the sitelinks from the feed to the campaign.
deleteCampaignFeed(adWordsServices, session, campaignFeed);
// Create extension settings instead of sitelinks.
createExtensionSetting(adWordsServices, session, feedItems, campaignFeed, feedItemIds, platformRestrictions);
// Mark the sitelinks from the feed for deletion.
allFeedItemsToDelete.addAll(feedItemIds);
}
}
// Delete all the sitelinks from the feed.
deleteOldFeedItems(adWordsServices, session, allFeedItemsToDelete, feed);
}
}
use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.
the class MigrateToExtensionSettings method createExtensionSetting.
/**
* Creates the extension setting for a list of feed items.
*
* @param adWordsServices the AdWordsServices
* @param session the AdWordsSession
* @param feedItems the list of all feed items
* @param campaignFeed the original campaign feed
* @param feedItemIds IDs of the feed items for which extension settings should be created
* @param platformRestrictions the platform restrictions for the new campaign extension setting
*/
private static void createExtensionSetting(AdWordsServicesInterface adWordsServices, AdWordsSession session, Map<Long, SiteLinkFromFeed> feedItems, CampaignFeed campaignFeed, Set<Long> feedItemIds, ExtensionSettingPlatform platformRestrictions) throws RemoteException {
// Get the CampaignExtensionSettingService.
CampaignExtensionSettingServiceInterface campaignExtensionSettingService = adWordsServices.get(session, CampaignExtensionSettingServiceInterface.class);
CampaignExtensionSetting campaignExtensionSetting = new CampaignExtensionSetting();
campaignExtensionSetting.setCampaignId(campaignFeed.getCampaignId());
campaignExtensionSetting.setExtensionType(FeedType.SITELINK);
ExtensionSetting extensionSetting = new ExtensionSetting();
List<ExtensionFeedItem> extensionFeedItems = new ArrayList<>();
for (Long feedItemId : feedItemIds) {
SiteLinkFromFeed siteLinkFromFeed = feedItems.get(feedItemId);
SitelinkFeedItem siteLinkFeedItem = new SitelinkFeedItem();
siteLinkFeedItem.setSitelinkText(siteLinkFromFeed.text);
if (siteLinkFromFeed.finalUrls != null && siteLinkFromFeed.finalUrls.length > 0) {
siteLinkFeedItem.setSitelinkFinalUrls(new UrlList(siteLinkFromFeed.finalUrls));
if (siteLinkFromFeed.finalMobileUrls != null && siteLinkFromFeed.finalMobileUrls.length > 0) {
siteLinkFeedItem.setSitelinkFinalMobileUrls(new UrlList(siteLinkFromFeed.finalMobileUrls));
}
siteLinkFeedItem.setSitelinkTrackingUrlTemplate(siteLinkFromFeed.trackingUrlTemplate);
} else {
siteLinkFeedItem.setSitelinkUrl(siteLinkFromFeed.url);
}
siteLinkFeedItem.setSitelinkLine2(siteLinkFromFeed.line2);
siteLinkFeedItem.setSitelinkLine3(siteLinkFromFeed.line3);
extensionFeedItems.add(siteLinkFeedItem);
}
extensionSetting.setExtensions(extensionFeedItems.toArray(new ExtensionFeedItem[extensionFeedItems.size()]));
extensionSetting.setPlatformRestrictions(platformRestrictions);
campaignExtensionSetting.setExtensionSetting(extensionSetting);
CampaignExtensionSettingOperation operation = new CampaignExtensionSettingOperation();
operation.setOperand(campaignExtensionSetting);
operation.setOperator(Operator.ADD);
campaignExtensionSettingService.mutate(new CampaignExtensionSettingOperation[] { operation });
}
use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.
the class MigrateToExtensionSettings method getFeeds.
/**
* Returns a list of all enabled feeds.
*/
private static List<Feed> getFeeds(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
FeedServiceInterface feedService = adWordsServices.get(session, FeedServiceInterface.class);
String query = "SELECT Id, Name, Attributes WHERE Origin = 'USER' AND FeedStatus = 'ENABLED'";
List<Feed> feeds = new ArrayList<>();
int offset = 0;
FeedPage feedPage;
do {
String pageQuery = String.format(query + " LIMIT %d, %d", offset, PAGE_SIZE);
feedPage = feedService.query(pageQuery);
if (feedPage.getEntries() != null) {
feeds.addAll(Arrays.asList(feedPage.getEntries()));
}
offset += PAGE_SIZE;
} while (offset < feedPage.getTotalNumEntries());
return feeds;
}
use of com.google.api.ads.adwords.axis.v201809.cm.Feed in project googleads-java-lib by googleads.
the class MigrateToExtensionSettings method getFeedItemIdsForCampaign.
/**
* Returns the list of feed item IDs that are used by a campaign through a given campaign feed.
*/
private static Set<Long> getFeedItemIdsForCampaign(CampaignFeed campaignFeed) throws RemoteException {
Set<Long> feedItemIds = Sets.newHashSet();
FunctionOperator functionOperator = campaignFeed.getMatchingFunction().getOperator();
if (FunctionOperator.IN.equals(functionOperator)) {
// Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
// Extract feed items if applicable.
feedItemIds.addAll(getFeedItemIdsFromArgument(campaignFeed.getMatchingFunction()));
} else if (FunctionOperator.AND.equals(functionOperator)) {
// Check if matchingFunction is of the form IN(FEED_ITEM_ID,{xxx,xxx}).
// Extract feed items if applicable.
Arrays.stream(campaignFeed.getMatchingFunction().getLhsOperand()).filter(FunctionOperand.class::isInstance).map(argument -> (FunctionOperand) argument).filter(operand -> FunctionOperator.IN.equals(operand.getValue().getOperator())).forEach(operand -> feedItemIds.addAll(getFeedItemIdsFromArgument(operand.getValue())));
} else {
// There are no other matching functions involving feed item IDs.
}
return feedItemIds;
}
Aggregations