/// <summary>
        /// Adds operations to a job for a set of sample transactions.
        /// </summary>
        /// <param name="offlineUserDataJobServiceClient">The offline user data job service
        ///     client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="offlineUserDataJobResourceName">The resource name of the job to which to
        ///     add transactions.</param>
        /// <param name="conversionActionId">The ID of a store sales conversion action.</param>
        private void AddTransactionsToOfflineUserDataJob(
            OfflineUserDataJobServiceClient offlineUserDataJobServiceClient, long customerId,
            string offlineUserDataJobResourceName, long conversionActionId)
        {
            // Constructions an operation for each transaction.
            List <OfflineUserDataJobOperation> userDataJobOperations =
                BuildOfflineUserDataJobOperations(customerId, conversionActionId);

            // Issues a request with partial failure enabled to add the operations to the offline
            // user data job.
            AddOfflineUserDataJobOperationsResponse response = offlineUserDataJobServiceClient
                                                               .AddOfflineUserDataJobOperations(new AddOfflineUserDataJobOperationsRequest()
            {
                EnablePartialFailure = true,
                ResourceName         = offlineUserDataJobResourceName,
                Operations           = { userDataJobOperations }
            });

            // Prints the status message if any partial failure error is returned.
            // NOTE: The details of each partial failure error are not printed here, you can refer
            // to the example HandlePartialFailure.cs to learn more.
            if (response.PartialFailureError != null)
            {
                Console.WriteLine($"Encountered {response.PartialFailureError.Details.Count} " +
                                  $"partial failure errors while adding {userDataJobOperations.Count} " +
                                  "operations to the offline user data job: " +
                                  $"'{response.PartialFailureError.Message}'. Only the successfully added " +
                                  "operations will be executed when the job runs.");
            }
            else
            {
                Console.WriteLine($"Successfully added {userDataJobOperations.Count} operations " +
                                  "to the offline user data job.");
            }
        }
        /// <summary>
        /// Adds operations to a job for a set of sample transactions.
        /// </summary>
        /// <param name="offlineUserDataJobServiceClient">The offline user data job service
        /// client.</param>
        /// <param name="customerId">The Google Ads customer ID for which the call is made.</param>
        /// <param name="offlineUserDataJobResourceName">The resource name of the job to which to
        /// add transactions.</param>
        /// <param name="conversionActionId">The ID of a store sales conversion action.</param>
        /// <param name="customKey">The custom key, or null if not uploading data with custom key
        /// and value.</param>
        /// <param name="itemId">A unique identifier of a product, or null if not uploading with
        /// item attributes.</param>
        /// <param name="merchantCenterAccountId">A Merchant Center Account ID, or null if not
        /// uploading with item attributes.</param>
        /// <param name="countryCode">A two-letter country code, or null if not uploading with
        /// item attributes.</param>
        /// <param name="languageCode">A two-letter language code, or null if not uploading with
        /// item attributes.</param>
        /// <param name="quantity">The number of items sold, or null if not uploading with
        /// item attributes.</param>
        private void AddTransactionsToOfflineUserDataJob(
            OfflineUserDataJobServiceClient offlineUserDataJobServiceClient, long customerId,
            string offlineUserDataJobResourceName, long conversionActionId, string customKey,
            string itemId, long?merchantCenterAccountId, string countryCode, string languageCode,
            long quantity)
        {
            // Constructions an operation for each transaction.
            List <OfflineUserDataJobOperation> userDataJobOperations =
                BuildOfflineUserDataJobOperations(customerId, conversionActionId, customKey, itemId,
                                                  merchantCenterAccountId, countryCode, languageCode, quantity);

            // [START enable_warnings_1]
            // Constructs a request with partial failure enabled to add the operations to the
            // offline user data job, and enable_warnings set to true to retrieve warnings.
            AddOfflineUserDataJobOperationsRequest request =
                new AddOfflineUserDataJobOperationsRequest()
            {
                EnablePartialFailure = true,
                ResourceName         = offlineUserDataJobResourceName,
                Operations           = { userDataJobOperations },
                EnableWarnings       = true,
            };

            AddOfflineUserDataJobOperationsResponse response = offlineUserDataJobServiceClient
                                                               .AddOfflineUserDataJobOperations(request);

            // [END enable_warnings_1]

            // Prints the status message if any partial failure error is returned.
            // NOTE: The details of each partial failure error are not printed here, you can refer
            // to the example HandlePartialFailure.cs to learn more.
            if (response.PartialFailureError != null)
            {
                Console.WriteLine($"Encountered {response.PartialFailureError.Details.Count} " +
                                  $"partial failure errors while adding {userDataJobOperations.Count} " +
                                  "operations to the offline user data job: " +
                                  $"'{response.PartialFailureError.Message}'. Only the successfully added " +
                                  "operations will be executed when the job runs.");
            }
            else
            {
                Console.WriteLine($"Successfully added {userDataJobOperations.Count} operations " +
                                  "to the offline user data job.");
            }

            // [START enable_warnings_2]
            // Prints the number of warnings if any warnings are returned. You can access
            // details of each warning using the same approach you'd use for partial failure
            // errors.
            if (request.EnableWarnings && response.Warnings != null)
            {
                // Extracts the warnings from the response.
                GoogleAdsFailure warnings = response.Warnings;
                Console.WriteLine($"{warnings.Errors.Count} warning(s) occurred");
            }
            // [END enable_warnings_2]
        }
 /// <summary>Snippet for AddOfflineUserDataJobOperations</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void AddOfflineUserDataJobOperations()
 {
     // Create client
     OfflineUserDataJobServiceClient offlineUserDataJobServiceClient = OfflineUserDataJobServiceClient.Create();
     // Initialize request argument(s)
     string resourceName = "customers/[CUSTOMER]/offlineUserDataJobs/[OFFLINE_USER_DATA_JOB]";
     IEnumerable <OfflineUserDataJobOperation> operations = new OfflineUserDataJobOperation[]
     {
         new OfflineUserDataJobOperation(),
     };
     // Make the request
     AddOfflineUserDataJobOperationsResponse response = offlineUserDataJobServiceClient.AddOfflineUserDataJobOperations(resourceName, operations);
 }
 /// <summary>Snippet for AddOfflineUserDataJobOperations</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void AddOfflineUserDataJobOperationsResourceNames()
 {
     // Create client
     OfflineUserDataJobServiceClient offlineUserDataJobServiceClient = OfflineUserDataJobServiceClient.Create();
     // Initialize request argument(s)
     OfflineUserDataJobName resourceName = OfflineUserDataJobName.FromCustomerOfflineUserDataUpdate("[CUSTOMER_ID]", "[OFFLINE_USER_DATA_UPDATE_ID]");
     IEnumerable <OfflineUserDataJobOperation> operations = new OfflineUserDataJobOperation[]
     {
         new OfflineUserDataJobOperation(),
     };
     // Make the request
     AddOfflineUserDataJobOperationsResponse response = offlineUserDataJobServiceClient.AddOfflineUserDataJobOperations(resourceName, operations);
 }
 /// <summary>Snippet for AddOfflineUserDataJobOperations</summary>
 public void AddOfflineUserDataJobOperationsResourceNames()
 {
     // Snippet: AddOfflineUserDataJobOperations(OfflineUserDataJobName, IEnumerable<OfflineUserDataJobOperation>, CallSettings)
     // Create client
     OfflineUserDataJobServiceClient offlineUserDataJobServiceClient = OfflineUserDataJobServiceClient.Create();
     // Initialize request argument(s)
     OfflineUserDataJobName resourceName = OfflineUserDataJobName.FromCustomerOfflineUserDataJob("[CUSTOMER]", "[OFFLINE_USER_DATA_JOB]");
     IEnumerable <OfflineUserDataJobOperation> operations = new OfflineUserDataJobOperation[]
     {
         new OfflineUserDataJobOperation(),
     };
     // Make the request
     AddOfflineUserDataJobOperationsResponse response = offlineUserDataJobServiceClient.AddOfflineUserDataJobOperations(resourceName, operations);
     // End snippet
 }
 /// <summary>Snippet for AddOfflineUserDataJobOperations</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void AddOfflineUserDataJobOperationsRequestObject()
 {
     // Create client
     OfflineUserDataJobServiceClient offlineUserDataJobServiceClient = OfflineUserDataJobServiceClient.Create();
     // Initialize request argument(s)
     AddOfflineUserDataJobOperationsRequest request = new AddOfflineUserDataJobOperationsRequest
     {
         ResourceNameAsOfflineUserDataJobName = OfflineUserDataJobName.FromCustomerOfflineUserDataJob("[CUSTOMER]", "[OFFLINE_USER_DATA_JOB]"),
         EnablePartialFailure = false,
         Operations           =
         {
             new OfflineUserDataJobOperation(),
         },
     };
     // Make the request
     AddOfflineUserDataJobOperationsResponse response = offlineUserDataJobServiceClient.AddOfflineUserDataJobOperations(request);
 }
