/// <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 UploadCallConversionsAsync</summary> public async Task UploadCallConversionsAsync() { // Snippet: UploadCallConversionsAsync(string, IEnumerable<CallConversion>, bool, CallSettings) // Additional: UploadCallConversionsAsync(string, IEnumerable<CallConversion>, bool, CancellationToken) // Create client ConversionUploadServiceClient conversionUploadServiceClient = await ConversionUploadServiceClient.CreateAsync(); // Initialize request argument(s) string customerId = ""; IEnumerable <CallConversion> conversions = new CallConversion[] { new CallConversion(), }; bool partialFailure = false; // Make the request UploadCallConversionsResponse response = await conversionUploadServiceClient.UploadCallConversionsAsync(customerId, conversions, partialFailure); // End snippet }