Skip to content

Commit

Permalink
Demonstrate passing consent in offline conversion upload (#547)
Browse files Browse the repository at this point in the history
Ref: b/310739611

Change-Id: I443406e95fe4a2ba3c3f04b898e1dfea698ffacb
  • Loading branch information
jradcliff authored Jan 11, 2024
1 parent 88ededa commit 7b991d8
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Google.Ads.GoogleAds.V15.Services;
using System;
using System.Linq;
using static Google.Ads.GoogleAds.V15.Enums.ConsentStatusEnum.Types;

namespace Google.Ads.GoogleAds.Examples.V15
{
Expand Down Expand Up @@ -87,6 +88,13 @@ public class Options : OptionsBase
[Option("conversionValue", Required = true, HelpText =
"The convsersion value.")]
public double ConversionValue { get; set; }

/// <summary>
/// The consent status for ad user data.
/// </summary>
[Option("adUserDataConsent", Required = false, HelpText =
"The ad user data consent for the click.")]
public ConsentStatus? AdUserDataConsent { get; set; }
}

/// <summary>
Expand All @@ -101,7 +109,7 @@ public static void Main(string[] args)
Console.WriteLine(codeExample.Description);
codeExample.Run(new GoogleAdsClient(), options.CustomerId, options.ConversionActionId,
options.ConversionTime, options.Gclid, options.Gbraid, options.Wbraid,
options.ConversionValue);
options.ConversionValue, options.AdUserDataConsent);
}

/// <summary>
Expand Down Expand Up @@ -129,10 +137,11 @@ public static void Main(string[] args)
/// <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>
/// <param name="adUserDataConsent">The ad user data consent for the click.</param>
// [START upload_offline_conversion]
public void Run(GoogleAdsClient client, long customerId, long conversionActionId,
string gclid, string gbraid, string wbraid, string conversionTime,
double conversionValue)
double conversionValue, ConsentStatus? adUserDataConsent)
{
// Get the ConversionActionService.
ConversionUploadServiceClient conversionUploadService =
Expand All @@ -147,6 +156,18 @@ public void Run(GoogleAdsClient client, long customerId, long conversionActionId
CurrencyCode = "USD",
};

// Sets the consent information, if provided.
if (adUserDataConsent != null)
{
// Specifies whether user consent was obtained for the data you are uploading. See
// https://www.google.com/about/company/user-consent-policy
// for details.
clickConversion.Consent = new Consent()
{
AdUserData = (ConsentStatus)adUserDataConsent
};
}

// 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.
Expand Down

0 comments on commit 7b991d8

Please sign in to comment.