GoogleAdsClient client = new GoogleAdsClient(new Google.Ads.GoogleAds.Config.GoogleAdsConfig()
{
LinkedCustomerId = CustomerId,
OAuth2ClientId = ClientId,
OAuth2ClientSecret = ClientSecret,
OAuth2RefreshToken = RefreshToken,
DeveloperToken = DevToken,
UseGrpcCore = true,
});
// Get the ConversionActionService.
ConversionUploadServiceClient conversionUploadService =
client.GetService(Services.V14.ConversionUploadService);
// Creates a click conversion by specifying currency as USD.
ClickConversion clickConversion = new ClickConversion()
{
ConversionAction = "Pending-Revenues",
ConversionValue = ConvertedValue.Value,
ConversionDateTime = ConversionTime.ToString("yyyyMMdd HHmmss") + " Africa/Cairo",
CurrencyCode = CurrencyCode
};
// 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 };
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;
}
try
{
// Issues a request to upload the click conversion.
UploadClickConversionsResponse response =
conversionUploadService.UploadClickConversions(
new UploadClickConversionsRequest()
{
CustomerId = CustomerId,
Conversions = { clickConversion },
PartialFailure = true,
ValidateOnly = false,
DebugEnabled = 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 (Exception ex)
{
}
at Google.Ads.Gax.Interceptors.UnaryRpcInterceptor.<>c__DisplayClass1_0`2.<Intercept>b__0(Task`1 oldTask)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Google.Api.Gax.Grpc.ApiCall.GrpcCallAdapter`2.<>c__DisplayClass4_0.<<CallAsync>g__WaitAndCallHandlers|0>d.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Google.Api.Gax.TaskExtensions.WaitWithUnwrappedExceptions(Task task)
at Google.Api.Gax.Grpc.ApiCall.GrpcCallAdapter`2.CallSync(TRequest request, CallSettings callSettings)
at Google.Api.Gax.Grpc.ApiCallRetryExtensions.<>c__DisplayClass1_0`2.<WithRetry>b__0(TRequest request, CallSettings callSettings)
at Google.Api.Gax.Grpc.ApiCall`2.<>c__DisplayClass12_0.<WithCallSettingsOverlay>b__1(TRequest req, CallSettings cs)
at Google.Api.Gax.Grpc.ApiCall`2.Sync(TRequest request, CallSettings perCallCallSettings)
at Google.Ads.GoogleAds.V14.Services.ConversionUploadServiceClientImpl.UploadClickConversions(UploadClickConversionsRequest request, CallSettings callSettings)