/// <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)
        {
            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="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.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);
            }
        }
Esempio n. 5
0
        /// <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);
            }
        }