public async stt::Task UploadClickConversionsRequestObjectAsync()
        {
            moq::Mock <ConversionUploadService.ConversionUploadServiceClient> mockGrpcClient = new moq::Mock <ConversionUploadService.ConversionUploadServiceClient>(moq::MockBehavior.Strict);
            UploadClickConversionsRequest request = new UploadClickConversionsRequest
            {
                CustomerId  = "customer_id3b3724cb",
                Conversions =
                {
                    new ClickConversion(),
                },
                PartialFailure = false,
                ValidateOnly   = true,
            };
            UploadClickConversionsResponse expectedResponse = new UploadClickConversionsResponse
            {
                PartialFailureError = new gr::Status(),
                Results             =
                {
                    new ClickConversionResult(),
                },
            };

            mockGrpcClient.Setup(x => x.UploadClickConversionsAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <UploadClickConversionsResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            ConversionUploadServiceClient  client = new ConversionUploadServiceClientImpl(mockGrpcClient.Object, null);
            UploadClickConversionsResponse responseCallSettings = await client.UploadClickConversionsAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            UploadClickConversionsResponse responseCancellationToken = await client.UploadClickConversionsAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
        public void UploadClickConversions()
        {
            moq::Mock <ConversionUploadService.ConversionUploadServiceClient> mockGrpcClient = new moq::Mock <ConversionUploadService.ConversionUploadServiceClient>(moq::MockBehavior.Strict);
            UploadClickConversionsRequest request = new UploadClickConversionsRequest
            {
                CustomerId  = "customer_id3b3724cb",
                Conversions =
                {
                    new ClickConversion(),
                },
                PartialFailure = false,
            };
            UploadClickConversionsResponse expectedResponse = new UploadClickConversionsResponse
            {
                PartialFailureError = new gr::Status(),
                Results             =
                {
                    new ClickConversionResult(),
                },
            };

            mockGrpcClient.Setup(x => x.UploadClickConversions(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            ConversionUploadServiceClient  client   = new ConversionUploadServiceClientImpl(mockGrpcClient.Object, null);
            UploadClickConversionsResponse response = client.UploadClickConversions(request.CustomerId, request.Conversions, request.PartialFailure);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Пример #3
0
 /// <summary>Snippet for UploadClickConversions</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void UploadClickConversions()
 {
     // Create client
     ConversionUploadServiceClient conversionUploadServiceClient = ConversionUploadServiceClient.Create();
     // Initialize request argument(s)
     string customerId = "";
     IEnumerable <ClickConversion> conversions = new ClickConversion[]
     {
         new ClickConversion(),
     };
     bool partialFailure = false;
     // Make the request
     UploadClickConversionsResponse response = conversionUploadServiceClient.UploadClickConversions(customerId, conversions, partialFailure);
 }
Пример #4
0
        /// <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>
        /// <param name="conversionActionId">The conversion action ID.</param>
        /// <param name="conversionTime">The conversion time.</param>
        /// <param name="gclid">The click ID.</param>
        /// <param name="conversionValue">The convsersion value.</param>
        public void Run(GoogleAdsClient client, long customerId, long conversionActionId,
                        string gclid, string conversionTime, double conversionValue)
        {
            // Get the ConversionActionService.
            ConversionUploadServiceClient conversionUploadService =
                client.GetService(Services.V5.ConversionUploadService);

            // Creates a click conversion by specifying currency as USD.
            ClickConversion clickConversion = new ClickConversion()
            {
                ConversionAction   = ResourceNames.ConversionAction(customerId, conversionActionId),
                Gclid              = gclid,
                ConversionValue    = conversionValue,
                ConversionDateTime = conversionTime,
                CurrencyCode       = "USD"
            };

            try
            {
                // Issues a request to upload the click conversion.
                UploadClickConversionsResponse response =
                    conversionUploadService.UploadClickConversions(
                        new UploadClickConversionsRequest()
                {
                    CustomerId     = customerId.ToString(),
                    Conversions    = { clickConversion },
                    PartialFailure = true,
                    ValidateOnly   = false
                });

                // Prints the result.
                ClickConversionResult uploadedClickConversion = response.Results[0];
                Console.WriteLine($"Uploaded conversion that occurred at " +
                                  $"'{uploadedClickConversion.ConversionDateTime}' from Google " +
                                  $"Click ID '{uploadedClickConversion.Gclid}' to " +
                                  $"'{uploadedClickConversion.ConversionAction}'.");
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
        public async Task UploadClickConversionsAsync3()
        {
            Mock <ConversionUploadService.ConversionUploadServiceClient> mockGrpcClient = new Mock <ConversionUploadService.ConversionUploadServiceClient>(MockBehavior.Strict);
            UploadClickConversionsRequest request = new UploadClickConversionsRequest
            {
                CustomerId  = "customerId-1772061412",
                Conversions = { },
            };
            UploadClickConversionsResponse expectedResponse = new UploadClickConversionsResponse();

            mockGrpcClient.Setup(x => x.UploadClickConversionsAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <UploadClickConversionsResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            ConversionUploadServiceClient  client   = new ConversionUploadServiceClientImpl(mockGrpcClient.Object, null);
            UploadClickConversionsResponse response = await client.UploadClickConversionsAsync(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        public void UploadClickConversions3()
        {
            Mock <ConversionUploadService.ConversionUploadServiceClient> mockGrpcClient = new Mock <ConversionUploadService.ConversionUploadServiceClient>(MockBehavior.Strict);
            UploadClickConversionsRequest request = new UploadClickConversionsRequest
            {
                CustomerId  = "customerId-1772061412",
                Conversions = { },
            };
            UploadClickConversionsResponse expectedResponse = new UploadClickConversionsResponse();

            mockGrpcClient.Setup(x => x.UploadClickConversions(request, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            ConversionUploadServiceClient  client   = new ConversionUploadServiceClientImpl(mockGrpcClient.Object, null);
            UploadClickConversionsResponse response = client.UploadClickConversions(request);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Пример #7
0
 /// <summary>Snippet for UploadClickConversions</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void UploadClickConversionsRequestObject()
 {
     // Create client
     ConversionUploadServiceClient conversionUploadServiceClient = ConversionUploadServiceClient.Create();
     // Initialize request argument(s)
     UploadClickConversionsRequest request = new UploadClickConversionsRequest
     {
         CustomerId  = "",
         Conversions =
         {
             new ClickConversion(),
         },
         PartialFailure = false,
         ValidateOnly   = false,
     };
     // Make the request
     UploadClickConversionsResponse response = conversionUploadServiceClient.UploadClickConversions(request);
 }
        /// <summary>Snippet for UploadClickConversionsAsync</summary>
        public async Task UploadClickConversionsAsync()
        {
            // Snippet: UploadClickConversionsAsync(string, IEnumerable<ClickConversion>, bool, CallSettings)
            // Additional: UploadClickConversionsAsync(string, IEnumerable<ClickConversion>, bool, CancellationToken)
            // Create client
            ConversionUploadServiceClient conversionUploadServiceClient = await ConversionUploadServiceClient.CreateAsync();

            // Initialize request argument(s)
            string customerId = "";
            IEnumerable <ClickConversion> conversions = new ClickConversion[]
            {
                new ClickConversion(),
            };
            bool partialFailure = false;
            // Make the request
            UploadClickConversionsResponse response = await conversionUploadServiceClient.UploadClickConversionsAsync(customerId, conversions, partialFailure);

            // End snippet
        }
        public async Task UploadClickConversionsAsync()
        {
            Mock <ConversionUploadService.ConversionUploadServiceClient> mockGrpcClient = new Mock <ConversionUploadService.ConversionUploadServiceClient>(MockBehavior.Strict);
            UploadClickConversionsRequest expectedRequest = new UploadClickConversionsRequest
            {
                CustomerId     = "customerId-1772061412",
                Conversions    = { },
                PartialFailure = true,
            };
            UploadClickConversionsResponse expectedResponse = new UploadClickConversionsResponse();

            mockGrpcClient.Setup(x => x.UploadClickConversionsAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <UploadClickConversionsResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            ConversionUploadServiceClient client = new ConversionUploadServiceClientImpl(mockGrpcClient.Object, null);
            string customerId = "customerId-1772061412";
            IEnumerable <ClickConversion> conversions = new List <ClickConversion>();
            bool partialFailure = true;
            UploadClickConversionsResponse response = await client.UploadClickConversionsAsync(customerId, conversions, partialFailure);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        /// <summary>Snippet for UploadClickConversionsAsync</summary>
        public async Task UploadClickConversionsRequestObjectAsync()
        {
            // Snippet: UploadClickConversionsAsync(UploadClickConversionsRequest, CallSettings)
            // Additional: UploadClickConversionsAsync(UploadClickConversionsRequest, CancellationToken)
            // Create client
            ConversionUploadServiceClient conversionUploadServiceClient = await ConversionUploadServiceClient.CreateAsync();

            // Initialize request argument(s)
            UploadClickConversionsRequest request = new UploadClickConversionsRequest
            {
                CustomerId  = "",
                Conversions =
                {
                    new ClickConversion(),
                },
                PartialFailure = false,
                ValidateOnly   = false,
            };
            // Make the request
            UploadClickConversionsResponse response = await conversionUploadServiceClient.UploadClickConversionsAsync(request);

            // End snippet
        }
Пример #11
0
        public void UploadClickConversions()
        {
            Mock <ConversionUploadService.ConversionUploadServiceClient> mockGrpcClient = new Mock <ConversionUploadService.ConversionUploadServiceClient>(MockBehavior.Strict);
            UploadClickConversionsRequest expectedRequest = new UploadClickConversionsRequest
            {
                CustomerId     = "customerId-1772061412",
                Conversions    = { },
                PartialFailure = true,
                ValidateOnly   = false,
            };
            UploadClickConversionsResponse expectedResponse = new UploadClickConversionsResponse();

            mockGrpcClient.Setup(x => x.UploadClickConversions(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            ConversionUploadServiceClient client = new ConversionUploadServiceClientImpl(mockGrpcClient.Object, null);
            string customerId = "customerId-1772061412";
            IEnumerable <ClickConversion> conversions = new List <ClickConversion>();
            bool partialFailure = true;
            bool validateOnly   = false;
            UploadClickConversionsResponse response = client.UploadClickConversions(customerId, conversions, partialFailure, validateOnly);

            Assert.AreEqual(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
        /// <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>
        /// <param name="conversionActionId">The conversion action ID.</param>
        /// <param name="conversionTime">The conversion time in "yyyy-mm-dd hh:mm:ss+|-hh:mm"
        /// format.</param>
        /// <param name="gclid">The GCLID for the conversion. If set, <code>gbraid</code> and
        /// <code>wbraid</code> must be null.</param>
        /// <param name="gbraid">The GBRAID for the iOS app conversion. If set, <code>gclid</code>
        /// and <code>wbraid</code> must be null.</param>
        /// <param name="wbraid">The WBRAID for the iOS web conversion. If set, <code>gclid</code>
        /// and <code>gbraid</code> must be null.</param>
        /// <param name="conversionValue">The convsersion value.</param>
        // [START upload_offline_conversion]
        public void Run(GoogleAdsClient client, long customerId, long conversionActionId,
                        string gclid, string gbraid, string wbraid, string conversionTime,
                        double conversionValue)
        {
            // Get the ConversionActionService.
            ConversionUploadServiceClient conversionUploadService =
                client.GetService(Services.V10.ConversionUploadService);

            // Creates a click conversion by specifying currency as USD.
            ClickConversion clickConversion = new ClickConversion()
            {
                ConversionAction   = ResourceNames.ConversionAction(customerId, conversionActionId),
                ConversionValue    = conversionValue,
                ConversionDateTime = conversionTime,
                CurrencyCode       = "USD"
            };

            // Verifies that exactly one of gclid, gbraid, and wbraid is specified, as required.
            // See https://developers.google.com/google-ads/api/docs/conversions/upload-clicks
            // for details.
            string[] ids     = { gclid, gbraid, wbraid };
            int      idCount = ids.Where(id => !string.IsNullOrEmpty(id)).Count();

            if (idCount != 1)
            {
                throw new ArgumentException($"Exactly 1 of gclid, gbraid, or wbraid is " +
                                            $"required, but {idCount} ID values were provided");
            }

            // Sets the single specified ID field.
            if (!string.IsNullOrEmpty(gclid))
            {
                clickConversion.Gclid = gclid;
            }
            else if (!string.IsNullOrEmpty(wbraid))
            {
                clickConversion.Wbraid = wbraid;
            }
            else if (!string.IsNullOrEmpty(gbraid))
            {
                clickConversion.Gbraid = gbraid;
            }

            try
            {
                // Issues a request to upload the click conversion.
                UploadClickConversionsResponse response =
                    conversionUploadService.UploadClickConversions(
                        new UploadClickConversionsRequest()
                {
                    CustomerId     = customerId.ToString(),
                    Conversions    = { clickConversion },
                    PartialFailure = true,
                    ValidateOnly   = false
                });

                // Prints the result.
                ClickConversionResult uploadedClickConversion = response.Results[0];
                Console.WriteLine($"Uploaded conversion that occurred at " +
                                  $"'{uploadedClickConversion.ConversionDateTime}' from Google " +
                                  $"Click ID '{uploadedClickConversion.Gclid}' to " +
                                  $"'{uploadedClickConversion.ConversionAction}'.");
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }
Пример #13
0
        /// <summary>
        /// Runs the code example.
        /// </summary>
        /// <param name="client">The Google Ads client.</param>
        /// <param name="customerId">The Google Ads customer ID for which conversions are uploaded.
        /// </param>
        /// <param name="conversionActionId">ID of the conversion action for which conversions are
        /// uploaded.</param>
        /// <param name="emailAddress">The email address.</param>
        /// <param name="conversionDateTime">The date time at which the conversion occurred.</param>
        /// <param name="conversionValue">The conversion value.</param>
        /// <param name="orderId">The unique order ID (transaction ID) of the conversion.</param>
        // [START upload_conversion_with_identifiers]
        public void Run(GoogleAdsClient client, long customerId, long conversionActionId,
                        string emailAddress, string conversionDateTime, double conversionValue,
                        string orderId)
        {
            // Get the ConversionUploadService.
            ConversionUploadServiceClient conversionUploadService =
                client.GetService(Services.V10.ConversionUploadService);

            // [START create_conversion]
            // Gets the conversion action resource name.
            string conversionActionResourceName =
                ResourceNames.ConversionAction(customerId, conversionActionId);

            // Creates a builder for constructing the click conversion.
            ClickConversion clickConversion = new ClickConversion()
            {
                ConversionAction   = conversionActionResourceName,
                ConversionDateTime = conversionDateTime,
                ConversionValue    = conversionValue,
                CurrencyCode       = "USD"
            };

            // Sets the order ID if provided.
            if (!string.IsNullOrEmpty(orderId))
            {
                clickConversion.OrderId = orderId;
            }

            // Optional: Specifies the user identifier source.
            clickConversion.UserIdentifiers.Add(new UserIdentifier()
            {
                // Creates a user identifier using the hashed email address, using the normalize
                // and hash method specifically for email addresses.
                // If using a phone number, use the NormalizeAndHash(String) method instead.
                HashedEmail = NormalizeAndHashEmailAddress(emailAddress),
                // Optional: Specifies the user identifier source.
                UserIdentifierSource = UserIdentifierSource.FirstParty
            });
            // [END create_conversion]

            try
            {
                // Uploads the click conversion. Partial failure should always be set to true.
                UploadClickConversionsResponse response =
                    conversionUploadService.UploadClickConversions(
                        new UploadClickConversionsRequest()
                {
                    CustomerId  = customerId.ToString(),
                    Conversions = { clickConversion },
                    // Enables partial failure (must be true).
                    PartialFailure = true
                });

                if (response.PartialFailureError != null)
                {
                    // Extracts the partial failure from the response status.
                    GoogleAdsFailure partialFailure = response.PartialFailure;
                    Console.WriteLine($"{partialFailure.Errors.Count} partial failure error(s) " +
                                      $"occurred");
                }
                else
                {
                    ClickConversionResult result = response.Results[0];
                    // Prints the result.
                    Console.WriteLine($"Uploaded conversion that occurred at" +
                                      $" {result.ConversionDateTime} to {result.ConversionAction}.");
                }
            }
            catch (GoogleAdsException e)
            {
                Console.WriteLine("Failure:");
                Console.WriteLine($"Message: {e.Message}");
                Console.WriteLine($"Failure: {e.Failure}");
                Console.WriteLine($"Request ID: {e.RequestId}");
                throw;
            }
        }