/// <summary> /// Runs the code example. /// </summary> /// <param name="client">The Google Ads client.</param> /// <param name="customerId">The Google Ads customer ID for whom the conversion action will /// be added.</param> /// <param name="callerId">The caller ID in E.164 format with preceding '+' sign. e.g. /// "+16502531234".</param> /// <param name="callStartTime">The call start time in "yyyy-mm-dd hh:mm:ss+|-hh:mm" /// format.</param> /// <param name="conversionTime">The conversion time in "yyyy-mm-dd hh:mm:ss+|-hh:mm" /// format.</param> /// <param name="conversionValue">The conversion value.</param> /// <param name="conversionCustomVariableId">The ID of the conversion custom variable to /// associate with the upload.</param> /// <param name="conversionCustomVariableValue">The value of the conversion custom variable /// to associate with the upload.</param> // [START upload_call_conversion] public void Run(GoogleAdsClient client, long customerId, string callerId, string callStartTime, string conversionTime, double conversionValue, long?conversionCustomVariableId, string conversionCustomVariableValue) { // Get the ConversionUploadService. ConversionUploadServiceClient conversionUploadService = client.GetService(Services.V10.ConversionUploadService); // Create a call conversion by specifying currency as USD. CallConversion callConversion = new CallConversion() { CallerId = callerId, CallStartDateTime = callStartTime, ConversionDateTime = conversionTime, ConversionValue = conversionValue, CurrencyCode = "USD" }; if (conversionCustomVariableId != null && !string.IsNullOrEmpty(conversionCustomVariableValue)) { callConversion.CustomVariables.Add(new CustomVariable() { ConversionCustomVariable = ResourceNames.ConversionCustomVariable( customerId, conversionCustomVariableId.Value), Value = conversionCustomVariableValue }); } UploadCallConversionsRequest request = new UploadCallConversionsRequest() { CustomerId = customerId.ToString(), Conversions = { callConversion }, PartialFailure = true }; try { // Issues a request to upload the call conversion. The partialFailure parameter // is set to true, and validateOnly parameter to false as required by this method // call. UploadCallConversionsResponse response = conversionUploadService.UploadCallConversions(request); // Prints the result. CallConversionResult uploadedCallConversion = response.Results[0]; Console.WriteLine($"Uploaded call conversion that occurred at " + $"'{uploadedCallConversion.CallStartDateTime}' for caller ID " + $"'{uploadedCallConversion.CallerId}' to the conversion action with " + $"resource name '{uploadedCallConversion.ConversionAction}'."); } 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 UploadCallConversions</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void UploadCallConversions() { // Create client ConversionUploadServiceClient conversionUploadServiceClient = ConversionUploadServiceClient.Create(); // Initialize request argument(s) string customerId = ""; IEnumerable <CallConversion> conversions = new CallConversion[] { new CallConversion(), }; bool partialFailure = false; // Make the request UploadCallConversionsResponse response = conversionUploadServiceClient.UploadCallConversions(customerId, conversions, partialFailure); }
/// <summary>Snippet for UploadClickConversionsAsync</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public async Task UploadClickConversionsAsync() { // 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); }
/// <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; } }
/// <summary>Snippet for UploadCallConversions</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void UploadCallConversionsRequestObject() { // Create client ConversionUploadServiceClient conversionUploadServiceClient = ConversionUploadServiceClient.Create(); // Initialize request argument(s) UploadCallConversionsRequest request = new UploadCallConversionsRequest { CustomerId = "", Conversions = { new CallConversion(), }, PartialFailure = false, ValidateOnly = false, }; // Make the request UploadCallConversionsResponse response = conversionUploadServiceClient.UploadCallConversions(request); }
/// <summary>Snippet for UploadClickConversionsAsync</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public async Task UploadClickConversionsRequestObjectAsync() { // 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); }
/// <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 }
/// <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 }
/// <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; } }
/// <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; } }