Search in sources :

Example 41 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.

the class AddSiteLinksUsingFeeds method restrictFeedItemToAdGroup.

/**
 * Restricts the first feed item in {@code siteLinksData} to only serve with ads for the specified
 * ad group ID.
 */
private static void restrictFeedItemToAdGroup(AdWordsServicesInterface adWordsServices, AdWordsSession session, SiteLinksDataHolder siteLinksData, Long adGroupId) throws RemoteException {
    FeedItemTargetServiceInterface feedItemTargetService = adWordsServices.get(session, FeedItemTargetServiceInterface.class);
    FeedItemAdGroupTarget feedItemAdGroupTarget = new FeedItemAdGroupTarget();
    feedItemAdGroupTarget.setAdGroupId(adGroupId);
    feedItemAdGroupTarget.setFeedId(siteLinksData.siteLinksFeedId);
    feedItemAdGroupTarget.setFeedItemId(siteLinksData.siteLinkFeedItemIds.get(0));
    FeedItemTargetOperation operation = new FeedItemTargetOperation();
    operation.setOperand(feedItemAdGroupTarget);
    operation.setOperator(Operator.ADD);
    feedItemAdGroupTarget = (FeedItemAdGroupTarget) feedItemTargetService.mutate(new FeedItemTargetOperation[] { operation }).getValue(0);
    System.out.printf("Feed item target for feed ID %d and feed item ID %d was created to restrict serving to " + "ad group ID %d'.%n", feedItemAdGroupTarget.getFeedId(), feedItemAdGroupTarget.getFeedItemId(), feedItemAdGroupTarget.getAdGroupId());
}
Also used : FeedItemTargetServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedItemTargetServiceInterface) FeedItemAdGroupTarget(com.google.api.ads.adwords.axis.v201809.cm.FeedItemAdGroupTarget) FeedItemTargetOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedItemTargetOperation)

Example 42 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation 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());
    }
}
Also used : CampaignFeedServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedServiceInterface) CampaignFeed(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeed) Function(com.google.api.ads.adwords.axis.v201809.cm.Function) CampaignFeedReturnValue(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedReturnValue) CampaignFeedOperation(com.google.api.ads.adwords.axis.v201809.cm.CampaignFeedOperation)

Example 43 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation 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());
    }
}
Also used : AttributeFieldMapping(com.google.api.ads.adwords.axis.v201809.cm.AttributeFieldMapping) FeedMappingReturnValue(com.google.api.ads.adwords.axis.v201809.cm.FeedMappingReturnValue) FeedMappingServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.FeedMappingServiceInterface) FeedMapping(com.google.api.ads.adwords.axis.v201809.cm.FeedMapping) FeedMappingOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedMappingOperation)

Example 44 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation 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;
}
Also used : FeedItem(com.google.api.ads.adwords.axis.v201809.cm.FeedItem) FeedItemAttributeValue(com.google.api.ads.adwords.axis.v201809.cm.FeedItemAttributeValue) FeedItemGeoRestriction(com.google.api.ads.adwords.axis.v201809.cm.FeedItemGeoRestriction) FeedItemOperation(com.google.api.ads.adwords.axis.v201809.cm.FeedItemOperation)

Example 45 with Operation

use of com.google.api.ads.adwords.axis.v201809.cm.Operation in project googleads-java-lib by googleads.

