شما میتوانید از API گوگل ادز برای وارد کردن تبدیلهای آفلاین به گوگل ادز استفاده کنید تا تبلیغاتی را که منجر به فروش در دنیای آفلاین، مانند تلفن یا از طریق نماینده فروش، شدهاند، ردیابی کنید.
برای بهرهمندی کامل از مزایای وارد کردن دادههای تبدیل، توصیه میکنیم تبدیلهای بهبود یافته برای سرنخها را پیادهسازی کنید، که از GCLIDها و دادههای ارائه شده توسط کاربر برای به حداکثر رساندن دوام و عملکرد استفاده میکند.
تبدیلهای بهبود یافته
تبدیلهای بهبود یافته به شما کمک میکنند تا با تکمیل تبدیلهای خود با دادههای تبدیل شخص ثالث، مانند آدرس ایمیل، نام، آدرس منزل و شماره تلفن، دقت اندازهگیری تبدیل خود را بهبود بخشید.
دو نوع تبدیل پیشرفته وجود دارد. برای جزئیات بیشتر به مقاله «درباره تبدیلهای پیشرفته» در مرکز راهنمایی مراجعه کنید.
بخش بعدی نحوه افزایش تبدیلهای آفلاین را توضیح میدهد، ویژگیای که به آن تبدیلهای بهبود یافته برای سرنخها نیز گفته میشود.
تبدیلهای بهبود یافته برای سرنخها چیست؟
تبدیلهای پیشرفته برای سرنخها، نسخه ارتقا یافتهای از وارد کردن تبدیل آفلاین است که از دادههای ارائه شده توسط کاربر، مانند آدرسهای ایمیل، برای تکمیل دادههای تبدیل آفلاین وارد شده استفاده میکند تا دقت و عملکرد پیشنهاد قیمت را بهبود بخشد. هنگامی که تبدیلهای آفلاین خود را وارد میکنید، از دادههای هش شده مشتری ارائه شده برای نسبت دادن به کمپین تبلیغات گوگل با تطبیق با همان دادههای جمعآوری شده در وبسایت شما، مانند فرم سرنخ، و به مشتریان وارد شدهای که با تبلیغ شما تعامل داشتهاند، استفاده میشود. برای اطلاعات بیشتر در مورد نحوه عملکرد تبدیلهای پیشرفته برای سرنخها، مقاله ما را با عنوان « درباره تبدیلهای پیشرفته برای سرنخها» مرور کنید.
بسته به اینکه آیا از برچسب گوگل برای ردیابی رویدادهای ارسال فرم در صفحه وب خود استفاده میکنید یا خیر، دو راه برای پیادهسازی تبدیلهای بهبود یافته برای سرنخها وجود دارد. برای بهترین عملکرد و دوام، اکیداً توصیه میکنیم از برچسب گوگل برای تبدیلهای بهبود یافته برای سرنخها استفاده کنید.
- اگر از ابتدا شروع میکنید، با بخش پیشنیازها شروع کنید.
- اگر از قبل واردات تبدیل آفلاین را تنظیم کردهاید و میخواهید آن را به تبدیلهای پیشرفته برای سرنخها ارتقا دهید، توصیه میکنیم از بخش پیکربندی برچسبگذاری شروع کنید.
- اگر قبلاً تگ گوگل را تنظیم کردهاید، یا قصد استفاده از تگ گوگل را ندارید، و در حال شروع کار بر روی ادغام API تبلیغات گوگل خود هستید، به بخش پیادهسازی API بروید.
- اگر نمیتوانید دادههای ارائه شده توسط کاربر را وارد کنید، یا برای تبدیلهای خود به منابع خارجی متکی هستید، به راهنمای وارد کردن تبدیلهای آفلاین قدیمی مراجعه کنید.
پیشنیازها
ابتدا، مطمئن شوید که مراحل موجود در بخش شروع کار را تکمیل کردهاید.
قبل از اینکه بتوانید از تبدیلهای پیشرفته برای سرنخها استفاده کنید، باید تبدیلهای پیشرفته برای سرنخها را انتخاب کنید و شرایط دادههای مشتری را بپذیرید. میتوانید با ارسال درخواست زیر به مشتری تبدیل گوگل ادز، تأیید کنید که آیا این پیشنیازها از قبل برآورده شدهاند یا خیر:
SELECT
  customer.id,
  customer.conversion_tracking_setting.accepted_customer_data_terms,
  customer.conversion_tracking_setting.enhanced_conversions_for_leads_enabled
FROM customer
 اگر هر یک از accepted_customer_data_terms یا enhanced_conversions_for_leads_enabled false باشد، دستورالعملهای مرکز راهنما را برای تکمیل این پیشنیازها دنبال کنید.