Exemplo n.º 7
0
 /// <summary>Snippet for AddOfflineUserDataJobOperations</summary>
 public void AddOfflineUserDataJobOperationsRequestObject()
 {
     // Snippet: AddOfflineUserDataJobOperations(AddOfflineUserDataJobOperationsRequest, CallSettings)
     // Create client
     OfflineUserDataJobServiceClient offlineUserDataJobServiceClient = OfflineUserDataJobServiceClient.Create();
     // Initialize request argument(s)
     AddOfflineUserDataJobOperationsRequest request = new AddOfflineUserDataJobOperationsRequest
     {
         ResourceNameAsOfflineUserDataJobName = OfflineUserDataJobName.FromCustomerOfflineUserDataUpdate("[CUSTOMER_ID]", "[OFFLINE_USER_DATA_UPDATE_ID]"),
         Operations =
         {
             new OfflineUserDataJobOperation(),
         },
         EnablePartialFailure = false,
     };
     // Make the request
     AddOfflineUserDataJobOperationsResponse response = offlineUserDataJobServiceClient.AddOfflineUserDataJobOperations(request);
     // End snippet
 }
Exemplo n.º 8
0
        /// <summary>
        /// Creates and executes an asynchronous job to add users to the Customer Match user list.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which calls are made.
        /// </param>
        /// <param name="userListResourceName">the resource name of the Customer Match user list
        /// to add users to</param>
        private static void AddUsersToCustomerMatchUserList(GoogleAdsClient client,
                                                            long customerId, string userListResourceName)
        {
            // Get the OfflineUserDataJobService.
            OfflineUserDataJobServiceClient service = client.GetService(
                Services.V4.OfflineUserDataJobService);

            // Creates a new offline user data job.
            OfflineUserDataJob offlineUserDataJob = new OfflineUserDataJob()
            {
                Type = OfflineUserDataJobType.CustomerMatchUserList,
                CustomerMatchUserListMetadata = new CustomerMatchUserListMetadata()
                {
                    UserList = userListResourceName
                }
            };

            // Issues a request to create the offline user data job.
            CreateOfflineUserDataJobResponse response1 = service.CreateOfflineUserDataJob(
                customerId.ToString(), offlineUserDataJob);
            string offlineUserDataJobResourceName = response1.ResourceName;

            Console.WriteLine($"Created an offline user data job with resource name: " +
                              $"'{offlineUserDataJobResourceName}'.");

            AddOfflineUserDataJobOperationsRequest request =
                new AddOfflineUserDataJobOperationsRequest()
            {
                ResourceName         = offlineUserDataJobResourceName,
                Operations           = { BuildOfflineUserDataJobOperations() },
                EnablePartialFailure = true,
            };
            // Issues a request to add the operations to the offline user data job.
            AddOfflineUserDataJobOperationsResponse response2 =
                service.AddOfflineUserDataJobOperations(request);

            // Prints the status message if any partial failure error is returned.
            // Note: The details of each partial failure error are not printed here,
            // you can refer to the example HandlePartialFailure.cs to learn more.
            if (response2.PartialFailureError == null)
            {
                // Extracts the partial failure from the response status.
                GoogleAdsFailure partialFailure = response2.PartialFailure;
                Console.WriteLine($"{partialFailure.Errors.Count} partial failure error(s) " +
                                  $"occurred");
            }
            Console.WriteLine("The operations are added to the offline user data job.");

            // Issues an asynchronous request to run the offline user data job for executing
            // all added operations.
            Operation <Empty, Empty> operationResponse =
                service.RunOfflineUserDataJob(offlineUserDataJobResourceName);

            Console.WriteLine("Asynchronous request to execute the added operations started.");;
            Console.WriteLine("Waiting until operation completes.");

            // PollUntilCompleted() implements a default back-off policy for retrying. You can
            // tweak the polling behaviour using a PollSettings as illustrated below.
            operationResponse.PollUntilCompleted(new PollSettings(
                                                     Expiration.FromTimeout(TimeSpan.FromSeconds(MAX_TOTAL_POLL_INTERVAL_SECONDS)),
                                                     TimeSpan.FromSeconds(POLL_FREQUENCY_SECONDS)));

            if (operationResponse.IsCompleted)
            {
                Console.WriteLine($"Offline user data job with resource name " +
                                  $"'{offlineUserDataJobResourceName}' has finished.");
            }
            else
            {
                Console.WriteLine($"Offline user data job with resource name" +
                                  $" '{offlineUserDataJobResourceName}' is pending after " +
                                  $"{MAX_TOTAL_POLL_INTERVAL_SECONDS} seconds.");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates and executes an asynchronous job to add users to the Customer Match user list.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which calls are made.
        /// </param>
        /// <param name="userListResourceName">the resource name of the Customer Match user list
        /// to add users to</param>
        /// <remarks>Resource of the offline user data job.</remarks>
        // [START add_customer_match_user_list]
        private static string AddUsersToCustomerMatchUserList(GoogleAdsClient client,
                                                              long customerId, string userListResourceName)
        {
            // Get the OfflineUserDataJobService.
            OfflineUserDataJobServiceClient service = client.GetService(
                Services.V10.OfflineUserDataJobService);

            // Creates a new offline user data job.
            OfflineUserDataJob offlineUserDataJob = new OfflineUserDataJob()
            {
                Type = OfflineUserDataJobType.CustomerMatchUserList,
                CustomerMatchUserListMetadata = new CustomerMatchUserListMetadata()
                {
                    UserList = userListResourceName
                }
            };

            // Issues a request to create the offline user data job.
            CreateOfflineUserDataJobResponse response1 = service.CreateOfflineUserDataJob(
                customerId.ToString(), offlineUserDataJob);
            string offlineUserDataJobResourceName = response1.ResourceName;

            Console.WriteLine($"Created an offline user data job with resource name: " +
                              $"'{offlineUserDataJobResourceName}'.");

            AddOfflineUserDataJobOperationsRequest request =
                new AddOfflineUserDataJobOperationsRequest()
            {
                ResourceName         = offlineUserDataJobResourceName,
                Operations           = { BuildOfflineUserDataJobOperations() },
                EnablePartialFailure = true,
            };
            // Issues a request to add the operations to the offline user data job.
            AddOfflineUserDataJobOperationsResponse response2 =
                service.AddOfflineUserDataJobOperations(request);

            // Prints the status message if any partial failure error is returned.
            // Note: The details of each partial failure error are not printed here,
            // you can refer to the example HandlePartialFailure.cs to learn more.
            if (response2.PartialFailureError != null)
            {
                // Extracts the partial failure from the response status.
                GoogleAdsFailure partialFailure = response2.PartialFailure;
                Console.WriteLine($"{partialFailure.Errors.Count} partial failure error(s) " +
                                  $"occurred");
            }
            Console.WriteLine("The operations are added to the offline user data job.");

            // Issues an asynchronous request to run the offline user data job for executing
            // all added operations.
            Operation <Empty, OfflineUserDataJobMetadata> operationResponse =
                service.RunOfflineUserDataJob(offlineUserDataJobResourceName);

            Console.WriteLine("Asynchronous request to execute the added operations started.");

            // Since offline user data jobs may take 24 hours or more to complete, it may not be
            // practical to do operationResponse.PollUntilCompleted() to wait for the results.
            // Instead, we save the offlineUserDataJobResourceName and use GoogleAdsService.Search
            // to check for the job status periodically.
            // In case you wish to follow the PollUntilCompleted or PollOnce approach, make sure
            // you keep both operationResponse and service variables alive until the polling
            // completes.

            return(offlineUserDataJobResourceName);
        }