the class AddCrmBasedUserList 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.
 * @throws UnsupportedEncodingException if encoding the hashed email failed.
 */
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException, UnsupportedEncodingException {
    // Get the UserListService.
    AdwordsUserListServiceInterface userListService = adWordsServices.get(session, AdwordsUserListServiceInterface.class);
    // Create a user list.
    CrmBasedUserList userList = new CrmBasedUserList();
    userList.setName("Customer relationship management list #" + System.currentTimeMillis());
    userList.setDescription("A list of customers that originated from email addresses");
    // CRM-based user lists can use a membershipLifeSpan of 10000 to indicate unlimited; otherwise
    // normal values apply.
    userList.setMembershipLifeSpan(30L);
    userList.setUploadKeyType(CustomerMatchUploadKeyType.CONTACT_INFO);
    // Create operation.
    UserListOperation operation = new UserListOperation();
    operation.setOperand(userList);
    operation.setOperator(Operator.ADD);
    // Add user list.
    UserListReturnValue result = userListService.mutate(new UserListOperation[] { operation });
    // Display user list.
    UserList userListAdded = result.getValue(0);
    System.out.printf("User list with name '%s' and ID %d was added.%n", userListAdded.getName(), userListAdded.getId());
    // Get user list ID.
    Long userListId = userListAdded.getId();
    // Create operation to add members to the user list based on email addresses.
    MutateMembersOperation mutateMembersOperation = new MutateMembersOperation();
    MutateMembersOperand operand = new MutateMembersOperand();
    operand.setUserListId(userListId);
    // Hash normalized email addresses based on SHA-256 hashing algorithm.
    List<Member> members = new ArrayList<>(EMAILS.size());
    for (String email : EMAILS) {
        String normalizedEmail = toNormalizedString(email);
        Member member = new Member();
        member.setHashedEmail(toSHA256String(normalizedEmail));
        members.add(member);
    }
    String firstName = "John";
    String lastName = "Doe";
    String countryCode = "US";
    String zipCode = "10011";
    AddressInfo addressInfo = new AddressInfo();
    // First and last name must be normalized and hashed.
    addressInfo.setHashedFirstName(toSHA256String(toNormalizedString(firstName)));
    addressInfo.setHashedLastName(toSHA256String(toNormalizedString(lastName)));
    // Country code and zip code are sent in plaintext.
    addressInfo.setCountryCode(countryCode);
    addressInfo.setZipCode(zipCode);
    Member memberByAddress = new Member();
    memberByAddress.setAddressInfo(addressInfo);
    members.add(memberByAddress);
    operand.setMembersList(members.toArray(new Member[members.size()]));
    mutateMembersOperation.setOperand(operand);
    mutateMembersOperation.setOperator(Operator.ADD);
    // Add members to the user list based on email addresses.
    MutateMembersReturnValue mutateMembersResult = userListService.mutateMembers(new MutateMembersOperation[] { mutateMembersOperation });
    // Reminder: it may take several hours for the list to be populated with members.
    for (UserList userListResult : mutateMembersResult.getUserLists()) {
        System.out.printf("%d email addresses were uploaded to user list with name '%s' and ID %d " + "and are scheduled for review.%n", EMAILS.size(), userListResult.getName(), userListResult.getId());
    }
}
Also used : AdwordsUserListServiceInterface(com.google.api.ads.adwords.axis.v201809.rm.AdwordsUserListServiceInterface) ArrayList(java.util.ArrayList) UserListOperation(com.google.api.ads.adwords.axis.v201809.rm.UserListOperation) UserListReturnValue(com.google.api.ads.adwords.axis.v201809.rm.UserListReturnValue) AddressInfo(com.google.api.ads.adwords.axis.v201809.rm.AddressInfo) CrmBasedUserList(com.google.api.ads.adwords.axis.v201809.rm.CrmBasedUserList) MutateMembersOperation(com.google.api.ads.adwords.axis.v201809.rm.MutateMembersOperation) MutateMembersOperand(com.google.api.ads.adwords.axis.v201809.rm.MutateMembersOperand) UserList(com.google.api.ads.adwords.axis.v201809.rm.UserList) CrmBasedUserList(com.google.api.ads.adwords.axis.v201809.rm.CrmBasedUserList) Member(com.google.api.ads.adwords.axis.v201809.rm.Member) MutateMembersReturnValue(com.google.api.ads.adwords.axis.v201809.rm.MutateMembersReturnValue)

Aggregations

ArrayList (java.util.ArrayList)24 Money (com.google.api.ads.adwords.axis.v201809.cm.Money)18 CampaignOperation (com.google.api.ads.adwords.axis.v201809.cm.CampaignOperation)17 BiddingStrategyConfiguration (com.google.api.ads.adwords.axis.v201809.cm.BiddingStrategyConfiguration)16 AdGroupCriterionOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterionOperation)15 AdGroupAdOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdOperation)14 Campaign (com.google.api.ads.adwords.axis.v201809.cm.Campaign)14 AdGroupAd (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAd)13 Budget (com.google.api.ads.adwords.axis.v201809.cm.Budget)13 AdGroupAdServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdServiceInterface)12 BiddableAdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.BiddableAdGroupCriterion)12 AdGroupOperation (com.google.api.ads.adwords.axis.v201809.cm.AdGroupOperation)11 CampaignServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.CampaignServiceInterface)11 AdGroupAdReturnValue (com.google.api.ads.adwords.axis.v201809.cm.AdGroupAdReturnValue)10 CpcBid (com.google.api.ads.adwords.axis.v201809.cm.CpcBid)10 AdGroupCriterion (com.google.api.ads.adwords.axis.v201809.cm.AdGroupCriterion)9 AdWordsServices (com.google.api.ads.adwords.axis.factory.AdWordsServices)8 AdGroup (com.google.api.ads.adwords.axis.v201809.cm.AdGroup)8 ApiException (com.google.api.ads.adwords.axis.v201809.cm.ApiException)8 Keyword (com.google.api.ads.adwords.axis.v201809.cm.Keyword)8