پیکربندی برچسبگذاری
با دنبال کردن دستورالعملهای موجود در مرکز راهنما، برچسب گوگل را پیکربندی کنید تا تبدیلهای پیشرفته برای سرنخها فعال شود. برای تنظیم تبدیلهای پیشرفته برای سرنخها با استفاده از Google Tag Manager، این دستورالعملها را دنبال کنید.
پیادهسازی API
در اینجا روند کلی برای وارد کردن تبدیلهای بهبود یافته برای سرنخها با استفاده از API گوگل ادز آمده است.
- دادههای ارائه شده توسط کاربر، مانند آدرس ایمیل، شماره تلفن و آدرس پستی را نرمالسازی و هش کنید . 
- اشیاء - ClickConversionرا با دادههای نرمالسازی و هششدهی ارائه شده توسط کاربر پر کنید .
- اشیاء - ClickConversionرا با استفاده از- ConversionUploadServiceبه API گوگل ادز وارد کنید. برای جزئیات بیشتر به- UploadClickConversionsمراجعه کنید.
نرمالسازی و هش کردن دادههای ارائه شده توسط کاربر
برای ملاحظات حریم خصوصی، دادههای زیر باید قبل از وارد شدن با استفاده از SHA-256 هش شوند:
- آدرس ایمیل
- شماره تلفن
- نام کوچک
- نام خانوادگی
- آدرس خیابان
برای استانداردسازی نتایج هش، قبل از هش کردن این مقادیر، باید موارد زیر را انجام دهید:
- فاصلههای خالیِ ابتدا و انتهای سطر را حذف کنید.
- متن را به حروف کوچک تبدیل کنید.
- شماره تلفنها را طبق استاندارد E164 قالببندی کنید.
-  تمام نقطهها ( .) که قبل از نام دامنه در آدرسهای ایمیلgmail.comوgooglemail.comقرار دارند را حذف کنید.
دادههای زیر را هش نکنید :
- کشور
- ایالت
- شهر
- کد پستی
مثال کد
این مثال نحوه نرمالسازی و هش کردن دادههای ارائه شده توسط کاربر را نشان میدهد.
جاوا
private String normalizeAndHash(MessageDigest digest, String s) throws UnsupportedEncodingException { // Normalizes by first converting all characters to lowercase, then trimming spaces. String normalized = s.toLowerCase(); // Removes leading, trailing, and intermediate spaces. normalized = normalized.replaceAll("\\s+", ""); // Hashes the normalized string using the hashing algorithm. byte[] hash = digest.digest(normalized.getBytes("UTF-8")); StringBuilder result = new StringBuilder(); for (byte b : hash) { result.append(String.format("%02x", b)); } return result.toString(); } /** * Returns the result of normalizing and hashing an email address. For this use case, Google Ads * requires removal of any '.' characters preceding {@code gmail.com} or {@code googlemail.com}. * * @param digest the digest to use to hash the normalized string. * @param emailAddress the email address to normalize and hash. */ private String normalizeAndHashEmailAddress(MessageDigest digest, String emailAddress) throws UnsupportedEncodingException { String normalizedEmail = emailAddress.toLowerCase(); String[] emailParts = normalizedEmail.split("@"); if (emailParts.length > 1 && emailParts[1].matches("^(gmail|googlemail)\\.com\\s*")) { // Removes any '.' characters from the portion of the email address before the domain if the // domain is gmail.com or googlemail.com. emailParts[0] = emailParts[0].replaceAll("\\.", ""); normalizedEmail = String.format("%s@%s", emailParts[0], emailParts[1]); } return normalizeAndHash(digest, normalizedEmail); }
سی شارپ
/// <summary> /// Normalizes the email address and hashes it. For this use case, Google Ads requires /// removal of any '.' characters preceding <code>gmail.com</code> or /// <code>googlemail.com</code>. /// </summary> /// <param name="emailAddress">The email address.</param> /// <returns>The hash code.</returns> private string NormalizeAndHashEmailAddress(string emailAddress) { string normalizedEmail = emailAddress.ToLower(); string[] emailParts = normalizedEmail.Split('@'); if (emailParts.Length > 1 && (emailParts[1] == "gmail.com" || emailParts[1] == "googlemail.com")) { // Removes any '.' characters from the portion of the email address before // the domain if the domain is gmail.com or googlemail.com. emailParts[0] = emailParts[0].Replace(".", ""); normalizedEmail = $"{emailParts[0]}@{emailParts[1]}"; } return NormalizeAndHash(normalizedEmail); } /// <summary> /// Normalizes and hashes a string value. /// </summary> /// <param name="value">The value to normalize and hash.</param> /// <returns>The normalized and hashed value.</returns> private static string NormalizeAndHash(string value) { return ToSha256String(digest, ToNormalizedValue(value)); } /// <summary> /// Hash a string value using SHA-256 hashing algorithm. /// </summary> /// <param name="digest">Provides the algorithm for SHA-256.</param> /// <param name="value">The string value (e.g. an email address) to hash.</param> /// <returns>The hashed value.</returns> private static string ToSha256String(SHA256 digest, string value) { byte[] digestBytes = digest.ComputeHash(Encoding.UTF8.GetBytes(value)); // Convert the byte array into an unhyphenated hexadecimal string. return BitConverter.ToString(digestBytes).Replace("-", string.Empty); } /// <summary> /// Removes leading and trailing whitespace and converts all characters to /// lower case. /// </summary> /// <param name="value">The value to normalize.</param> /// <returns>The normalized value.</returns> private static string ToNormalizedValue(string value) { return value.Trim().ToLower(); }
پی اچ پی
private static function normalizeAndHash(string $hashAlgorithm, string $value): string { // Normalizes by first converting all characters to lowercase, then trimming spaces. $normalized = strtolower($value); // Removes leading, trailing, and intermediate spaces. $normalized = str_replace(' ', '', $normalized); return hash($hashAlgorithm, strtolower(trim($normalized))); } /** * Returns the result of normalizing and hashing an email address. For this use case, Google * Ads requires removal of any '.' characters preceding "gmail.com" or "googlemail.com". * * @param string $hashAlgorithm the hash algorithm to use * @param string $emailAddress the email address to normalize and hash * @return string the normalized and hashed email address */ private static function normalizeAndHashEmailAddress( string $hashAlgorithm, string $emailAddress ): string { $normalizedEmail = strtolower($emailAddress); $emailParts = explode("@", $normalizedEmail); if ( count($emailParts) > 1 && preg_match('/^(gmail|googlemail)\.com\s*/', $emailParts[1]) ) { // Removes any '.' characters from the portion of the email address before the domain // if the domain is gmail.com or googlemail.com. $emailParts[0] = str_replace(".", "", $emailParts[0]); $normalizedEmail = sprintf('%s@%s', $emailParts[0], $emailParts[1]); } return self::normalizeAndHash($hashAlgorithm, $normalizedEmail); }
پایتون
def normalize_and_hash_email_address(email_address: str) -> str: """Returns the result of normalizing and hashing an email address. For this use case, Google Ads requires removal of any '.' characters preceding "gmail.com" or "googlemail.com" Args: email_address: An email address to normalize. Returns: A normalized (lowercase, removed whitespace) and SHA-265 hashed string. """ normalized_email: str = email_address.strip().lower() email_parts: list[str] = normalized_email.split("@") # Check that there are at least two segments if len(email_parts) > 1: # Checks whether the domain of the email address is either "gmail.com" # or "googlemail.com". If this regex does not match then this statement # will evaluate to None. if re.match(r"^(gmail|googlemail)\.com$", email_parts[1]): # Removes any '.' characters from the portion of the email address # before the domain if the domain is gmail.com or googlemail.com. email_parts[0] = email_parts[0].replace(".", "") normalized_email = "@".join(email_parts) return normalize_and_hash(normalized_email) def normalize_and_hash(s: str) -> str: """Normalizes and hashes a string with SHA-256. Private customer data must be hashed during upload, as described at: https://support.google.com/google-ads/answer/7474263 Args: s: The string to perform this operation on. Returns: A normalized (lowercase, removed whitespace) and SHA-256 hashed string. """ return hashlib.sha256(s.strip().lower().encode()).hexdigest()
روبی
# Returns the result of normalizing and then hashing the string using the # provided digest. Private customer data must be hashed during upload, as # described at https://support.google.com/google-ads/answer/7474263. def normalize_and_hash(str) # Remove leading and trailing whitespace and ensure all letters are lowercase # before hashing. Digest::SHA256.hexdigest(str.strip.downcase) end # Returns the result of normalizing and hashing an email address. For this use # case, Google Ads requires removal of any '.' characters preceding 'gmail.com' # or 'googlemail.com'. def normalize_and_hash_email(email) email_parts = email.downcase.split("@") # Removes any '.' characters from the portion of the email address before the # domain if the domain is gmail.com or googlemail.com. if email_parts.last =~ /^(gmail|googlemail)\.com\s*/ email_parts[0] = email_parts[0].gsub('.', '') end normalize_and_hash(email_parts.join('@')) end
پرل
sub normalize_and_hash { my $value = shift; # Removes leading, trailing, and intermediate spaces. $value =~ s/\s+//g; return sha256_hex(lc $value); } # Returns the result of normalizing and hashing an email address. For this use # case, Google Ads requires removal of any '.' characters preceding 'gmail.com' # or 'googlemail.com'. sub normalize_and_hash_email_address { my $email_address = shift; my $normalized_email = lc $email_address; my @email_parts = split('@', $normalized_email); if (scalar @email_parts > 1 && $email_parts[1] =~ /^(gmail|googlemail)\.com\s*/) { # Remove any '.' characters from the portion of the email address before the # domain if the domain is 'gmail.com' or 'googlemail.com'. $email_parts[0] =~ s/\.//g; $normalized_email = sprintf '%s@%s', $email_parts[0], $email_parts[1]; } return normalize_and_hash($normalized_email); }
اشیاء ClickConversion را پر کنید
 مجموعه اشیاء ClickConversion در UploadClickConversionRequest شما، مجموعهای از تبدیلهایی را نشان میدهد که میخواهید وارد کنید. هنگام ایجاد اشیاء ClickConversion ، جزئیات زیر را در نظر داشته باشید:
-  gclid
- GCLIDها شناسههایی هستند که از پارامترهای URL هنگام کلیک یک فرد روی تبلیغ شما و هدایت او به وبسایت شما، استخراج میشوند. 
-  gbraid
- gbraidیک پارامتر URL است که وقتی کاربر روی یک تبلیغ در وب کلیک میکند و به برنامه iOS شما هدایت میشود، نمایش داده میشود.
-  wbraid
- wbraidیک پارامتر URL است که وقتی کاربر روی یک تبلیغ در یک برنامه iOS کلیک میکند و به صفحه وب شما هدایت میشود، نمایش داده میشود.
-  user_identifiers
- هنگام استفاده از تبدیلهای پیشرفته برای سرنخها، باید فیلد - user_identifiersرا با دادههای نرمالسازی و هششدهی ارائه شده توسط کاربر پر کنید. اگر چندین شناسهی کاربری در دسترس دارید، برای هر کدام یک- UserIdentifierجداگانه، حداکثر تا پنج شناسه، ایجاد کنید.
-  conversion_date_time
- تاریخ و زمان تبدیل. - مقدار باید دارای یک منطقه زمانی مشخص باشد و قالب آن باید - yyyy-mm-dd HH:mm:ss+|-HH:mmباشد، برای مثال:- 2022-01-01 19:32:45-05:00(زمان تابستانی در نظر گرفته نمیشود).- منطقه زمانی میتواند برای هر مقدار معتبری باشد: لازم نیست با منطقه زمانی حساب کاربری مطابقت داشته باشد. با این حال، اگر قصد دارید دادههای تبدیل وارد شده خود را با دادههای موجود در رابط کاربری گوگل ادز مقایسه کنید، توصیه میکنیم از همان منطقه زمانی حساب گوگل ادز خود استفاده کنید تا تعداد تبدیلها مطابقت داشته باشد. میتوانید جزئیات و مثالهای بیشتری را در مرکز راهنما بیابید و کدها و قالبها را برای لیستی از شناسههای منطقه زمانی معتبر بررسی کنید. 
-  conversion_action
- نام منبع - ConversionActionبرای تبدیل آفلاین.- عمل تبدیل باید از - type- UPLOAD_CLICKSباشد و باید در حساب کاربری تبدیل گوگل ادز مرتبط با کلیک، در حساب کاربری گوگل ادز وجود داشته باشد.
-  conversion_value
- ارزش تبدیل. 
-  currency_code
- کد ارز - conversion_value.
-  consent
- اکیداً توصیه میشود که فیلد - consentشیء- ClickConversionرا پر کنید. اگر تنظیم نشود، ممکن است تبدیلهای شما قابل انتساب نباشند.
-  order_id
- همچنین به عنوان شناسه تراکنش برای تبدیل شناخته میشود. این فیلد اختیاری است، اما اکیداً توصیه میشود، زیرا ارجاع به تبدیلهای وارد شده را هنگام انجام تنظیمات سادهتر میکند. اگر آن را در حین وارد کردن تنظیم کنید، باید برای هرگونه تنظیم از آن استفاده کنید. برای کسب اطلاعات بیشتر در مورد نحوه استفاده از شناسه تراکنش برای به حداقل رساندن تبدیلهای تکراری، به این مقاله مرکز راهنما مراجعه کنید. 
-  custom_variables
- مقادیر مربوط به متغیرهای تبدیل سفارشی . - گوگل ادز از متغیرهای تبدیل سفارشی در ترکیب با - wbraidیا- gbraidپشتیبانی نمیکند.
-  conversion_environment
- محیطی را نشان میدهد که این تبدیل در آن ثبت شده است. برای مثال، - APPیا- WEB.
-  session_attributes_encodedوsession_attributes_key_value_pairs
- ویژگیهای جلسه، شناسههای تجمیعی مورد استفاده برای انتساب تبدیل را نشان میدهند. این شناسهها علاوه بر GCLIDها و پارامترهای URL (مانند GBRAIDها) و دادههای ارائه شده توسط کاربر، که برای تبدیلهای بهبود یافته برای سرنخها ضروری است، کار میکنند. دو راه برای وارد کردن ویژگیهای جلسه وجود دارد: با ارائه توکن رمزگذاری شده تولید شده توسط کد جاوا اسکریپت ما در مرورگر، یا با ارائه جفتهای کلید-مقدار جداگانه برای هر یک از شناسهها. - برای به حداکثر رساندن عملکرد کمپین خود، توصیه میکنیم در صورت امکان، شناسههای کلیک، دادههای ارائه شده توسط کاربر و ویژگیهای جلسه را با تمام تبدیلهای خود وارد کنید. - جاوا- // Sets one of the sessionAttributesEncoded or sessionAttributesKeyValuePairs if either is // provided. if (rawRecord.containsKey("sessionAttributesEncoded")) { clickConversionBuilder.setSessionAttributesEncoded( ByteString.copyFromUtf8(rawRecord.get("sessionAttributesEncoded"))); } else if (rawRecord.containsKey("sessionAttributesMap")) { List<String> pairings = Arrays.stream(rawRecord.get("sessionAttributesMap").split(" ")) .map(String::trim) .collect(Collectors.toList()); SessionAttributesKeyValuePairs.Builder sessionAttributePairs = SessionAttributesKeyValuePairs.newBuilder(); for (String pair : pairings) { String[] parts = pair.split("=", 2); if (parts.length != 2) { throw new IllegalArgumentException( "Failed to read the sessionAttributesMap. SessionAttributesMap must use a " + "space-delimited list of session attribute key value pairs. Each pair should be" + " separated by an equal sign, for example: 'gad_campaignid=12345 gad_source=1'"); } sessionAttributePairs.addKeyValuePairs( SessionAttributeKeyValuePair.newBuilder() .setSessionAttributeKey(parts[0]) .setSessionAttributeValue(parts[1]) .build()); } clickConversionBuilder.setSessionAttributesKeyValuePairs(sessionAttributePairs.build()); } - سی شارپ- if (!string.IsNullOrEmpty(sessionAttributesEncoded)) { clickConversion.SessionAttributesEncoded = ByteString.CopyFrom(sessionAttributesEncoded, Encoding.Unicode); } else if (!string.IsNullOrEmpty(sessionAttributes)) { IEnumerable<SessionAttributeKeyValuePair> parsedSessionAttributes = sessionAttributes.Split(';').Select(pair => { string[] split = pair.Split('='); return new SessionAttributeKeyValuePair() { SessionAttributeKey = split[0], SessionAttributeValue = split[1] }; }); clickConversion.SessionAttributesKeyValuePairs = new SessionAttributesKeyValuePairs(); clickConversion.SessionAttributesKeyValuePairs.KeyValuePairs .AddRange(parsedSessionAttributes); } - پی اچ پی- This example is not yet available in PHP; you can take a look at the other languages.- پایتون- # Set one of the session_attributes_encoded or # session_attributes_key_value_pairs fields if either are provided. if session_attributes_encoded: click_conversion.session_attributes_encoded = session_attributes_encoded elif session_attributes_dict: for key, value in session_attributes_dict.items(): pair: SessionAttributeKeyValuePair = client.get_type( "SessionAttributeKeyValuePair" ) pair.session_attribute_key = key pair.session_attribute_value = value click_conversion.session_attributes_key_value_pairs.key_value_pairs.append( pair ) - روبی- This example is not yet available in Ruby; you can take a look at the other languages.- پرل- # Set one of the session_attributes_encoded or session_attributes_key_value_pairs # fields if either are provided. if (defined $session_attributes_encoded) { $click_conversion->{sessionAttributesEncoded} = $session_attributes_encoded; } elsif (defined $session_attributes_hash) { while (my ($key, $value) = each %$session_attributes_hash) { my $pair = Google::Ads::GoogleAds::V22::Services::ConversionUploadService::SessionAttributeKeyValuePair ->new({sessionAttributeKey => $key, sessionAttributeValue => $value}); push @{$click_conversion->{sessionAttributesKeyValuePairs}{keyValuePairs} }, $pair; } } 
-  user_ip_address
- آدرس IP مشتری هنگام ورود به صفحه فرود پس از کلیک روی تبلیغ و قبل از رویداد تبدیل. این آدرس IP دستگاه مشتری است، نه سرور تبلیغکننده. - این فیلد رشتهای است که نشاندهندهی یک آدرس IP در قالب IPv4 یا IPv6 است. برای مثال: -  آیپی نسخه ۴: "192.0.2.0"
-  IPv6: "2001:0DB8:1234:5678:9999:1111:0000:0001"
 
-  آیپی نسخه ۴: 
مثال کد
 این مثال نحوهی تنظیم دادههای نرمالسازی و هششدهی ارائه شده توسط کاربر را روی یک شیء ClickConversion نشان میدهد. 
جاوا
// Creates an empty builder for constructing the click conversion. ClickConversion.Builder clickConversionBuilder = ClickConversion.newBuilder(); // Extracts user email and phone from the raw data, normalizes and hashes it, then wraps it in // UserIdentifier objects. // Creates a separate UserIdentifier object for each. The data in this example is hardcoded, but // in your application you might read the raw data from an input file. // IMPORTANT: Since the identifier attribute of UserIdentifier // (https://developers.google.com/google-ads/api/reference/rpc/latest/UserIdentifier) is a // oneof // (https://protobuf.dev/programming-guides/proto3/#oneof-features), you must set only ONE of // hashedEmail, hashedPhoneNumber, mobileId, thirdPartyUserId, or addressInfo. Setting more // than one of these attributes on the same UserIdentifier will clear all the other members // of the oneof. For example, the following code is INCORRECT and will result in a // UserIdentifier with ONLY a hashedPhoneNumber. // // UserIdentifier incorrectlyPopulatedUserIdentifier = // UserIdentifier.newBuilder() // .setHashedEmail("...") // .setHashedPhoneNumber("...") // .build(); ImmutableMap.Builder<String, String> rawRecordBuilder = ImmutableMap.<String, String>builder() .put("email", "alex.2@example.com") // Phone number to be converted to E.164 format, with a leading '+' as required. .put("phone", "+1 800 5550102") // This example lets you put conversion details as arguments, but in reality you might // store this data alongside other user data, so we include it in this sample user // record. .put("conversionActionId", Long.toString(conversionActionId)) .put("conversionDateTime", conversionDateTime) .put("conversionValue", Double.toString(conversionValue)) .put("currencyCode", "USD"); // Adds entries for the optional fields. if (orderId != null) { rawRecordBuilder.put("orderId", orderId); } if (gclid != null) { rawRecordBuilder.put("gclid", gclid); } if (adUserDataConsent != null) { rawRecordBuilder.put("adUserDataConsent", adUserDataConsent.name()); } if (sessionAttributesEncoded != null) { rawRecordBuilder.put("sessionAttributesEncoded", sessionAttributesEncoded); } if (sessionAttributesMap != null) { rawRecordBuilder.put("sessionAttributesMap", sessionAttributesMap); } // Builds the map representing the record. Map<String, String> rawRecord = rawRecordBuilder.build(); // Creates a SHA256 message digest for hashing user identifiers in a privacy-safe way, as // described at https://support.google.com/google-ads/answer/9888656. MessageDigest sha256Digest = MessageDigest.getInstance("SHA-256"); // Creates a list for the user identifiers. List<UserIdentifier> userIdentifiers = new ArrayList<>(); // Creates a user identifier using the hashed email address, using the normalize and hash method // specifically for email addresses. UserIdentifier emailIdentifier = UserIdentifier.newBuilder() // Optional: specify the user identifier source. .setUserIdentifierSource(UserIdentifierSource.FIRST_PARTY) // Uses the normalize and hash method specifically for email addresses. .setHashedEmail(normalizeAndHashEmailAddress(sha256Digest, rawRecord.get("email"))) .build(); userIdentifiers.add(emailIdentifier); // Creates a user identifier using normalized and hashed phone info. UserIdentifier hashedPhoneNumberIdentifier = UserIdentifier.newBuilder() .setHashedPhoneNumber(normalizeAndHash(sha256Digest, rawRecord.get("phone"))) .build(); // Adds the hashed phone number identifier to the UserData object's list. userIdentifiers.add(hashedPhoneNumberIdentifier); // Adds the user identifiers to the conversion. clickConversionBuilder.addAllUserIdentifiers(userIdentifiers);
سی شارپ
// Adds a user identifier using the hashed email address, using the normalize // and hash method specifically for email addresses. clickConversion.UserIdentifiers.Add(new UserIdentifier() { HashedEmail = NormalizeAndHashEmailAddress("alex.2@example.com"), // Optional: Specifies the user identifier source. UserIdentifierSource = UserIdentifierSource.FirstParty }); // Adds a user identifier using normalized and hashed phone info. clickConversion.UserIdentifiers.Add(new UserIdentifier() { HashedPhoneNumber = NormalizeAndHash("+1 800 5550102"), // Optional: Specifies the user identifier source. UserIdentifierSource = UserIdentifierSource.FirstParty }); // Adds a user identifier with all the required mailing address elements. clickConversion.UserIdentifiers.Add(new UserIdentifier() { AddressInfo = new OfflineUserAddressInfo() { // FirstName and LastName must be normalized and hashed. HashedFirstName = NormalizeAndHash("Alex"), HashedLastName = NormalizeAndHash("Quinn"), // CountryCode and PostalCode are sent in plain text. CountryCode = "US", PostalCode = "94045" } });
پی اچ پی
// Creates a click conversion with the specified attributes. $clickConversion = new ClickConversion(); // Extract user email and phone from the raw data, normalize and hash it, then wrap it in // UserIdentifier objects. Creates a separate UserIdentifier object for each. // The data in this example is hardcoded, but in your application you might read the raw // data from an input file. // IMPORTANT: Since the identifier attribute of UserIdentifier // (https://developers.google.com/google-ads/api/reference/rpc/latest/UserIdentifier) is a // oneof // (https://protobuf.dev/programming-guides/proto3/#oneof-features), you must set only ONE // of hashedEmail, hashedPhoneNumber, mobileId, thirdPartyUserId, or addressInfo. Setting // more than one of these attributes on the same UserIdentifier will clear all the other // members of the oneof. For example, the following code is INCORRECT and will result in a // UserIdentifier with ONLY a hashedPhoneNumber. // // $incorrectlyPopulatedUserIdentifier = new UserIdentifier([ // 'hashed_email' => '...', // 'hashed_phone_number' => '...' // ]); $rawRecord = [ // Email address that includes a period (.) before the Gmail domain. 'email' => 'alex.2@example.com', // Phone number to be converted to E.164 format, with a leading '+' as required. 'phone' => '+1 800 5550102', // This example lets you input conversion details as arguments, but in reality you might // store this data alongside other user data, so we include it in this sample user // record. 'orderId' => $orderId, 'gclid' => $gclid, 'conversionActionId' => $conversionActionId, 'conversionDateTime' => $conversionDateTime, 'conversionValue' => $conversionValue, 'currencyCode' => 'USD', 'adUserDataConsent' => $adUserDataConsent, 'sessionAttributesEncoded' => $sessionAttributesEncoded, 'sessionAttributesDict' => $sessionAttributesDict ]; // Creates a list for the user identifiers. $userIdentifiers = []; // Uses the SHA-256 hash algorithm for hashing user identifiers in a privacy-safe way, as // described at https://support.google.com/google-ads/answer/9888656. $hashAlgorithm = "sha256"; // Creates a user identifier using the hashed email address, using the normalize and hash // method specifically for email addresses. $emailIdentifier = new UserIdentifier([ // Uses the normalize and hash method specifically for email addresses. 'hashed_email' => self::normalizeAndHashEmailAddress( $hashAlgorithm, $rawRecord['email'] ), // Optional: Specifies the user identifier source. 'user_identifier_source' => UserIdentifierSource::FIRST_PARTY ]); $userIdentifiers[] = $emailIdentifier; // Checks if the record has a phone number, and if so, adds a UserIdentifier for it. if (array_key_exists('phone', $rawRecord)) { $hashedPhoneNumberIdentifier = new UserIdentifier([ 'hashed_phone_number' => self::normalizeAndHash( $hashAlgorithm, $rawRecord['phone'], true ) ]); // Adds the hashed email identifier to the user identifiers list. $userIdentifiers[] = $hashedPhoneNumberIdentifier; } // Adds the user identifiers to the conversion. $clickConversion->setUserIdentifiers($userIdentifiers);
پایتون
# Extract user email and phone from the raw data, normalize and hash it, # then wrap it in UserIdentifier objects. Create a separate UserIdentifier # object for each. The data in this example is hardcoded, but in your # application you might read the raw data from an input file. # IMPORTANT: Since the identifier attribute of UserIdentifier # (https://developers.google.com/google-ads/api/reference/rpc/latest/UserIdentifier) # is a oneof # (https://protobuf.dev/programming-guides/proto3/#oneof-features), you must # set only ONE of hashed_email, hashed_phone_number, mobile_id, # third_party_user_id, or address_info. Setting more than one of these # attributes on the same UserIdentifier will clear all the other members of # the oneof. For example, the following code is INCORRECT and will result in # a UserIdentifier with ONLY a hashed_phone_number: # # incorrectly_populated_user_identifier = client.get_type("UserIdentifier") # incorrectly_populated_user_identifier.hashed_email = "..."" # incorrectly_populated_user_identifier.hashed_phone_number = "..."" raw_record: Dict[str, Union[str, float]] = { # Email address that includes a period (.) before the Gmail domain. "email": "alex.2@example.com", # Phone number to be converted to E.164 format, with a leading '+' as # required. "phone": "+1 800 5550102", # This example lets you input conversion details as arguments, # but in reality you might store this data alongside other user data, # so we include it in this sample user record. "order_id": order_id, "gclid": gclid, "conversion_action_id": conversion_action_id, "conversion_date_time": conversion_date_time, "conversion_value": conversion_value, "currency_code": "USD", "ad_user_data_consent": ad_user_data_consent, } # Constructs the click conversion. click_conversion: ClickConversion = client.get_type("ClickConversion") # Creates a user identifier using the hashed email address, using the # normalize and hash method specifically for email addresses. email_identifier: UserIdentifier = client.get_type("UserIdentifier") # Optional: Specifies the user identifier source. email_identifier.user_identifier_source = ( client.enums.UserIdentifierSourceEnum.FIRST_PARTY ) # Uses the normalize and hash method specifically for email addresses. email_identifier.hashed_email = normalize_and_hash_email_address( raw_record["email"] ) # Adds the user identifier to the conversion. click_conversion.user_identifiers.append(email_identifier) # Checks if the record has a phone number, and if so, adds a UserIdentifier # for it. if raw_record.get("phone") is not None: phone_identifier: UserIdentifier = client.get_type("UserIdentifier") phone_identifier.hashed_phone_number = normalize_and_hash( raw_record["phone"] ) # Adds the phone identifier to the conversion adjustment. click_conversion.user_identifiers.append(phone_identifier)
روبی
# Extract user email and phone from the raw data, normalize and hash it, # then wrap it in UserIdentifier objects. Create a separate UserIdentifier # object for each. The data in this example is hardcoded, but in your # application you might read the raw data from an input file. # IMPORTANT: Since the identifier attribute of UserIdentifier # (https://developers.google.com/google-ads/api/reference/rpc/latest/UserIdentifier) # is a oneof # (https://protobuf.dev/programming-guides/proto3/#oneof-features), you must # set only ONE of hashed_email, hashed_phone_number, mobile_id, # third_party_user_id, or address_info. Setting more than one of these # attributes on the same UserIdentifier will clear all the other members of # the oneof. For example, the following code is INCORRECT and will result in # a UserIdentifier with ONLY a hashed_phone_number: # # incorrectly_populated_user_identifier.hashed_email = "..."" # incorrectly_populated_user_identifier.hashed_phone_number = "..."" raw_record = { # Email address that includes a period (.) before the Gmail domain. "email" => "alex.2@example.com", # Phone number to be converted to E.164 format, with a leading '+' as # required. "phone" => "+1 800 5550102", # This example lets you input conversion details as arguments, # but in reality you might store this data alongside other user data, # so we include it in this sample user record. "order_id" => order_id, "gclid" => gclid, "conversion_action_id" => conversion_action_id, "conversion_date_time" => conversion_date_time, "conversion_value" => conversion_value, "currency_code" => "USD", "ad_user_data_consent" => ad_user_data_consent, "session_attributes_encoded" => session_attributes_encoded, "session_attributes_hash" => session_attributes_hash } click_conversion = client.resource.click_conversion do |cc| cc.conversion_action = client.path.conversion_action(customer_id, conversion_action_id) cc.conversion_date_time = conversion_date_time cc.conversion_value = conversion_value.to_f cc.currency_code = 'USD' unless order_id.nil? cc.order_id = order_id end unless raw_record["gclid"].nil? cc.gclid = gclid end # 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 raw_record["ad_user_data_consent"].nil? cc.consent = client.resource.consent do |c| c.ad_user_data = ad_user_data_consent end end # Set one of the session_attributes_encoded or # session_attributes_key_value_pairs fields if either are provided. if session_attributes_encoded != nil cc.class.module_eval { attr_accessor :session_attributes_encoded} cc.session_attributes_encoded = session_attributes_encoded elsif session_attributes_hash != nil # Add new attribute to click conversion object cc.class.module_eval { attr_accessor :session_attributes_key_value_pairs} cc.session_attributes_key_value_pairs = ::Google::Ads::GoogleAds::V19::Services::SessionAttributesKeyValuePairs.new # Loop thru inputted session_attributes_hash to populate session_attributes_key_value_pairs session_attributes_hash.each do |key, value| pair = ::Google::Ads::GoogleAds::V19::Services::SessionAttributeKeyValuePair.new pair.session_attribute_key = key pair.session_attribute_value = value cc.session_attributes_key_value_pairs.key_value_pairs << pair end end # Creates a user identifier using the hashed email address, using the # normalize and hash method specifically for email addresses. # If using a phone number, use the normalize_and_hash method instead. cc.user_identifiers << client.resource.user_identifier do |ui| ui.hashed_email = normalize_and_hash_email(raw_record["email"]) # Optional: Specifies the user identifier source. ui.user_identifier_source = :FIRST_PARTY end # Checks if the record has a phone number, and if so, adds a UserIdentifier # for it. unless raw_record["phone"].nil? cc.user_identifiers << client.resource.user_identifier do |ui| ui.hashed_phone_number = normalize_and_hash(raw_record["phone"]) end end end
پرل
# Create an empty click conversion. my $click_conversion = Google::Ads::GoogleAds::V22::Services::ConversionUploadService::ClickConversion ->new({}); # Extract user email and phone from the raw data, normalize and hash it, # then wrap it in UserIdentifier objects. Create a separate UserIdentifier # object for each. # The data in this example is hardcoded, but in your application # you might read the raw data from an input file. # # IMPORTANT: Since the identifier attribute of UserIdentifier # (https://developers.google.com/google-ads/api/reference/rpc/latest/UserIdentifier) # is a oneof # (https://protobuf.dev/programming-guides/proto3/#oneof-features), you must set # only ONE of hashed_email, hashed_phone_number, mobile_id, third_party_user_id, # or address-info. Setting more than one of these attributes on the same UserIdentifier # will clear all the other members of the oneof. For example, the following code is # INCORRECT and will result in a UserIdentifier with ONLY a hashed_phone_number: # # my $incorrect_user_identifier = Google::Ads::GoogleAds::V22::Common::UserIdentifier->new({ # hashedEmail => '...', # hashedPhoneNumber => '...', # }); my $raw_record = { # Email address that includes a period (.) before the Gmail domain. email => 'alex.2@example.com', # Phone number to be converted to E.164 format, with a leading '+' as # required. phone => '+1 800 5550102', # This example lets you input conversion details as arguments, # but in reality you might store this data alongside other user data, # so we include it in this sample user record. orderId => $order_id, gclid => $gclid, conversionActionId => $conversion_action_id, conversionDateTime => $conversion_date_time, conversionValue => $conversion_value, currencyCode => "USD", adUserDataConsent => $ad_user_data_consent }; my $user_identifiers = []; # Create a user identifier using the hashed email address, using the normalize # and hash method specifically for email addresses. my $hashed_email = normalize_and_hash_email_address($raw_record->{email}); push( @$user_identifiers, Google::Ads::GoogleAds::V22::Common::UserIdentifier->new({ hashedEmail => $hashed_email, # Optional: Specify the user identifier source. userIdentifierSource => FIRST_PARTY })); # Create a user identifier using normalized and hashed phone info. my $hashed_phone = normalize_and_hash($raw_record->{phone}); push( @$user_identifiers, Google::Ads::GoogleAds::V22::Common::UserIdentifier->new({ hashedPhone => $hashed_phone, # Optional: Specify the user identifier source. userIdentifierSource => FIRST_PARTY })); # Add the user identifiers to the conversion. $click_conversion->{userIdentifiers} = $user_identifiers;
 این مثال نحوه تنظیم سایر فیلدهای ضروری روی یک شیء ClickConversion را نشان میدهد. 
جاوا
// Adds details of the conversion. clickConversionBuilder.setConversionAction( ResourceNames.conversionAction( customerId, Long.parseLong(rawRecord.get("conversionActionId")))); clickConversionBuilder.setConversionDateTime(rawRecord.get("conversionDateTime")); clickConversionBuilder.setConversionValue(Double.parseDouble(rawRecord.get("conversionValue"))); clickConversionBuilder.setCurrencyCode(rawRecord.get("currencyCode")); // Sets the order ID if provided. if (rawRecord.containsKey("orderId")) { clickConversionBuilder.setOrderId(rawRecord.get("orderId")); } // Sets the Google click ID (gclid) if provided. if (rawRecord.containsKey("gclid")) { clickConversionBuilder.setGclid(rawRecord.get("gclid")); } // Sets the consent information, if provided. if (rawRecord.containsKey("adUserDataConsent")) { // Specifies whether user consent was obtained for the data you are uploading. See // https://www.google.com/about/company/user-consent-policy for details. clickConversionBuilder.setConsent( Consent.newBuilder() .setAdUserData(ConsentStatus.valueOf(rawRecord.get("adUserDataConsent")))); } // Sets one of the sessionAttributesEncoded or sessionAttributesKeyValuePairs if either is // provided. if (rawRecord.containsKey("sessionAttributesEncoded")) { clickConversionBuilder.setSessionAttributesEncoded( ByteString.copyFromUtf8(rawRecord.get("sessionAttributesEncoded"))); } else if (rawRecord.containsKey("sessionAttributesMap")) { List<String> pairings = Arrays.stream(rawRecord.get("sessionAttributesMap").split(" ")) .map(String::trim) .collect(Collectors.toList()); SessionAttributesKeyValuePairs.Builder sessionAttributePairs = SessionAttributesKeyValuePairs.newBuilder(); for (String pair : pairings) { String[] parts = pair.split("=", 2); if (parts.length != 2) { throw new IllegalArgumentException( "Failed to read the sessionAttributesMap. SessionAttributesMap must use a " + "space-delimited list of session attribute key value pairs. Each pair should be" + " separated by an equal sign, for example: 'gad_campaignid=12345 gad_source=1'"); } sessionAttributePairs.addKeyValuePairs( SessionAttributeKeyValuePair.newBuilder() .setSessionAttributeKey(parts[0]) .setSessionAttributeValue(parts[1]) .build()); } clickConversionBuilder.setSessionAttributesKeyValuePairs(sessionAttributePairs.build()); } // Calls build to build the conversion. ClickConversion clickConversion = clickConversionBuilder.build();
سی شارپ
// Adds details of the conversion. clickConversion.ConversionAction = ResourceNames.ConversionAction(customerId, conversionActionId); clickConversion.ConversionDateTime = conversionDateTime; clickConversion.ConversionValue = conversionValue; clickConversion.CurrencyCode = "USD"; // Sets the order ID if provided. if (!string.IsNullOrEmpty(orderId)) { clickConversion.OrderId = orderId; } // Sets the Google click ID (gclid) if provided. if (!string.IsNullOrEmpty(gclid)) { clickConversion.Gclid = gclid; } if (!string.IsNullOrEmpty(sessionAttributesEncoded)) { clickConversion.SessionAttributesEncoded = ByteString.CopyFrom(sessionAttributesEncoded, Encoding.Unicode); } else if (!string.IsNullOrEmpty(sessionAttributes)) { IEnumerable<SessionAttributeKeyValuePair> parsedSessionAttributes = sessionAttributes.Split(';').Select(pair => { string[] split = pair.Split('='); return new SessionAttributeKeyValuePair() { SessionAttributeKey = split[0], SessionAttributeValue = split[1] }; }); clickConversion.SessionAttributesKeyValuePairs = new SessionAttributesKeyValuePairs(); clickConversion.SessionAttributesKeyValuePairs.KeyValuePairs .AddRange(parsedSessionAttributes); }
پی اچ پی
// Adds details of the conversion. $clickConversion->setConversionAction( ResourceNames::forConversionAction($customerId, $rawRecord['conversionActionId']) ); $clickConversion->setConversionDateTime($rawRecord['conversionDateTime']); $clickConversion->setConversionValue($rawRecord['conversionValue']); $clickConversion->setCurrencyCode($rawRecord['currencyCode']); // Sets the order ID if provided. if (!empty($rawRecord['orderId'])) { $clickConversion->setOrderId($rawRecord['orderId']); } // Sets the Google click ID (gclid) if provided. if (!empty($rawRecord['gclid'])) { $clickConversion->setGclid($rawRecord['gclid']); } // Sets the ad user data consent if provided. if (!empty($rawRecord['adUserDataConsent'])) { // 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->setConsent( new Consent(['ad_user_data' => $rawRecord['adUserDataConsent']]) ); } // Set one of the sessionAttributesEncoded or // SessionAttributeKeyValuePair fields if either are provided. if (!empty($sessionAttributesEncoded)) { $clickConversion->setSessionAttributesEncoded($sessionAttributesEncoded); } elseif (!empty($sessionAttributesDict)) { // Create a new container object to hold key-value pairs. $sessionAttributesKeyValuePairs = new SessionAttributesKeyValuePairs(); // Initialize an array to hold individual key-value pair messages. $keyValuePairs = []; // Append each key-value pair provided to the $keyValuePairs array foreach ($sessionAttributesDict as $key => $value) { $pair = new SessionAttributeKeyValuePair(); $pair->setSessionAttributeKey($key); $pair->setSessionAttributeValue($value); $keyValuePairs[] = $pair; } // Set the the full list of key-value pairs on the container object. $sessionAttributesKeyValuePairs->setKeyValuePairs($keyValuePairs); // Attach the container of key-value pairs to the ClickConversion object. $clickConversion->setSessionAttributesKeyValuePairs($sessionAttributesKeyValuePairs); }
پایتون
# Add details of the conversion. # Gets the conversion action resource name. conversion_action_service: ConversionActionServiceClient = ( client.get_service("ConversionActionService") ) click_conversion.conversion_action = ( conversion_action_service.conversion_action_path( customer_id, raw_record["conversion_action_id"] ) ) click_conversion.conversion_date_time = raw_record["conversion_date_time"] click_conversion.conversion_value = raw_record["conversion_value"] click_conversion.currency_code = raw_record["currency_code"] # Sets the order ID if provided. if raw_record.get("order_id"): click_conversion.order_id = raw_record["order_id"] # Sets the gclid if provided. if raw_record.get("gclid"): click_conversion.gclid = raw_record["gclid"] # 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 if raw_record["ad_user_data_consent"]: click_conversion.consent.ad_user_data = client.enums.ConsentStatusEnum[ raw_record["ad_user_data_consent"] ] # Set one of the session_attributes_encoded or # session_attributes_key_value_pairs fields if either are provided. if session_attributes_encoded: click_conversion.session_attributes_encoded = session_attributes_encoded elif session_attributes_dict: for key, value in session_attributes_dict.items(): pair: SessionAttributeKeyValuePair = client.get_type( "SessionAttributeKeyValuePair" ) pair.session_attribute_key = key pair.session_attribute_value = value click_conversion.session_attributes_key_value_pairs.key_value_pairs.append( pair )
روبی
cc.conversion_action = client.path.conversion_action(customer_id, conversion_action_id) cc.conversion_date_time = conversion_date_time cc.conversion_value = conversion_value.to_f cc.currency_code = 'USD' unless order_id.nil? cc.order_id = order_id end unless raw_record["gclid"].nil? cc.gclid = gclid end # 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 raw_record["ad_user_data_consent"].nil? cc.consent = client.resource.consent do |c| c.ad_user_data = ad_user_data_consent end end # Set one of the session_attributes_encoded or # session_attributes_key_value_pairs fields if either are provided. if session_attributes_encoded != nil cc.class.module_eval { attr_accessor :session_attributes_encoded} cc.session_attributes_encoded = session_attributes_encoded elsif session_attributes_hash != nil # Add new attribute to click conversion object cc.class.module_eval { attr_accessor :session_attributes_key_value_pairs} cc.session_attributes_key_value_pairs = ::Google::Ads::GoogleAds::V19::Services::SessionAttributesKeyValuePairs.new # Loop thru inputted session_attributes_hash to populate session_attributes_key_value_pairs session_attributes_hash.each do |key, value| pair = ::Google::Ads::GoogleAds::V19::Services::SessionAttributeKeyValuePair.new pair.session_attribute_key = key pair.session_attribute_value = value cc.session_attributes_key_value_pairs.key_value_pairs << pair end end
پرل
# Add details of the conversion. $click_conversion->{conversionAction} = Google::Ads::GoogleAds::V22::Utils::ResourceNames::conversion_action( $customer_id, $raw_record->{conversionActionId}); $click_conversion->{conversionDateTime} = $raw_record->{conversionDateTime}; $click_conversion->{conversionValue} = $raw_record->{conversionValue}; $click_conversion->{currencyCode} = $raw_record->{currencyCode}; # Set the order ID if provided. if (defined $raw_record->{orderId}) { $click_conversion->{orderId} = $raw_record->{orderId}; } # Set the Google click ID (gclid) if provided. if (defined $raw_record->{gclid}) { $click_conversion->{gclid} = $raw_record->{gclid}; } # Set the consent information, if provided. if (defined $raw_record->{adUserDataConsent}) { $click_conversion->{consent} = Google::Ads::GoogleAds::V22::Common::Consent->new({ adUserData => $raw_record->{adUserDataConsent}}); } # Set one of the session_attributes_encoded or session_attributes_key_value_pairs # fields if either are provided. if (defined $session_attributes_encoded) { $click_conversion->{sessionAttributesEncoded} = $session_attributes_encoded; } elsif (defined $session_attributes_hash) { while (my ($key, $value) = each %$session_attributes_hash) { my $pair = Google::Ads::GoogleAds::V22::Services::ConversionUploadService::SessionAttributeKeyValuePair ->new({sessionAttributeKey => $key, sessionAttributeValue => $value}); push @{$click_conversion->{sessionAttributesKeyValuePairs}{keyValuePairs} }, $pair; } }
ساخت درخواست
 پس از پیکربندی اشیاء ClickConversion و اضافه شدن آنها به فیلد conversions شیء UploadClickConversionRequest ، فیلدهای زیر را تنظیم کرده و درخواست را به متد UploadClickConversions در ConversionUploadService ارسال کنید.
-  customer_id
-  این را روی مشتری تبدیل گوگل ادز حسابی که منبع کلیکها است تنظیم کنید. اگر مطمئن نیستید کدام حساب درست است، به فیلد customer.conversion_tracking_setting.google_ads_conversion_customerدر مثال کوئری در بخش شروع به کار مراجعه کنید.
-  job_id
- مکانیزمی برای مرتبط کردن درخواستهای ورودی شما با اطلاعات مربوط به هر کار در تشخیص دادههای آفلاین ارائه میدهد. - اگر این فیلد را تنظیم نکنید، API گوگل ادز به هر درخواست یک مقدار منحصر به فرد در محدوده - [2^31, 2^63)اختصاص میدهد. اگر ترجیح میدهید چندین درخواست را در یک کار منطقی گروهبندی کنید، این فیلد را برای هر درخواست در کار خود روی یک مقدار یکسان در محدوده- [0, 2^31)تنظیم کنید.- job_idدر پاسخ، صرف نظر از اینکه شما مقداری را مشخص کردهاید یا اجازه دادهاید که API تبلیغات گوگل مقداری را اختصاص دهد، حاوی شناسه کار برای درخواست است.
-  partial_failure
- هنگام وارد کردن تبدیلها، این فیلد باید روی - trueتنظیم شود. هنگام پردازش پاسخ ، دستورالعملهای مربوط به خرابیهای جزئی را دنبال کنید.
درخواست را وارد کنید
 پس از اینکه اشیاء ClickConversion خود را پر کردید و درخواست خود را ساختید، میتوانید ایمپورت خود را ارسال کنید. 
جاوا
// Creates the conversion upload service client. try (ConversionUploadServiceClient conversionUploadServiceClient = googleAdsClient.getLatestVersion().createConversionUploadServiceClient()) { // Uploads the click conversion. Partial failure should always be set to true. // NOTE: This request contains a single conversion as a demonstration. However, if you have // multiple conversions to upload, it's best to upload multiple conversions per request // instead of sending a separate request per conversion. See the following for per-request // limits: // https://developers.google.com/google-ads/api/docs/best-practices/quotas#conversion_upload_service UploadClickConversionsResponse response = conversionUploadServiceClient.uploadClickConversions( UploadClickConversionsRequest.newBuilder() .setCustomerId(Long.toString(customerId)) .addConversions(clickConversion) // Enables partial failure (must be true). .setPartialFailure(true) .build());
سی شارپ
// Uploads the click conversion. Partial failure should always be set to true. // NOTE: This request contains a single conversion as a demonstration. // However, if you have multiple conversions to upload, it's best to upload multiple // conversions per request instead of sending a separate request per conversion. // See the following for per-request limits: // https://developers.google.com/google-ads/api/docs/best-practices/quotas#conversion_upload UploadClickConversionsResponse response = conversionUploadService.UploadClickConversions( new UploadClickConversionsRequest() { CustomerId = customerId.ToString(), Conversions = { clickConversion }, // Enables partial failure (must be true). PartialFailure = true });
پی اچ پی
// Issues a request to upload the click conversion. $conversionUploadServiceClient = $googleAdsClient->getConversionUploadServiceClient(); // NOTE: This request contains a single conversion as a demonstration. However, if you have // multiple conversions to upload, it's best to upload multiple conversions per request // instead of sending a separate request per conversion. See the following for per-request // limits: // https://developers.google.com/google-ads/api/docs/best-practices/quotas#conversion_upload_service $response = $conversionUploadServiceClient->uploadClickConversions( // Enables partial failure (must be true). UploadClickConversionsRequest::build($customerId, [$clickConversion], true) );
پایتون
# Creates the conversion upload service client. conversion_upload_service: ConversionUploadServiceClient = ( client.get_service("ConversionUploadService") ) # Uploads the click conversion. Partial failure should always be set to # True. # NOTE: This request only uploads a single conversion, but if you have # multiple conversions to upload, it's most efficient to upload them in a # single request. See the following for per-request limits for reference: # https://developers.google.com/google-ads/api/docs/best-practices/quotas#conversion_upload_service response: UploadClickConversionsResponse = ( conversion_upload_service.upload_click_conversions( customer_id=customer_id, conversions=[click_conversion], # Enables partial failure (must be true). partial_failure=True, ) )
روبی
response = client.service.conversion_upload.upload_click_conversions( customer_id: customer_id, conversions: [click_conversion], # Partial failure must be true. partial_failure: true, ) if response.partial_failure_error puts "Partial failure encountered: #{response.partial_failure_error.message}" else result = response.results.first puts "Uploaded click conversion that happened at #{result.conversion_date_time} " \ "to #{result.conversion_action}." end
پرل
# Upload the click conversion. Partial failure should always be set to true. # # NOTE: This request contains a single conversion as a demonstration. # However, if you have multiple conversions to upload, it's best to # upload multiple conversions per request instead of sending a separate # request per conversion. See the following for per-request limits: # https://developers.google.com/google-ads/api/docs/best-practices/quotas#conversion_upload_service my $response = $api_client->ConversionUploadService()->upload_click_conversions({ customerId => $customer_id, conversions => [$click_conversion], # Enable partial failure (must be true). partialFailure => "true" });
واردات خود را بررسی کنید
از گزارش تشخیص پیشرفته تبدیلها برای سرنخها برای بررسی سلامت کلی واردات اخیر خود استفاده کنید.
 تبدیلهای وارد شده در گزارشها برای تاریخ نمایش کلیک اصلی منعکس میشوند، نه تاریخ درخواست وارد کردن یا تاریخ conversion_date_time مربوط به ClickConversion .
نمایش آمار تبدیل وارد شده در حساب گوگل ادز شما برای انتساب آخرین کلیک، تا سه ساعت طول میکشد. برای سایر مدلهای انتساب جستجو، میتواند بیش از سه ساعت طول بکشد. برای اطلاعات بیشتر به راهنمای تازگی دادهها مراجعه کنید.
 هنگام گزارشدهی در مورد معیارهای تبدیل برای کمپینهای خود، به نگاشت معیارهای رابط کاربری مراجعه کنید تا معیارهای رابط کاربری گوگل ادز را با فیلدهای گزارشدهی API گوگل ادز مرتبط کنید. همچنین میتوانید از منبع conversion_action برای مشاهده تعداد کل تبدیلها و کل ارزش تبدیل برای یک اقدام تبدیل مشخص، کوئری بگیرید.
بهترین شیوهها
هنگام پیادهسازی تبدیلهای بهبود یافته برای سرنخها، بهترین شیوههای زیر را در نظر داشته باشید.
ارسال تمام دادههای تبدیل صرف نظر از کامل بودن آنها
برای اطمینان از گزارش کامل و دقیق تبدیل، تمام رویدادهای تبدیل آفلاین موجود، از جمله مواردی که ممکن است از Google Ads نیامده باشند را وارد کنید. تبدیلهایی که فقط شامل دادههای ارائه شده توسط کاربر هستند، هنوز مفید هستند و میتوانند به بهینهسازی کمپین Google Ads کمک کنند.
 اگر به یک تبدیل، order_id اختصاص میدهید، توصیه میکنیم آن را نیز اضافه کنید. اگر GCLID مربوط به یک تبدیل را دارید، برای بهبود عملکرد، توصیه میکنیم آن را علاوه بر user_identifiers ارسال کنید. علاوه بر این، اگر بیش از یک UserIdentifier برای تبدیل دارید، همه آنها را در شیء ClickConversion قرار دهید تا احتمال تطابق افزایش یابد.
تبدیلهای چندگانه را در یک درخواست واحد دستهبندی کنید
 اگر چندین تبدیل برای وارد کردن دارید، به جای ارسال یک درخواست واردات برای هر تبدیل، تبدیلها را در یک UploadClickConversionsRequest دستهبندی کنید.
برای اطلاع از محدودیتهای تعداد تبدیلها در هر درخواست، راهنمای سهمیهبندی را بررسی کنید.
 اگر میخواهید تشخیص دادههای آفلاین، مجموعهای از درخواستها را تحت یک کار منطقی گروهبندی کند، job_id همه درخواستها را روی یک مقدار یکسان تنظیم کنید. این میتواند در صورتی مفید باشد که یک کار یا فرآیند واحد دارید که تعداد زیادی تبدیل را با استفاده از چندین درخواست وارد میکند. اگر job_id را روی هر یک از این درخواستها روی یک مقدار یکسان تنظیم کنید، میتوانید یک ورودی واحد برای کار را از job_summaries بازیابی کنید. اگر به جای آن، به API گوگل ادز اجازه دهید یک مقدار تولید شده توسط سیستم را به job_id هر درخواست اختصاص دهد، job_summaries شامل یک ورودی جداگانه برای هر درخواست است که میتواند تجزیه و تحلیل سلامت کلی کار شما را چالش برانگیزتر کند.
از دادههای انتساب خارجی استفاده نکنید
 هنگام استفاده از تبدیلهای پیشرفته برای سرنخها، external_attribution_data روی ClickConversion تنظیم نکنید یا conversion_action ای را مشخص نکنید که از یک مدل انتساب خارجی استفاده کند. گوگل ادز از تبدیلهای دارای انتساب خارجی برای وارد کردن با استفاده از دادههای ارائه شده توسط کاربر پشتیبانی نمیکند.
متغیرهای سفارشی را وارد نکنید
 هنگام استفاده از تبدیلهای پیشرفته برای سرنخها، هیچ custom_variables وارد نکنید. گوگل ادز از استفاده از متغیرهای سفارشی با دادههای ارائه شده توسط کاربر در وارد کردن تبدیلها پشتیبانی نمیکند. اگر متغیرهای سفارشی با تبدیلهایی که حاوی دادههای ارائه شده توسط کاربر هستند، گنجانده شوند، آن تبدیلها نامعتبر تلقی شده و حذف میشوند.
عیبیابی
 تشخیص آفلاین دادهها، منبعی واحد برای بررسی سلامت کلی دادههای وارد شده شما به صورت مداوم فراهم میکند. با این حال، در طول پیادهسازی میتوانید از اطلاعات این بخش برای بررسی هرگونه خطای گزارش شده در فیلد partial_failure_error پاسخ استفاده کنید.
 برخی از رایجترین خطاها هنگام وارد کردن اقدامات تبدیل، خطاهای مجوز مانند USER_PERMISSION_DENIED هستند. دوباره بررسی کنید که شناسه مشتری در درخواست شما روی مشتری تبدیل Google Ads که مالک اقدام تبدیل است، تنظیم شده باشد. برای جزئیات بیشتر به راهنمای مجوز ما مراجعه کنید و برای نکاتی در مورد نحوه اشکالزدایی این خطاهای مختلف، به راهنمای خطاهای رایج ما مراجعه کنید.
اشکالزدایی خطاهای رایج
| خطا | |
|---|---|
| NO_CONVERSION_ACTION_FOUND | اقدام تبدیل مشخصشده یا فعال نیست، یا توسط حساب کاربری مشخصشده توسط فیلد `client_id` در درخواست قابل دسترسی نیست. مطمئن شوید که اقدام تبدیل در آپلود شما فعال است و متعلق به مشتری ارسالکننده درخواست آپلود است.  این خطا همچنین ممکن است در صورتی رخ دهد که GCLID موجود در درخواست متعلق به یک حساب کاربری باشد که به عمل تبدیل مشخص شده در درخواست دسترسی ندارد. شما میتوانید با ارسال یک پرسوجو که  | 
| INVALID_CONVERSION_ACTION_TYPE | نوع عمل تبدیل مشخص شده برای تبدیلهای پیشرفته برای سرنخها معتبر نیست. مطمئن شوید که ConversionActionمشخص شده در درخواست آپلود شما از نوعUPLOAD_CLICKSباشد. | 
| CUSTOMER_NOT_ENABLED_ENHANCED_CONVERSIONS_FOR_LEADS | مطمئن شوید که در تنظیمات تبدیل، تبدیلهای پیشرفته برای سرنخها را فعال کردهاید. دستورالعملهای مربوط به این مورد را در راهنمای پیشنیازها بیابید. | 
| DUPLICATE_ORDER_ID | رویدادهای وارد شده شامل چندین تبدیل با شناسه سفارش یکسان هستند و پردازش نشدهاند. مطمئن شوید که شناسههای سفارش منحصر به فرد هستند و دوباره امتحان کنید. | 
| CLICK_NOT_FOUND | هیچ کلیکی مطابق با شناسههای کاربری ارائه شده یافت نشد. API تبلیغات گوگل فقط در صورتی این خطا را برمیگرداند که debug_enabledدرUploadClickConversionsRequesttrueداشته باشد. اگر یک تبدیل با این هشدار مواجه شود، API گوگل ادز آن را در  اگر کلیک از یک کمپین تبلیغات گوگل نباشد، این خطا قابل انتظار است. برای مثال، ممکن است از SA360 یا DV360 باشد. سایر علل احتمالی به شرح زیر است: 
 در موارد نادری که مشتری آپلودکننده با مشتری تبدیل گوگل ادز متفاوت است، این خطا میتواند به این معنی باشد که مشتری آپلودکننده شرایط دادههای مشتری را پذیرفته است، اما مشتری ارائهدهنده خدمات این شرایط را نپذیرفته است.شما میتوانید با پرسوجو از منبع customerو بررسی فیلدcustomer.offline_conversion_tracking_info.accepted_customer_data_terms، تشخیص دهید که آیا یک حساب کاربری شرایط دادههای مشتری را پذیرفته است یا خیر. |