// Get the AdwordsUserListService.
AdwordsUserListServiceInterface adwordsUserListService =
user.getService(AdWordsService.V201306.ADWORDS_USER_LIST_SERVICE);
// Get the ConversionTrackerService.
ConversionTrackerServiceInterface conversionTrackerService =
user.getService(AdWordsService.V201306.CONVERSION_TRACKER_SERVICE);
// Create conversion type (tag).
UserListConversionType conversionType = new UserListConversionType();
conversionType.setName("Mars cruise customers #" + System.currentTimeMillis());
// Create remarketing user list.
BasicUserList userList = new BasicUserList();
userList.setName("Mars cruise customers #" + System.currentTimeMillis());
userList.setDescription("A list of mars cruise customers in the last year");
userList.setMembershipLifeSpan(365L);
userList.setConversionTypes(new UserListConversionType[] {conversionType});
// Create operations.
UserListOperation operation = new UserListOperation();
operation.setOperand(userList);
operation.setOperator(Operator.ADD);
UserListOperation[] operations = new UserListOperation[] {operation};
// Add user list.
UserListReturnValue result = adwordsUserListService.mutate(operations);
// Display results.
if (result != null && result.getValue() != null) {
// Capture the ID(s) of the conversion.
List<String> conversionIds = new ArrayList<String>();
for (UserList userListResult : result.getValue()) {
if (userListResult instanceof BasicUserList) {
BasicUserList remarketingAdwordsUserList = (BasicUserList) userListResult;
for (UserListConversionType userListConversionType :
remarketingAdwordsUserList.getConversionTypes()) {
conversionIds.add(userListConversionType.getId().toString());
}
}
}
// Create predicate and selector.
Predicate predicate = new Predicate();
predicate.setField("Id");
predicate.setOperator(PredicateOperator.IN);
predicate.setValues(conversionIds.toArray(new String[0]));
Selector selector = new Selector();
selector.setFields(new String[] {"Id"});
selector.setPredicates(new Predicate[] {predicate});
// Get all conversion trackers.
Map<Long, AdWordsConversionTracker> conversionTrackers =
new HashMap<Long, AdWordsConversionTracker>();
ConversionTrackerPage page = conversionTrackerService.get(selector);
if (page != null && page.getEntries() != null) {
for (ConversionTracker conversionTracker : page.getEntries()) {
conversionTrackers.put(conversionTracker.getId(),
(AdWordsConversionTracker) conversionTracker);
}