From 7b991d879770fa4a4ee94177133593ecbdfc2eb2 Mon Sep 17 00:00:00 2001 From: Josh Radcliff Date: Thu, 11 Jan 2024 16:17:54 -0500 Subject: [PATCH] Demonstrate passing consent in offline conversion upload (#547) Ref: b/310739611 Change-Id: I443406e95fe4a2ba3c3f04b898e1dfea698ffacb --- .../Remarketing/UploadOfflineConversion.cs | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Google.Ads.GoogleAds/examples/Remarketing/UploadOfflineConversion.cs b/Google.Ads.GoogleAds/examples/Remarketing/UploadOfflineConversion.cs index da9f598dc..74eae9172 100644 --- a/Google.Ads.GoogleAds/examples/Remarketing/UploadOfflineConversion.cs +++ b/Google.Ads.GoogleAds/examples/Remarketing/UploadOfflineConversion.cs @@ -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 { @@ -87,6 +88,13 @@ public class Options : OptionsBase [Option("conversionValue", Required = true, HelpText = "The convsersion value.")] public double ConversionValue { get; set; } + + /// + /// The consent status for ad user data. + /// + [Option("adUserDataConsent", Required = false, HelpText = + "The ad user data consent for the click.")] + public ConsentStatus? AdUserDataConsent { get; set; } } /// @@ -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); } /// @@ -129,10 +137,11 @@ public static void Main(string[] args) /// The WBRAID for the iOS web conversion. If set, gclid /// and gbraid must be null. /// The convsersion value. + /// The ad user data consent for the click. // [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 = @@ -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.