/// <summary> /// Creates the customer match user list. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for which the user list is added. /// </param> /// <returns>The resource name of the newly created user list</returns> private string CreateCustomerMatchUserList(GoogleAdsClient client, long customerId) { // Get the UserListService. UserListServiceClient service = client.GetService(Services.V4.UserListService); // Creates the user list. UserList userList = new UserList() { Name = $"Customer Match list# {ExampleUtilities.GetShortRandomString()}", Description = "A list of customers that originated from email and physical" + " addresses", // Customer Match user lists can use a membership life span of 10000 to // indicate unlimited; otherwise normal values apply. // Sets the membership life span to 30 days. MembershipLifeSpan = 30, CrmBasedUserList = new CrmBasedUserListInfo() { UploadKeyType = CustomerMatchUploadKeyType.ContactInfo } }; // Creates the user list operation. UserListOperation operation = new UserListOperation() { Create = userList }; // Issues a mutate request to add the user list and prints some information. MutateUserListsResponse response = service.MutateUserLists( customerId.ToString(), new[] { operation }); string userListResourceName = response.Results[0].ResourceName; Console.WriteLine($"User list with resource name '{userListResourceName}' " + $"was created."); return(userListResourceName); }
/// <summary> /// Creates the user list. /// </summary> /// <param name="user">The AdWords user.</param> /// <returns>The user list ID.</returns> public long CreateUserList(AdWordsUser user) { using (AdwordsUserListService userListService = (AdwordsUserListService)user.GetService( AdWordsService.v201802.AdwordsUserListService)) { BasicUserList userList = new BasicUserList(); userList.name = "Mars cruise customers #" + GetTimeStamp(); userList.description = "A list of mars cruise customers in the last year."; userList.status = UserListMembershipStatus.OPEN; userList.membershipLifeSpan = 365; UserListConversionType conversionType = new UserListConversionType(); conversionType.name = userList.name; userList.conversionTypes = new UserListConversionType[] { conversionType }; // Optional: Set the user list status. userList.status = UserListMembershipStatus.OPEN; // Create the operation. UserListOperation operation = new UserListOperation(); operation.operand = userList; operation.@operator = Operator.ADD; UserListReturnValue retval = userListService.mutate( new UserListOperation[] { operation }); return(retval.value[0].id); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The client customer ID.</param> /// <param name="conversionActionIds">The IDs of the conversion actions for the basic user /// list.</param> public void Run(GoogleAdsClient client, long customerId, long[] conversionActionIds) { // Creates the service client. UserListServiceClient userListServiceClient = client.GetService(Services.V4.UserListService); List <UserListActionInfo> userListActionInfoList = new List <UserListActionInfo>(); foreach (long conversionActionId in conversionActionIds) { // Creates the UserListActionInfo object for a given conversion action. This // specifies the conversion action that, when triggered, will cause a user to be // added to a UserList. userListActionInfoList.Add(new UserListActionInfo { ConversionAction = ResourceNames.ConversionAction(customerId, conversionActionId) }); } // Creates a basic user list info object with all of the conversion actions. BasicUserListInfo basicUserListInfo = new BasicUserListInfo(); basicUserListInfo.Actions.Add(userListActionInfoList); // Creates the basic user list. UserList basicUserList = new UserList { Name = $"Example BasicUserList #{ExampleUtilities.GetShortRandomString()}", Description = "A list of people who have triggered one or more conversion actions", MembershipLifeSpan = 365L, BasicUserList = basicUserListInfo, MembershipStatus = UserListMembershipStatus.Open }; // Creates the operation. UserListOperation operation = new UserListOperation { Create = basicUserList }; try { // Adds the new user list. MutateUserListsResponse response = userListServiceClient.MutateUserLists (customerId.ToString(), new[] { operation }); // Prints the result. Console.WriteLine("Created basic user list with resource name: " + $"{response.Results.First().ResourceName}"); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
/// <summary>Snippet for MutateUserLists</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void MutateUserLists() { // Create client UserListServiceClient userListServiceClient = UserListServiceClient.Create(); // Initialize request argument(s) string customerId = ""; IEnumerable <UserListOperation> operations = new UserListOperation[] { new UserListOperation(), }; // Make the request MutateUserListsResponse response = userListServiceClient.MutateUserLists(customerId, operations); }
/// <summary>Snippet for MutateUserListsAsync</summary> public async Task MutateUserListsAsync() { // Snippet: MutateUserListsAsync(string, IEnumerable<UserListOperation>, CallSettings) // Additional: MutateUserListsAsync(string, IEnumerable<UserListOperation>, CancellationToken) // Create client UserListServiceClient userListServiceClient = await UserListServiceClient.CreateAsync(); // Initialize request argument(s) string customerId = ""; IEnumerable <UserListOperation> operations = new UserListOperation[] { new UserListOperation(), }; // Make the request MutateUserListsResponse response = await userListServiceClient.MutateUserListsAsync(customerId, operations); // End snippet }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID.</param> // [START add_combined_rule_user_list] public void Run(GoogleAdsClient client, long customerId) { // Get the UserListServiceClient. UserListServiceClient userListServiceClient = client.GetService(Services.V10.UserListService); // Creates a rule targeting any user that visited a url that equals // 'http://example.com/example1'. UserListRuleInfo userVisitedSite1RuleInfo = BuildVisitedSiteRuleInfo("http://example.com/example1"); // Creates a rule targeting any user that visited a url that equals // 'http://example.com/example2'. UserListRuleInfo userVisitedSite2RuleInfo = BuildVisitedSiteRuleInfo("http://example.com/example2"); // Creates the user list where "Visitors of a page who did visit another page". // To create a user list where "Visitors of a page who did not visit another page", // change the UserListCombinedRuleOperator from .And to .AndNot. CombinedRuleUserListInfo combinedRuleUserListInfo = new CombinedRuleUserListInfo() { LeftOperand = userVisitedSite1RuleInfo, RightOperand = userVisitedSite2RuleInfo, RuleOperator = UserListCombinedRuleOperator.And }; // Defines a representation of a user list that is generated by a rule. RuleBasedUserListInfo ruleBasedUserListInfo = new RuleBasedUserListInfo() { // Optional: To include past users in the user list, set the prepopulation_status to // REQUESTED. PrepopulationStatus = UserListPrepopulationStatus.Requested, CombinedRuleUserList = combinedRuleUserListInfo }; // Creates a user list. UserList userList = new UserList() { Name = "All visitors to http://example.com/example1 AND " + $"http://example.com/example2 #{ExampleUtilities.GetShortRandomString()}", Description = "Visitors of both http://example.com/example1 AND " + "http://example.com/example2", MembershipStatus = UserListMembershipStatus.Open, MembershipLifeSpan = 365L, RuleBasedUserList = ruleBasedUserListInfo }; // Creates the operation. UserListOperation operation = new UserListOperation() { Create = userList }; try { // Adds the new user list and prints the result. MutateUserListsResponse response = userListServiceClient.MutateUserLists (customerId.ToString(), new[] { operation }); Console.WriteLine("Created user list with resource name:" + $"{response.Results.First().ResourceName}"); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { using (AdwordsUserListService userListService = (AdwordsUserListService)user.GetService(AdWordsService.v201802 .AdwordsUserListService)) using (ConversionTrackerService conversionTrackerService = (ConversionTrackerService)user.GetService(AdWordsService.v201802 .ConversionTrackerService)) { BasicUserList userList = new BasicUserList { name = "Mars cruise customers #" + ExampleUtilities.GetRandomString(), description = "A list of mars cruise customers in the last year.", status = UserListMembershipStatus.OPEN, membershipLifeSpan = 365 }; UserListConversionType conversionType = new UserListConversionType { name = userList.name }; userList.conversionTypes = new UserListConversionType[] { conversionType }; // Optional: Set the user list status. userList.status = UserListMembershipStatus.OPEN; // Create the operation. UserListOperation operation = new UserListOperation { operand = userList, @operator = Operator.ADD }; try { // Add the user list. UserListReturnValue retval = userListService.mutate(new UserListOperation[] { operation }); UserList newUserList = retval.value[0]; Console.WriteLine("User list with name '{0}' and id '{1}' was added.", newUserList.name, newUserList.id); List <string> conversionIds = new List <string>(); Array.ForEach(userList.conversionTypes, delegate(UserListConversionType item) { conversionIds.Add(item.id.ToString()); }); // Create the selector. Selector selector = new Selector() { fields = new string[] { ConversionTracker.Fields.Id, ConversionTracker.Fields.GoogleGlobalSiteTag, ConversionTracker.Fields.GoogleEventSnippet }, predicates = new Predicate[] { Predicate.In(ConversionTracker.Fields.Id, conversionIds.ToArray()) } }; // Get all conversion trackers. ConversionTrackerPage page = conversionTrackerService.get(selector); if (page != null && page.entries != null) { foreach (ConversionTracker tracker in page.entries) { Console.WriteLine( "Google global site tag:\n{0}\nGoogle event snippet:\n{1}", tracker.googleGlobalSiteTag, tracker.googleGlobalSiteTag); } } } catch (Exception e) { throw new System.ApplicationException( "Failed to add user lists (a.k.a. audiences).", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for the conversion action is /// added.</param> public void Run(GoogleAdsClient client, long customerId) { // Get the user list service client. UserListServiceClient userListServiceClient = client.GetService(Services.V6.UserListService); try { // Create a rule targeting any user that visited the checkout page. UserListRuleItemInfo checkoutRule = new UserListRuleItemInfo { // The rule variable name must match a corresponding key name fired from a pixel. // To learn more about setting up remarketing tags, visit // https://support.google.com/google-ads/answer/2476688. // To learn more about remarketing events and parameters, visit // https://support.google.com/google-ads/answer/7305793. Name = "ecomm_pagetype", StringRuleItem = new UserListStringRuleItemInfo { Operator = UserListStringRuleItemOperator.Equals, Value = "checkout" } }; // Create a rule targeting any user that had more than one item in their cart. UserListRuleItemInfo cartSizeRule = new UserListRuleItemInfo { // The rule variable name must match a corresponding key name fired from a pixel. Name = "cart_size", NumberRuleItem = new UserListNumberRuleItemInfo { Operator = UserListNumberRuleItemOperator.GreaterThan, Value = 1.0 } }; // Create a rule group that includes the checkout and cart size rules. Combining the // two rule items into a UserListRuleItemGroupInfo object causes Google Ads to AND // their rules together. To instead OR the rules together, each rule should be // placed in its own rule item group. UserListRuleItemGroupInfo checkoutAndCartSizeRuleGroup = new UserListRuleItemGroupInfo(); checkoutAndCartSizeRuleGroup.RuleItems.Add(checkoutRule); checkoutAndCartSizeRuleGroup.RuleItems.Add(cartSizeRule); // Create the RuleItem for checkout start date. // The tags and keys used below must have been in place in the past for the date // range specified in the rules. UserListRuleItemInfo startDateRule = new UserListRuleItemInfo { // The rule variable name must match a corresponding key name fired from a pixel. Name = "checkoutdate", DateRuleItem = new UserListDateRuleItemInfo { // Available UserListDateRuleItemOperators can be found at // https://developers.google.com/google-ads/api/reference/rpc/latest/UserListDateRuleItemOperatorEnum.UserListDateRuleItemOperator Operator = UserListDateRuleItemOperator.After, Value = "20191031" } }; // Create the RuleItem for checkout end date. UserListRuleItemInfo endDateRule = new UserListRuleItemInfo { // The rule variable name must match a corresponding key name fired from a pixel. Name = "checkoutdate", DateRuleItem = new UserListDateRuleItemInfo { Operator = UserListDateRuleItemOperator.Before, Value = "20200101" } }; // Create a rule group targeting users who checked out between November and December // by using the start and end date rules. Combining the two rule items into a // UserListRuleItemGroupInfo object causes Google Ads to AND their rules together. // To instead OR the rules together, each rule should be placed in its own rule item // group. UserListRuleItemGroupInfo checkoutDateRuleGroup = new UserListRuleItemGroupInfo(); checkoutDateRuleGroup.RuleItems.Add(startDateRule); checkoutDateRuleGroup.RuleItems.Add(endDateRule); // Create an ExpressionRuleUserListInfo object, or a boolean rule that defines this // user list. The default rule_type for a UserListRuleInfo object is OR of ANDs // (disjunctive normal form). That is, rule items will be ANDed together within rule // item groups and the groups themselves will be ORed together. ExpressionRuleUserListInfo expressionRuleUserListInfo = new ExpressionRuleUserListInfo { Rule = new UserListRuleInfo() }; expressionRuleUserListInfo.Rule.RuleItemGroups.Add(checkoutAndCartSizeRuleGroup); expressionRuleUserListInfo.Rule.RuleItemGroups.Add(checkoutDateRuleGroup); // Defines a representation of a user list that is generated by a rule. RuleBasedUserListInfo ruleBasedUserListInfo = new RuleBasedUserListInfo { // Optional: To include past users in the user list, set the // prepopulation status to REQUESTED. PrepopulationStatus = UserListPrepopulationStatus.Requested, ExpressionRuleUserList = expressionRuleUserListInfo }; // Create a user list. UserList userList = new UserList { Name = $"My expression rule user list #{ExampleUtilities.GetRandomString()}", Description = "Users who checked out in November or December OR visited the checkout " + "page with more than one item in their cart", MembershipLifeSpan = 90L, MembershipStatus = UserListMembershipStatus.Open, RuleBasedUserList = ruleBasedUserListInfo }; // Create the operation. UserListOperation userListOperation = new UserListOperation { Create = userList }; // Add the user list and print the results. MutateUserListsResponse response = userListServiceClient.MutateUserLists(customerId.ToString(), new[] { userListOperation }); string userListResourceName = response.Results.First().ResourceName; Console.WriteLine( $"Created user list with resource name '{userListResourceName}'."); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { using (AdwordsUserListService userListService = (AdwordsUserListService)user.GetService(AdWordsService.v201809 .AdwordsUserListService)) { // Create a user list. CrmBasedUserList userList = new CrmBasedUserList() { name = "Customer relationship management list #" + ExampleUtilities.GetRandomString(), description = "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. membershipLifeSpan = 30L, uploadKeyType = CustomerMatchUploadKeyType.CONTACT_INFO }; // Create operation. UserListOperation operation = new UserListOperation() { operand = userList, @operator = Operator.ADD }; try { // Add user list. UserListReturnValue result = userListService.mutate(new UserListOperation[] { operation }); Console.WriteLine( "Created new user list with name = '{0}' and id = " + "'{1}'.", result.value[0].name, result.value[0].id); // Get user list ID. long userListId = result.value[0].id; // Prepare the emails for upload. List <Member> memberList = new List <Member>(); // Hash normalized email addresses based on SHA-256 hashing algorithm. string[] emailHashes = new string[EMAILS.Length]; for (int i = 0; i < EMAILS.Length; i++) { Member member = new Member { hashedEmail = ToSha256String(digest, ToNormalizedEmail(EMAILS[i])) }; memberList.Add(member); } ; // Add a user by first and last name. AddressInfo addressInfo = new AddressInfo { // First and last name must be normalized and hashed. hashedFirstName = ToSha256String(digest, FIRST_NAME), hashedLastName = ToSha256String(digest, LAST_NAME), // Country code and zip code are sent in plaintext. zipCode = ZIP_CODE, countryCode = COUNTRY_CODE }; Member memberByAddress = new Member { addressInfo = addressInfo }; memberList.Add(memberByAddress); // Create operation to add members to the user list based on email // addresses. MutateMembersOperation mutateMembersOperation = new MutateMembersOperation() { operand = new MutateMembersOperand() { userListId = userListId, membersList = memberList.ToArray() }, @operator = Operator.ADD }; // Add members to the user list based on email addresses. MutateMembersReturnValue mutateMembersResult = userListService.mutateMembers( new MutateMembersOperation[] { mutateMembersOperation }); // Display results. // Reminder: it may take several hours for the list to be populated // with members. foreach (UserList userListResult in mutateMembersResult.userLists) { Console.WriteLine( "Email addresses were added to user list with " + "name '{0}' and id '{1}'.", userListResult.name, userListResult.id); } } catch (Exception e) { throw new System.ApplicationException( "Failed to add user lists " + "(a.k.a. audiences) and upload email addresses.", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID.</param> /// <param name="userListIds">The IDs of the lists to be used for the new combination user /// list.</param> public void Run(GoogleAdsClient client, long customerId, long[] userListIds) { // Gets the UserListService client. UserListServiceClient userListServiceClient = client.GetService(Services.V6.UserListService); // Adds each of the provided list IDs to a list of rule operands specifying which lists // the operator should target. List <LogicalUserListOperandInfo> logicalUserListOperandInfoList = userListIds.Select(userListId => new LogicalUserListOperandInfo { UserList = ResourceNames.UserList(customerId, userListId) }).ToList(); // Creates the UserListLogicalRuleInfo specifying that a user should be added to the new // list if they are present in any of the provided lists. UserListLogicalRuleInfo userListLogicalRuleInfo = new UserListLogicalRuleInfo { // Using ANY means that a user should be added to the combined list if they are // present on any of the lists targeted in the LogicalUserListOperandInfo. Use ALL // to add users present on all of the provided lists or NONE to add users that // aren't present on any of the targeted lists. Operator = UserListLogicalRuleOperatorEnum.Types.UserListLogicalRuleOperator.Any, }; userListLogicalRuleInfo.RuleOperands.Add(logicalUserListOperandInfoList); LogicalUserListInfo logicalUserListInfo = new LogicalUserListInfo(); logicalUserListInfo.Rules.Add(userListLogicalRuleInfo); // Creates the new combination user list. UserList userList = new UserList { Name = "My combination list of other user lists " + $"#{ExampleUtilities.GetRandomString()}", LogicalUserList = logicalUserListInfo }; // Creates the operation. UserListOperation operation = new UserListOperation { Create = userList }; try { // Sends the request to add the user list and prints the response. MutateUserListsResponse response = userListServiceClient.MutateUserLists (customerId.ToString(), new[] { operation }); Console.WriteLine("Created combination user list with resource name: " + $"{response.Results.First().ResourceName}"); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID to which the new user list will be /// added.</param> public void Run(GoogleAdsClient client, long customerId) { // Gets the UserListService. UserListServiceClient userListServiceClient = client.GetService(Services.V4.UserListService); // Creates the user targeting rules for each URL. UserListRuleItemInfo rule1 = BuildVisitedSiteRuleInfo("example.com/section1"); UserListRuleItemInfo rule2 = BuildVisitedSiteRuleInfo("example.com/section2"); // Combine the two rule items into a UserListRuleItemGroupInfo object so Google Ads will // AND their rules together. To instead OR the rules together, each rule should be // placed in its own rule item group. UserListRuleItemGroupInfo userListRuleItemGroupInfo = new UserListRuleItemGroupInfo(); userListRuleItemGroupInfo.RuleItems.Add(rule1); userListRuleItemGroupInfo.RuleItems.Add(rule2); UserListRuleInfo userListRuleInfo = new UserListRuleInfo(); userListRuleInfo.RuleItemGroups.Add(userListRuleItemGroupInfo); // Creates an ExpressionRuleUserListInfo object, or a boolean rule that defines this // user list. The default rule_type for a UserListRuleInfo object is OR of ANDs // (disjunctive normal form). That is, rule items will be ANDed together within rule // item groups and the groups themselves will be ORed together. ExpressionRuleUserListInfo expressionRuleUserListInfo = new ExpressionRuleUserListInfo { Rule = userListRuleInfo }; // Defines a representation of a user list that is generated by a rule. RuleBasedUserListInfo ruleBasedUserListInfo = new RuleBasedUserListInfo { // Optional: To include past users in the user list, set the prepopulation_status to // REQUESTED. PrepopulationStatus = UserListPrepopulationStatus.Requested, ExpressionRuleUserList = expressionRuleUserListInfo }; // Creates a new user list. UserList userList = new UserList { Name = "All visitors to example.com/section1 AND example.com/section2 " + $"#{ExampleUtilities.GetRandomString()}", Description = "Visitors of both example.com/section1 AND example.com/section2", MembershipStatus = UserListMembershipStatus.Open, MembershipLifeSpan = 365L, RuleBasedUserList = ruleBasedUserListInfo }; // Creates the operation. UserListOperation operation = new UserListOperation() { Create = userList }; try { // Adds the user list. MutateUserListsResponse response = userListServiceClient.MutateUserLists (customerId.ToString(), new[] { operation }); // Displays the results. Console.WriteLine("Created new user list with resource name: " + $"'{response.Results.First().ResourceName}'."); } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
/// <summary> /// Creates a user list targeting users that have visited a given url. /// </summary> /// <param name="client">The Google Ads API client.</param> /// <param name="customerId">The Google Ads customer ID for which the call is made.</param> /// <returns>The resource name of the newly created user list.</returns> // [START setup_remarketing] private string CreateUserList(GoogleAdsClient client, long customerId) { // Get the UserListService client. UserListServiceClient userListServiceClient = client.GetService(Services.V10.UserListService); // Create a rule targeting any user that visited a url containing 'example.com'. UserListRuleItemInfo rule = new UserListRuleItemInfo { // Use a built-in parameter to create a domain URL rule. Name = "url__", StringRuleItem = new UserListStringRuleItemInfo { Operator = UserListStringRuleItemOperator.Contains, Value = "example.com" } }; // Specify that the user list targets visitors of a page based on the provided rule. ExpressionRuleUserListInfo expressionRuleUserListInfo = new ExpressionRuleUserListInfo { Rule = new UserListRuleInfo() }; UserListRuleItemGroupInfo userListRuleItemGroupInfo = new UserListRuleItemGroupInfo(); userListRuleItemGroupInfo.RuleItems.Add(rule); expressionRuleUserListInfo.Rule.RuleItemGroups.Add(userListRuleItemGroupInfo); // Define a representation of a user list that is generated by a rule. RuleBasedUserListInfo ruleBasedUserListInfo = new RuleBasedUserListInfo { // Optional: To include past users in the user list, set the prepopulation_status to // REQUESTED. PrepopulationStatus = UserListPrepopulationStatus.Requested, ExpressionRuleUserList = expressionRuleUserListInfo }; // Create the user list. UserList userList = new UserList { Name = $"All visitors to example.com #{ExampleUtilities.GetRandomString()}", Description = "Any visitor to any page of example.com", MembershipStatus = UserListMembershipStatus.Open, MembershipLifeSpan = 365L, RuleBasedUserList = ruleBasedUserListInfo }; // Create the operation. UserListOperation userListOperation = new UserListOperation { Create = userList }; // Add the user list, then print and return the new list's resource name. MutateUserListsResponse mutateUserListsResponse = userListServiceClient .MutateUserLists(customerId.ToString(), new[] { userListOperation }); string userListResourceName = mutateUserListsResponse.Results.First().ResourceName; Console.WriteLine($"Created user list with resource name '{userListResourceName}'."); return(userListResourceName); }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the UserListService. AdwordsUserListService userListService = (AdwordsUserListService)user.GetService(AdWordsService.v201509.AdwordsUserListService); // Create remarketing user list. CrmBasedUserList userList = new CrmBasedUserList() { name = "Customer relationship management list #" + ExampleUtilities.GetRandomString(), description = "A list of customers that originated from email addresses", // CRM Userlist has a maximum membership lifespan of 180 days. See // https://support.google.com/adwords/answer/6276125 for details. membershipLifeSpan = 180L, // You can optionally provide this field to conveniently link an // endpoint for opting-out members from this list. This would link to // a service you created that would appropriately remove members from // the relevant user list. Different user lists may use different // endpoints. Use this field to store the appropriate link. optOutLink = "http://endpoint1.example.com/optout" }; // Create operation. UserListOperation operation = new UserListOperation() { operand = userList, @operator = Operator.ADD }; try { // Add user list. UserListReturnValue result = userListService.mutate(new UserListOperation[] { operation }); Console.WriteLine("Created new user list with name = '{0}' and id = '{1}'.", result.value[0].name, result.value[0].id); // Get user list ID. long userListId = result.value[0].id; // Create operation to add members to the user list based on email // addresses. MutateMembersOperation mutateMembersOperation = new MutateMembersOperation() { operand = new MutateMembersOperand() { userListId = userListId, dataType = MutateMembersOperandDataType.EMAIL_SHA256 }, @operator = Operator.ADD }; // Hash normalized email addresses based on SHA-256 hashing algorithm. String[] emailHashes = new String[EMAILS.Length]; for (int i = 0; i < EMAILS.Length; i++) { String normalizedEmail = ToNormalizedEmail(EMAILS[i]); emailHashes[i] = ToSha256String(hashProvider, normalizedEmail); } // Add email address hashes. mutateMembersOperation.operand.members = emailHashes; // Add members to the user list based on email addresses. MutateMembersReturnValue mutateMembersResult = userListService.mutateMembers(new MutateMembersOperation[] { mutateMembersOperation }); // Display results. // Reminder: it may take several hours for the list to be populated // with members. foreach (UserList userListResult in mutateMembersResult.userLists) { Console.WriteLine("Email addresses were added to user list with name '{0}' and " + "id '{1}'.", userListResult.name, userListResult.id); } } catch (Exception e) { throw new System.ApplicationException("Failed to add user lists (a.k.a. audiences) " + "and upload email addresses.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the UserListService. AdwordsUserListService userListService = (AdwordsUserListService)user.GetService(AdWordsService.v201708.AdwordsUserListService); // First rule item group - users who visited the checkout page and had // more than one item in their shopping cart. StringRuleItem checkoutStringRuleItem = new StringRuleItem(); checkoutStringRuleItem.key = new StringKey(); checkoutStringRuleItem.key.name = "ecomm_pagetype"; checkoutStringRuleItem.op = StringRuleItemStringOperator.EQUALS; checkoutStringRuleItem.value = "checkout"; RuleItem checkoutRuleItem = new RuleItem(); checkoutRuleItem.Item = checkoutStringRuleItem; NumberRuleItem cartSizeNumberRuleItem = new NumberRuleItem(); cartSizeNumberRuleItem.key = new NumberKey(); cartSizeNumberRuleItem.key.name = "cartsize"; cartSizeNumberRuleItem.op = NumberRuleItemNumberOperator.GREATER_THAN; cartSizeNumberRuleItem.value = 1; RuleItem cartSizeRuleItem = new RuleItem(); cartSizeRuleItem.Item = cartSizeNumberRuleItem; // Combine the two rule items into a RuleItemGroup so AdWords will AND // their rules together. RuleItemGroup checkoutMultipleItemGroup = new RuleItemGroup(); checkoutMultipleItemGroup.items = new RuleItem[] { checkoutRuleItem, cartSizeRuleItem }; // Second rule item group - users who check out within the next 3 months. DateRuleItem startDateDateRuleItem = new DateRuleItem(); startDateDateRuleItem.key = new DateKey(); startDateDateRuleItem.key.name = "checkoutdate"; startDateDateRuleItem.op = DateRuleItemDateOperator.AFTER; startDateDateRuleItem.value = DateTime.Now.ToString(DATE_FORMAT_STRING); RuleItem startDateRuleItem = new RuleItem(); startDateRuleItem.Item = startDateDateRuleItem; DateRuleItem endDateDateRuleItem = new DateRuleItem(); endDateDateRuleItem.key = new DateKey(); endDateDateRuleItem.key.name = "checkoutdate"; endDateDateRuleItem.op = DateRuleItemDateOperator.BEFORE; endDateDateRuleItem.value = DateTime.Now.AddMonths(3).ToString(DATE_FORMAT_STRING); RuleItem endDateRuleItem = new RuleItem(); endDateRuleItem.Item = endDateDateRuleItem; // Combine the date rule items into a RuleItemGroup. RuleItemGroup checkedOutNextThreeMonthsItemGroup = new RuleItemGroup(); checkedOutNextThreeMonthsItemGroup.items = new RuleItem[] { startDateRuleItem, endDateRuleItem }; // Combine the rule item groups into a Rule so AdWords knows how to apply the rules. Rule rule = new Rule(); rule.groups = new RuleItemGroup[] { checkoutMultipleItemGroup, checkedOutNextThreeMonthsItemGroup }; // ExpressionRuleUserLists can use either CNF Or DNF For matching. CNF means // 'at least one item in each rule item group must match', and DNF means 'at // least one entire rule item group must match'. // DateSpecificRuleUserList only supports DNF. You can also omit the rule // type altogether To Default To DNF. rule.ruleType = UserListRuleTypeEnumsEnum.DNF; // Third and fourth rule item groups. // Visitors of a page who visited another page. See // https://developers.google.com/adwords/api/docs/reference/latest/AdwordsUserListService.StringKey // for more details. StringKey urlStringKey = new StringKey() { name = "url__" }; StringRuleItem site1StringRuleItem = new StringRuleItem(); site1StringRuleItem.key = urlStringKey; site1StringRuleItem.op = StringRuleItemStringOperator.EQUALS; site1StringRuleItem.value = "example.com/example1"; RuleItem site1RuleItem = new RuleItem(); site1RuleItem.Item = site1StringRuleItem; StringRuleItem site2StringRuleItem = new StringRuleItem(); site2StringRuleItem.key = (urlStringKey); site2StringRuleItem.op = (StringRuleItemStringOperator.EQUALS); site2StringRuleItem.value = ("example.com/example2"); RuleItem site2RuleItem = new RuleItem(); site2RuleItem.Item = (site2StringRuleItem); // Create two RuleItemGroups to show that a visitor browsed two sites. RuleItemGroup site1RuleItemGroup = new RuleItemGroup(); site1RuleItemGroup.items = new RuleItem[] { site1RuleItem }; RuleItemGroup site2RuleItemGroup = new RuleItemGroup(); site2RuleItemGroup.items = new RuleItem[] { site2RuleItem }; // Create two rules to show that a visitor browsed two sites. Rule userVisitedSite1Rule = new Rule(); userVisitedSite1Rule.groups = new RuleItemGroup[] { site1RuleItemGroup }; Rule userVisitedSite2Rule = new Rule(); userVisitedSite2Rule.groups = new RuleItemGroup[] { site2RuleItemGroup }; // Create the user list with no restrictions on site visit date. ExpressionRuleUserList expressionUserList = new ExpressionRuleUserList(); String creationTimeString = new DateTime().ToString("yyyyMMdd_HHmmss"); expressionUserList.name = "Expression based user list created at " + creationTimeString; expressionUserList.description = "Users who checked out in three month window OR visited " + "the checkout page with more than one item in their cart."; expressionUserList.rule = rule; // Optional: Set the prepopulationStatus to REQUESTED to include past users // in the user list. expressionUserList.prepopulationStatus = RuleBasedUserListPrepopulationStatus.REQUESTED; // Create the user list restricted to users who visit your site within // the next six months. DateTime startDate = DateTime.Now; DateTime endDate = startDate.AddMonths(6); DateSpecificRuleUserList dateUserList = new DateSpecificRuleUserList(); dateUserList.name = "Date rule user list created at " + creationTimeString; dateUserList.description = String.Format("Users who visited the site between {0} and " + "{1} and checked out in three month window OR visited the checkout page " + "with more than one item in their cart.", startDate.ToString(DATE_FORMAT_STRING), endDate.ToString(DATE_FORMAT_STRING)); dateUserList.rule = rule; // Set the start and end dates of the user list. dateUserList.startDate = startDate.ToString(DATE_FORMAT_STRING); dateUserList.endDate = endDate.ToString(DATE_FORMAT_STRING); // Create the user list where "Visitors of a page who did visit another page". // To create a user list where "Visitors of a page who did not visit another // page", change the ruleOperator from AND to AND_NOT. CombinedRuleUserList combinedRuleUserList = new CombinedRuleUserList(); combinedRuleUserList.name = "Combined rule user list created at " + creationTimeString; combinedRuleUserList.description = "Users who visited two sites."; combinedRuleUserList.leftOperand = userVisitedSite1Rule; combinedRuleUserList.rightOperand = userVisitedSite2Rule; combinedRuleUserList.ruleOperator = CombinedRuleUserListRuleOperator.AND; // Create operations to add the user lists. List <UserListOperation> operations = new List <UserListOperation>(); foreach (UserList userList in new UserList[] { expressionUserList, dateUserList, combinedRuleUserList }) { UserListOperation operation = new UserListOperation(); operation.operand = userList; operation.@operator = Operator.ADD; operations.Add(operation); } try { // Submit the operations. UserListReturnValue result = userListService.mutate(operations.ToArray()); // Display the results. foreach (UserList userListResult in result.value) { Console.WriteLine("User list added with ID {0}, name '{1}', status '{2}', " + "list type '{3}', accountUserListStatus '{4}', description '{5}'.", userListResult.id, userListResult.name, userListResult.status, userListResult.listType, userListResult.accountUserListStatus, userListResult.description); } } catch (Exception e) { throw new System.ApplicationException("Failed to add rule based user lists.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the UserListService. AdwordsUserListService userListService = (AdwordsUserListService) user.GetService(AdWordsService.v201601.AdwordsUserListService); // First rule item group - users who visited the checkout page and had // more than one item in their shopping cart. StringRuleItem checkoutStringRuleItem = new StringRuleItem(); checkoutStringRuleItem.key = new StringKey(); checkoutStringRuleItem.key.name = "ecomm_pagetype"; checkoutStringRuleItem.op = StringRuleItemStringOperator.EQUALS; checkoutStringRuleItem.value = "checkout"; RuleItem checkoutRuleItem = new RuleItem(); checkoutRuleItem.Item = checkoutStringRuleItem; NumberRuleItem cartSizeNumberRuleItem = new NumberRuleItem(); cartSizeNumberRuleItem.key = new NumberKey(); cartSizeNumberRuleItem.key.name = "cartsize"; cartSizeNumberRuleItem.op = NumberRuleItemNumberOperator.GREATER_THAN; cartSizeNumberRuleItem.value = 1; RuleItem cartSizeRuleItem = new RuleItem(); cartSizeRuleItem.Item = cartSizeNumberRuleItem; // Combine the two rule items into a RuleItemGroup so AdWords will AND // their rules together. RuleItemGroup checkoutMultipleItemGroup = new RuleItemGroup(); checkoutMultipleItemGroup.items = new RuleItem[] { checkoutRuleItem, cartSizeRuleItem }; // Second rule item group - users who check out within the next 3 months. DateRuleItem startDateDateRuleItem = new DateRuleItem(); startDateDateRuleItem.key = new DateKey(); startDateDateRuleItem.key.name = "checkoutdate"; startDateDateRuleItem.op = DateRuleItemDateOperator.AFTER; startDateDateRuleItem.value = DateTime.Now.ToString(DATE_FORMAT_STRING); RuleItem startDateRuleItem = new RuleItem(); startDateRuleItem.Item = startDateDateRuleItem; DateRuleItem endDateDateRuleItem = new DateRuleItem(); endDateDateRuleItem.key = new DateKey(); endDateDateRuleItem.key.name = "checkoutdate"; endDateDateRuleItem.op = DateRuleItemDateOperator.BEFORE; endDateDateRuleItem.value = DateTime.Now.AddMonths(3).ToString(DATE_FORMAT_STRING); RuleItem endDateRuleItem = new RuleItem(); endDateRuleItem.Item = endDateDateRuleItem; // Combine the date rule items into a RuleItemGroup. RuleItemGroup checkedOutNextThreeMonthsItemGroup = new RuleItemGroup(); checkedOutNextThreeMonthsItemGroup.items = new RuleItem[] { startDateRuleItem, endDateRuleItem }; // Combine the rule item groups into a Rule so AdWords will OR the groups // together. Rule rule = new Rule(); rule.groups = new RuleItemGroup[] {checkoutMultipleItemGroup, checkedOutNextThreeMonthsItemGroup}; // Create the user list with no restrictions on site visit date. ExpressionRuleUserList expressionUserList = new ExpressionRuleUserList(); expressionUserList.name = "Expression based user list created at " + DateTime.Now.ToString( "yyyyMMdd_HHmmss"); expressionUserList.description = "Users who checked out in three month window OR visited " + "the checkout page with more than one item in their cart."; expressionUserList.rule = rule; // Create the user list restricted to users who visit your site within // the next six months. DateTime startDate = DateTime.Now; DateTime endDate = startDate.AddMonths(6); DateSpecificRuleUserList dateUserList = new DateSpecificRuleUserList(); dateUserList.name = "Date rule user list created at " + DateTime.Now.ToString("yyyyMMdd_HHmmss"); dateUserList.description = String.Format("Users who visited the site between {0} and " + "{1} and checked out in three month window OR visited the checkout page " + "with more than one item in their cart.", startDate.ToString(DATE_FORMAT_STRING), endDate.ToString(DATE_FORMAT_STRING)); dateUserList.rule = rule; // Set the start and end dates of the user list. dateUserList.startDate = startDate.ToString(DATE_FORMAT_STRING); dateUserList.endDate = endDate.ToString(DATE_FORMAT_STRING); // Create operations to add the user lists. List<UserListOperation> operations = new List<UserListOperation>(); foreach (UserList userList in new UserList[] { expressionUserList, dateUserList }) { UserListOperation operation = new UserListOperation(); operation.operand = userList; operation.@operator = Operator.ADD; operations.Add(operation); } try { // Submit the operations. UserListReturnValue result = userListService.mutate(operations.ToArray()); // Display the results. foreach (UserList userListResult in result.value) { Console.WriteLine("User list added with ID {0}, name '{1}', status '{2}', " + "list type '{3}', accountUserListStatus '{4}', description '{5}'.", userListResult.id, userListResult.name, userListResult.status, userListResult.listType, userListResult.accountUserListStatus, userListResult.description); } } catch (Exception e) { throw new System.ApplicationException("Failed to add rule based user lists.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the UserListService. AdwordsUserListService userListService = (AdwordsUserListService)user.GetService( AdWordsService.v201607.AdwordsUserListService); // Create a user list. CrmBasedUserList userList = new CrmBasedUserList() { name = "Customer relationship management list #" + ExampleUtilities.GetRandomString(), description = "A list of customers that originated from email " + "addresses", // CRM Userlist has a maximum membership lifespan of 180 days. See // https://support.google.com/adwords/answer/6276125 for details. membershipLifeSpan = 180L, }; // Create operation. UserListOperation operation = new UserListOperation() { operand = userList, @operator = Operator.ADD }; try { // Add user list. UserListReturnValue result = userListService.mutate( new UserListOperation[] { operation }); Console.WriteLine("Created new user list with name = '{0}' and id = " + "'{1}'.", result.value[0].name, result.value[0].id); // Get user list ID. long userListId = result.value[0].id; // Create operation to add members to the user list based on email // addresses. MutateMembersOperation mutateMembersOperation = new MutateMembersOperation() { operand = new MutateMembersOperand() { userListId = userListId, dataType = MutateMembersOperandDataType.EMAIL_SHA256 }, @operator = Operator.ADD }; // Hash normalized email addresses based on SHA-256 hashing algorithm. String[] emailHashes = new String[EMAILS.Length]; for (int i = 0; i < EMAILS.Length; i++) { String normalizedEmail = ToNormalizedEmail(EMAILS[i]); emailHashes[i] = ToSha256String(digest, normalizedEmail); } // Add email address hashes. mutateMembersOperation.operand.members = emailHashes; // Add members to the user list based on email addresses. MutateMembersReturnValue mutateMembersResult = userListService.mutateMembers( new MutateMembersOperation[] { mutateMembersOperation }); // Display results. // Reminder: it may take several hours for the list to be populated // with members. foreach (UserList userListResult in mutateMembersResult.userLists) { Console.WriteLine("Email addresses were added to user list with " + "name '{0}' and id '{1}'.", userListResult.name, userListResult.id); } } catch (Exception e) { throw new System.ApplicationException("Failed to add user lists " + "(a.k.a. audiences) and upload email addresses.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the UserListService. AdwordsUserListService userListService = (AdwordsUserListService)user.GetService(AdWordsService.v201506.AdwordsUserListService); // First rule item group - users who visited the checkout page and had // more than one item in their shopping cart. StringRuleItem checkoutStringRuleItem = new StringRuleItem(); checkoutStringRuleItem.key = new StringKey(); checkoutStringRuleItem.key.name = "ecomm_pagetype"; checkoutStringRuleItem.op = StringRuleItemStringOperator.EQUALS; checkoutStringRuleItem.value = "checkout"; RuleItem checkoutRuleItem = new RuleItem(); checkoutRuleItem.Item = checkoutStringRuleItem; NumberRuleItem cartSizeNumberRuleItem = new NumberRuleItem(); cartSizeNumberRuleItem.key = new NumberKey(); cartSizeNumberRuleItem.key.name = "cartsize"; cartSizeNumberRuleItem.op = NumberRuleItemNumberOperator.GREATER_THAN; cartSizeNumberRuleItem.value = 1; RuleItem cartSizeRuleItem = new RuleItem(); cartSizeRuleItem.Item = cartSizeNumberRuleItem; // Combine the two rule items into a RuleItemGroup so AdWords will AND // their rules together. RuleItemGroup checkoutMultipleItemGroup = new RuleItemGroup(); checkoutMultipleItemGroup.items = new RuleItem[] { checkoutRuleItem, cartSizeRuleItem }; // Second rule item group - users who check out within the next 3 months. DateRuleItem startDateDateRuleItem = new DateRuleItem(); startDateDateRuleItem.key = new DateKey(); startDateDateRuleItem.key.name = "checkoutdate"; startDateDateRuleItem.op = DateRuleItemDateOperator.AFTER; startDateDateRuleItem.value = DateTime.Now.ToString(DATE_FORMAT_STRING); RuleItem startDateRuleItem = new RuleItem(); startDateRuleItem.Item = startDateDateRuleItem; DateRuleItem endDateDateRuleItem = new DateRuleItem(); endDateDateRuleItem.key = new DateKey(); endDateDateRuleItem.key.name = "checkoutdate"; endDateDateRuleItem.op = DateRuleItemDateOperator.BEFORE; endDateDateRuleItem.value = DateTime.Now.AddMonths(3).ToString(DATE_FORMAT_STRING); RuleItem endDateRuleItem = new RuleItem(); endDateRuleItem.Item = endDateDateRuleItem; // Combine the date rule items into a RuleItemGroup. RuleItemGroup checkedOutNextThreeMonthsItemGroup = new RuleItemGroup(); checkedOutNextThreeMonthsItemGroup.items = new RuleItem[] { startDateRuleItem, endDateRuleItem }; // Combine the rule item groups into a Rule so AdWords will OR the groups // together. Rule rule = new Rule(); rule.groups = new RuleItemGroup[] { checkoutMultipleItemGroup, checkedOutNextThreeMonthsItemGroup }; // Create the user list with no restrictions on site visit date. ExpressionRuleUserList expressionUserList = new ExpressionRuleUserList(); expressionUserList.name = "Expression based user list created at " + DateTime.Now.ToString( "yyyyMMdd_HHmmss"); expressionUserList.description = "Users who checked out in three month window OR visited " + "the checkout page with more than one item in their cart."; expressionUserList.rule = rule; // Create the user list restricted to users who visit your site within // the next six months. DateTime startDate = DateTime.Now; DateTime endDate = startDate.AddMonths(6); DateSpecificRuleUserList dateUserList = new DateSpecificRuleUserList(); dateUserList.name = "Date rule user list created at " + DateTime.Now.ToString("yyyyMMdd_HHmmss"); dateUserList.description = String.Format("Users who visited the site between {0} and " + "{1} and checked out in three month window OR visited the checkout page " + "with more than one item in their cart.", startDate.ToString(DATE_FORMAT_STRING), endDate.ToString(DATE_FORMAT_STRING)); dateUserList.rule = rule; // Set the start and end dates of the user list. dateUserList.startDate = startDate.ToString(DATE_FORMAT_STRING); dateUserList.endDate = endDate.ToString(DATE_FORMAT_STRING); // Create operations to add the user lists. List <UserListOperation> operations = new List <UserListOperation>(); foreach (UserList userList in new UserList[] { expressionUserList, dateUserList }) { UserListOperation operation = new UserListOperation(); operation.operand = userList; operation.@operator = Operator.ADD; operations.Add(operation); } try { // Submit the operations. UserListReturnValue result = userListService.mutate(operations.ToArray()); // Display the results. foreach (UserList userListResult in result.value) { Console.WriteLine("User list added with ID {0}, name '{1}', status '{2}', " + "list type '{3}', accountUserListStatus '{4}', description '{5}'.", userListResult.id, userListResult.name, userListResult.status, userListResult.listType, userListResult.accountUserListStatus, userListResult.description); } } catch (Exception ex) { throw new System.ApplicationException("Failed to add rule based user lists.", ex); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { using (AdwordsUserListService userListService = (AdwordsUserListService)user.GetService( AdWordsService.v201710.AdwordsUserListService)) using (ConversionTrackerService conversionTrackerService = (ConversionTrackerService)user.GetService(AdWordsService.v201710. ConversionTrackerService)) { BasicUserList userList = new BasicUserList(); userList.name = "Mars cruise customers #" + ExampleUtilities.GetRandomString(); userList.description = "A list of mars cruise customers in the last year."; userList.status = UserListMembershipStatus.OPEN; userList.membershipLifeSpan = 365; UserListConversionType conversionType = new UserListConversionType(); conversionType.name = userList.name; userList.conversionTypes = new UserListConversionType[] { conversionType }; // Optional: Set the user list status. userList.status = UserListMembershipStatus.OPEN; // Create the operation. UserListOperation operation = new UserListOperation(); operation.operand = userList; operation.@operator = Operator.ADD; try { // Add the user list. UserListReturnValue retval = userListService.mutate( new UserListOperation[] { operation }); UserList[] userLists = null; if (retval != null && retval.value != null) { userLists = retval.value; // Get all conversion snippets List <string> conversionIds = new List <string>(); foreach (BasicUserList newUserList in userLists) { if (newUserList.conversionTypes != null) { foreach (UserListConversionType newConversionType in newUserList.conversionTypes) { conversionIds.Add(newConversionType.id.ToString()); } } } Dictionary <long, ConversionTracker> conversionsMap = new Dictionary <long, ConversionTracker>(); if (conversionIds.Count > 0) { // Create the selector. Selector selector = new Selector() { fields = new string[] { ConversionTracker.Fields.Id }, predicates = new Predicate[] { Predicate.In(ConversionTracker.Fields.Id, conversionIds) } }; // Get all conversion trackers. ConversionTrackerPage page = conversionTrackerService.get(selector); if (page != null && page.entries != null) { foreach (ConversionTracker tracker in page.entries) { conversionsMap[tracker.id] = tracker; } } } // Display the results. foreach (BasicUserList newUserList in userLists) { Console.WriteLine("User list with name '{0}' and id '{1}' was added.", newUserList.name, newUserList.id); // Display user list associated conversion code snippets. if (newUserList.conversionTypes != null) { foreach (UserListConversionType userListConversionType in newUserList.conversionTypes) { if (conversionsMap.ContainsKey(userListConversionType.id)) { AdWordsConversionTracker conversionTracker = (AdWordsConversionTracker)conversionsMap[userListConversionType.id]; Console.WriteLine("Conversion type code snippet associated to the " + "list:\n{0}\n", conversionTracker.snippet); } else { throw new Exception("Failed to associate conversion type code snippet."); } } } } } else { Console.WriteLine("No user lists (a.k.a. audiences) were added."); } } catch (Exception e) { throw new System.ApplicationException("Failed to add user lists (a.k.a. audiences).", e); } } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the UserListService. AdwordsUserListService userListService = (AdwordsUserListService) user.GetService(AdWordsService.v201509.AdwordsUserListService); // Create remarketing user list. CrmBasedUserList userList = new CrmBasedUserList() { name = "Customer relationship management list #" + ExampleUtilities.GetRandomString(), description = "A list of customers that originated from email addresses", // CRM Userlist has a maximum membership lifespan of 180 days. See // https://support.google.com/adwords/answer/6276125 for details. membershipLifeSpan = 180L, // This field is optional. It links to a service you created that allows members // of this list to remove themselves. optOutLink = "http://endpoint1.example.com/optout" }; // Create operation. UserListOperation operation = new UserListOperation() { operand = userList, @operator = Operator.ADD }; try { // Add user list. UserListReturnValue result = userListService.mutate(new UserListOperation[] { operation }); Console.WriteLine("Created new user list with name = '{0}' and id = '{1}'.", result.value[0].name, result.value[0].id); // Get user list ID. long userListId = result.value[0].id; // Create operation to add members to the user list based on email // addresses. MutateMembersOperation mutateMembersOperation = new MutateMembersOperation() { operand = new MutateMembersOperand() { userListId = userListId, dataType = MutateMembersOperandDataType.EMAIL_SHA256 }, @operator = Operator.ADD }; // Hash normalized email addresses based on SHA-256 hashing algorithm. String[] emailHashes = new String[EMAILS.Length]; for (int i = 0; i < EMAILS.Length; i++) { String normalizedEmail = ToNormalizedEmail(EMAILS[i]); emailHashes[i] = ToSha256String(hashProvider, normalizedEmail); } // Add email address hashes. mutateMembersOperation.operand.members = emailHashes; // Add members to the user list based on email addresses. MutateMembersReturnValue mutateMembersResult = userListService.mutateMembers(new MutateMembersOperation[] { mutateMembersOperation }); // Display results. // Reminder: it may take several hours for the list to be populated // with members. foreach (UserList userListResult in mutateMembersResult.userLists) { Console.WriteLine("Email addresses were added to user list with name '{0}' and " + "id '{1}'.", userListResult.name, userListResult.id); } } catch (Exception e) { throw new System.ApplicationException("Failed to add user lists (a.k.a. audiences) " + "and upload email addresses.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the UserListService. AdwordsUserListService userListService = (AdwordsUserListService)user.GetService( AdWordsService.v201710.AdwordsUserListService); // Create a user list. CrmBasedUserList userList = new CrmBasedUserList() { name = "Customer relationship management list #" + ExampleUtilities.GetRandomString(), description = "A list of customers that originated from email " + "addresses", // CRM Userlist has a maximum membership lifespan of 180 days. See // https://support.google.com/adwords/answer/6276125 for details. membershipLifeSpan = 180L, }; // Create operation. UserListOperation operation = new UserListOperation() { operand = userList, @operator = Operator.ADD }; try { // Add user list. UserListReturnValue result = userListService.mutate( new UserListOperation[] { operation }); Console.WriteLine("Created new user list with name = '{0}' and id = " + "'{1}'.", result.value[0].name, result.value[0].id); // Get user list ID. long userListId = result.value[0].id; // Prepare the emails for upload. List <Member> memberList = new List <Member>(); // Hash normalized email addresses based on SHA-256 hashing algorithm. String[] emailHashes = new String[EMAILS.Length]; for (int i = 0; i < EMAILS.Length; i++) { Member member = new Member(); member.hashedEmail = ToSha256String(digest, ToNormalizedEmail(EMAILS[i])); // Adding address info is currently available on a whitelist-only basis. This // code demonstrates how to do it, but if you are not on the whitelist, you // will need to remove this block for the example to run. AddressInfo addressInfo = new AddressInfo(); addressInfo.hashedFirstName = ToSha256String(digest, FIRST_NAME); addressInfo.hashedLastName = ToSha256String(digest, LAST_NAME); addressInfo.zipCode = ZIP_CODE; addressInfo.countryCode = COUNTRY_CODE; member.addressInfo = addressInfo; memberList.Add(member); } ; // Create operation to add members to the user list based on email // addresses. MutateMembersOperation mutateMembersOperation = new MutateMembersOperation() { operand = new MutateMembersOperand() { userListId = userListId, membersList = memberList.ToArray() }, @operator = Operator.ADD }; // Add members to the user list based on email addresses. MutateMembersReturnValue mutateMembersResult = userListService.mutateMembers( new MutateMembersOperation[] { mutateMembersOperation }); // Display results. // Reminder: it may take several hours for the list to be populated // with members. foreach (UserList userListResult in mutateMembersResult.userLists) { Console.WriteLine("Email addresses were added to user list with " + "name '{0}' and id '{1}'.", userListResult.name, userListResult.id); } userListService.Close(); } catch (Exception e) { throw new System.ApplicationException("Failed to add user lists " + "(a.k.a. audiences) and upload email addresses.", e); } }
/// <summary> /// Runs the code example. /// </summary> /// <param name="user">The AdWords user.</param> public void Run(AdWordsUser user) { // Get the UserListService. AdwordsUserListService userListService = (AdwordsUserListService) user.GetService(AdWordsService.v201509.AdwordsUserListService); // Get the ConversionTrackerService. ConversionTrackerService conversionTrackerService = (ConversionTrackerService)user.GetService(AdWordsService.v201509. ConversionTrackerService); BasicUserList userList = new BasicUserList(); userList.name = "Mars cruise customers #" + ExampleUtilities.GetRandomString(); userList.description = "A list of mars cruise customers in the last year."; userList.status = UserListMembershipStatus.OPEN; userList.membershipLifeSpan = 365; UserListConversionType conversionType = new UserListConversionType(); conversionType.name = userList.name; userList.conversionTypes = new UserListConversionType[] {conversionType}; // Optional: Set the user list status. userList.status = UserListMembershipStatus.OPEN; // Create the operation. UserListOperation operation = new UserListOperation(); operation.operand = userList; operation.@operator = Operator.ADD; try { // Add the user list. UserListReturnValue retval = userListService.mutate(new UserListOperation[] {operation}); UserList[] userLists = null; if (retval != null && retval.value != null) { userLists = retval.value; // Get all conversion snippets List<string> conversionIds = new List<string>(); foreach (BasicUserList newUserList in userLists) { if (newUserList.conversionTypes != null) { foreach (UserListConversionType newConversionType in newUserList.conversionTypes) { conversionIds.Add(newConversionType.id.ToString()); } } } Dictionary<long, ConversionTracker> conversionsMap = new Dictionary<long, ConversionTracker>(); if (conversionIds.Count > 0) { // Create the selector. Selector selector = new Selector() { fields = new string[] { ConversionTracker.Fields.Id }, predicates = new Predicate[] { Predicate.In(ConversionTracker.Fields.Id, conversionIds) } }; // Get all conversion trackers. ConversionTrackerPage page = conversionTrackerService.get(selector); if (page != null && page.entries != null) { foreach (ConversionTracker tracker in page.entries) { conversionsMap[tracker.id] = tracker; } } } // Display the results. foreach (BasicUserList newUserList in userLists) { Console.WriteLine("User list with name '{0}' and id '{1}' was added.", newUserList.name, newUserList.id); // Display user list associated conversion code snippets. if (newUserList.conversionTypes != null) { foreach (UserListConversionType userListConversionType in newUserList.conversionTypes) { if (conversionsMap.ContainsKey(userListConversionType.id)) { AdWordsConversionTracker conversionTracker = (AdWordsConversionTracker) conversionsMap[userListConversionType.id]; Console.WriteLine("Conversion type code snippet associated to the list:\n{0}\n", conversionTracker.snippet); } else { throw new Exception("Failed to associate conversion type code snippet."); } } } } } else { Console.WriteLine("No user lists (a.k.a. audiences) were added."); } } catch (Exception e) { throw new System.ApplicationException("Failed to add user lists (a.k.a. audiences).", e); } }