Skip to content

Commit

Permalink
V15: Update examples to add DMA consent field
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfrg committed Oct 20, 2023
1 parent 82cd096 commit 63c1b9c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/remarketing/add_customer_match_user_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def add_users_to_customer_match_user_list(client, customer_id, run_job, user_lis
client.resource.customer_match_user_list_metadata do |m|
m.user_list = user_list

unless ad_user_data_consent.nil? && ad_personalization_consent.nil?
if !gclid.nil? || !gclid.nil?
m.consent = client.resource.consent do |c|
# Specifies whether user consent was obtained for the data you are
# uploading. For more details, see:
Expand Down
9 changes: 5 additions & 4 deletions examples/remarketing/upload_call_conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def upload_call_conversion(
end

unless ad_user_data_consent.nil?
m.consent = client.resource.consent do |c|
c.consent = client.resource.consent do |c|
# Specifies whether user consent was obtained for the data you are
# uploading. For more details, see:
# https://www.google.com/about/company/user-consent-policy
Expand Down Expand Up @@ -127,6 +127,7 @@ def upload_call_conversion(
# associate with the call conversion upload.
options[:conversion_custom_variable_id] = nil;
options[:conversion_custom_variable_value] = nil;
options[:ad_user_data_consent] = nil;

OptionParser.new do |opts|
opts.banner = sprintf('Usage: %s [options]', File.basename(__FILE__))
Expand Down Expand Up @@ -158,19 +159,19 @@ def upload_call_conversion(
options[:conversion_value] = v.to_f
end

opts.on('-d', '--conversion-custom-variable-id CONVERSION-CUSTOM-VARIABLE-ID', \
opts.on('-w', '--conversion-custom-variable-id CONVERSION-CUSTOM-VARIABLE-ID', \
String, '(Optional) The ID of the conversion custom variable to ' \
'associate with the upload') do |v|
options[:conversion_custom_variable_id] = v
end

opts.on('-d', '--conversion-custom-variable-value CONVERSION-CUSTOM-VARIABLE-VALUE', \
opts.on('-x', '--conversion-custom-variable-value CONVERSION-CUSTOM-VARIABLE-VALUE', \
String, '(Optional) The value of the conversion custom ' \
'variable to associate with the upload') do |v|
options[:conversion_custom_variable_value] = v
end

opts.on('-u', '--ad-user-data-consent AD-USER-DATA_CONSENT', \
opts.on('-d', '--ad-user-data-consent AD-USER-DATA_CONSENT', \
String, '(Optional) The data consent status for ad user data for all members in the job.' \
'e.g. UNKNOWN, GRANTED, DENIED') do |v|
options[:ad_user_data_consent] = v
Expand Down
15 changes: 9 additions & 6 deletions examples/remarketing/upload_enhanced_conversions_for_leads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ def upload_conversion_with_identifiers(
# uploading. For more details, see:
# https://www.google.com/about/company/user-consent-policy
unless raw_record["ad_user_data_consent"].nil?
# cc.consent.ad_user_data = client.enums.ConsentStatusEnum[
# raw_record["ad_user_data_consent"]
# ]
cc.consent = client.resource.consent do |c|
c.ad_user_data = ad_user_data_consent
end
end
# [END add_conversion_details]

Expand All @@ -117,6 +117,7 @@ def upload_conversion_with_identifiers(
end
# [END add_user_identifiers]

# [START upload_conversion]
response = client.service.conversion_upload.upload_click_conversions(
customer_id: customer_id,
conversions: [click_conversion],
Expand All @@ -131,6 +132,7 @@ def upload_conversion_with_identifiers(
puts "Uploaded click conversion that happened at #{result.conversion_date_time} " \
"to #{result.conversion_action}."
end
# [END upload_conversion]
end

# [START normalize_and_hash]
Expand Down Expand Up @@ -173,8 +175,8 @@ def normalize_and_hash_email(email)
options[:conversion_date_time] = 'INSERT_CONVERSION_DATE_TIME_HERE'
options[:conversion_value] = 'INSERT_CONVERSION_VALUE_HERE'
options[:order_id] = nil
options[:gclid] = 'INSERT_GCLID_HERE'
options[:ad_user_data_consent] = 'INSERT_AD_USER_DATA_CONSENT_ENUM_HERE'
options[:gclid] = nil
options[:ad_user_data_consent] = nil

OptionParser.new do |opts|
opts.banner = sprintf('Usage: %s [options]', File.basename(__FILE__))
Expand Down Expand Up @@ -211,7 +213,8 @@ def normalize_and_hash_email(email)

opts.on('-d', '--ad-user-data-dconsent GCLID', String,
'The data consent status for ad user data for all members in' \
'the job.') do |v|
'the job.' \
'e.g. UNKNOWN, GRANTED, DENIED') do |v|
options[:ad_user_data_consent] = v
end

Expand Down
44 changes: 40 additions & 4 deletions examples/remarketing/upload_store_sales_transactions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def upload_store_sales_transactions(
merchant_center_account_id,
region_code,
language_code,
quantity)
quantity,
ad_user_data_consent,
ad_personalization_consent)
# GoogleAdsClient will read a config file from
# ENV['HOME']/google_ads_config.rb when called without parameters
client = Google::Ads::GoogleAds::GoogleAdsClient.new
Expand All @@ -66,6 +68,8 @@ def upload_store_sales_transactions(
offline_user_data_job_resource_name,
conversion_action_id,
custom_value,
ad_user_data_consent,
ad_personalization_consent
)

# Issues an asynchronous request to run the offline user data job.
Expand Down Expand Up @@ -181,10 +185,13 @@ def add_transactions_to_offline_user_data_job(
customer_id,
offline_user_data_job_resource_name,
conversion_action_id,
custom_value)
custom_value,
ad_user_data_consent,
ad_personalization_consent)
# Constructs the operation for each transaction.
user_data_job_operations = build_offline_user_data_job_operations(
client, customer_id, conversion_action_id, custom_value)
client, customer_id, conversion_action_id, custom_value, ad_user_data_consent,
ad_personalization_consent)

# [START enable_warnings_1]
# Issues a request to add the operations to the offline user data job.
Expand Down Expand Up @@ -238,7 +245,9 @@ def build_offline_user_data_job_operations(
client,
customer_id,
conversion_action_id,
custom_value)
custom_value,
ad_user_data_consent,
ad_personalization_consent)
operations = []

# Creates the first transaction for upload based on an email address
Expand Down Expand Up @@ -267,6 +276,19 @@ def build_offline_user_data_job_operations(
t.transaction_date_time = "2020-05-01 23:52:12"
t.custom_value = custom_value unless custom_value.nil?
end
if !gclid.nil? || !gclid.nil?
job.consent = client.resource.consent do |c|
# Specifies whether user consent was obtained for the data you are
# uploading. For more details, see:
# https://www.google.com/about/company/user-consent-policy
unless ad_user_data_consent.nil?
c.ad_user_data = ad_user_data_consent
end
unless ad_personalization_consent.nil?
c.ad_personalization = ad_personalization_consent
end
end
end
end

# Creates the second transaction for upload based on a physical address.
Expand Down Expand Up @@ -466,6 +488,18 @@ def check_job_status(
options[:quantity] = v
end

opts.on('-d', '--ad-user-data-consent [AD-USER-DATA_CONSENT]', String,
'The personalization consent status for ad user data for all members in the job.' \
'e.g. UNKNOWN, GRANTED, DENIED') do |v|
options[:ad_user_data_consent] = v
end

opts.on('-p', '--ad-personalization-consent [AD-PERSONALIZATION-CONSENT]', String,
'The personalization consent status for ad user data for all members in the job.' \
'e.g. UNKNOWN, GRANTED, DENIED') do |v|
options[:ad_personalization_consent] = v
end

opts.separator ''
opts.separator 'Help:'

Expand All @@ -491,6 +525,8 @@ def check_job_status(
options[:region_code],
options[:language_code],
options[:quantity],
options[:ad_user_data_consent],
options[:ad_personalization_consent],
)
rescue Google::Ads::GoogleAds::Errors::GoogleAdsError => e
e.failure.errors.each do |error|
Expand Down

0 comments on commit 63c1b9c

Please sign in to comment.