คุณสามารถใช้ Google Ads API เพื่อนําเข้า Conversion การโทรแบบออฟไลน์ไปยัง Google Ads เพื่อติดตามว่าเมื่อใดที่โฆษณานําไปสู่การโทร และเมื่อใดที่การโทรเหล่านั้นนําไปสู่ การกระทําที่มีคุณค่าของลูกค้า
การแมปกับ UI ของ Google Ads จะเหมือนกับการใช้แหล่งที่มาของ Conversion การอัปโหลด ตามด้วยการเลือก Conversion จากการโทร
สร้าง Conversion จากการโทร
สิ่งที่ควรคำนึงถึงเมื่อสร้าง CallConversion มีดังนี้
คุณต้องป้อนข้อมูลในช่อง
consentของออบเจ็กต์CallConversionแอตทริบิวต์
partial_failureของUploadCallConversionsRequestควรตั้งค่าเป็นtrueเสมอ ปฏิบัติตามหลักเกณฑ์เกี่ยวกับความล้มเหลวบางส่วนเมื่อจัดการการดำเนินการที่ถูกต้องและการดำเนินการที่ไม่สำเร็จพร้อมกันหากคุณได้รับข้อความตอบกลับ
TOO_RECENT_CONVERSION_ACTIONหรือTOO_RECENT_CALLสำหรับคำขอการนำเข้า Conversion ให้รอ 6 ชั่วโมงหรือ 12 ชั่วโมง ตามลำดับ ก่อนที่จะลองแถวที่ล้มเหลวอีกครั้งระบบใช้เวลาสูงสุด 3 ชั่วโมงในการแสดงสถิติ Conversion ที่นำเข้าในบัญชี Google Ads
- หากคำขอเดียวมีการดำเนินการหลายรายการสำหรับ Conversion เดียวกัน ระบบจะแสดง
DUPLICATE_CALL_CONVERSION_IN_REQUESTข้อผิดพลาด
- หากคำขอเดียวมีการดำเนินการหลายรายการสำหรับ Conversion เดียวกัน ระบบจะแสดง
หากผู้ใช้คัดลอกหมายเลขโอนสายของ Google ด้วยตนเองและโทรหาหมายเลขดังกล่าว ระบบจะบันทึก Conversion ไม่ได้
นำเข้า Conversion การโทร
หากต้องการเชื่อมโยง Conversion การโทรแบบออฟไลน์กับการกระทำที่ถือเป็น Conversion คุณต้องมีข้อมูลต่อไปนี้ หมายเลขผู้โทร (หมายเลขโทรศัพท์) วันที่และเวลาที่เกิด Conversion ชื่อทรัพยากรของการกระทำที่ถือเป็น Conversion และมูลค่า Conversion และสกุลเงิน (ไม่บังคับ) ไปยัง ConversionUploadService
ดูรายละเอียดเพิ่มเติมเกี่ยวกับอินพุตต่างๆ ได้ที่บทความในศูนย์ช่วยเหลือ ตัวอย่างโค้ดยังอธิบายรูปแบบสำหรับอินพุตต่างๆ ด้วย
ข้อกำหนด
คุณต้องปฏิบัติตามข้อกำหนดต่อไปนี้เมื่อนำเข้าCallConversion
หากต้องการหลีกเลี่ยงข้อผิดพลาด ConversionUploadError.INVALID_CONVERSION_ACTION แอตทริบิวต์
conversion_action
ต้องอ้างอิงถึง ConversionAction ที่มีลักษณะดังนี้
ConversionActionTypeคือUPLOAD_CALLSstatusของConversionActionคือENABLEDมิฉะนั้น การดำเนินการจะล้มเหลวพร้อมข้อผิดพลาดNO_CONVERSION_ACTION_FOUNDConversionActionอยู่ในลูกค้า Conversion ของ Google Ads ของบัญชี Google Ads ของการคลิก
นอกจากนี้ เราขอแนะนำให้ตั้งค่า
ConversionAction.category เป็น
หมวดหมู่ที่อธิบาย Conversion ได้ดีที่สุดด้วย
นอกจากนี้ ยังต้องเป็นไปตามเงื่อนไขต่อไปนี้ด้วย
ในขณะที่โทร มีการเปิดใช้เครื่องมือวัด Conversion ใน ลูกค้า Conversion ของ Google Ads ของบัญชี Google Ads ของการโทร
customer_idของUploadCallConversionsRequestต้องเป็นรหัสลูกค้าของลูกค้า Conversion ของ Google Adsของ บัญชี Google Ads ของการโทร ไม่เช่นนั้น การนําเข้า Conversion จะทําให้เกิดข้อผิดพลาดConversionUploadError.INVALID_CUSTOMER_FOR_CALLconversion_valueต้องมากกว่าหรือเท่ากับ 0conversion_date_timeต้องมีการระบุเขตเวลา และรูปแบบเป็นyyyy-mm-dd HH:mm:ss+|-HH:mmเช่น2022-01-01 19:32:45-05:00(ไม่สนใจเวลาออมแสง) เขตเวลาอาจเป็นค่าที่ถูกต้องใดก็ได้ โดยไม่จำเป็นต้องตรงกับเขตเวลาของบัญชี อย่างไรก็ตาม หากคุณวางแผนที่จะเปรียบเทียบข้อมูล Conversion ที่นําเข้ากับข้อมูลใน UI ของ Google Ads เราขอแนะนําให้ใช้เขตเวลาเดียวกันกับบัญชี Google Ads เพื่อให้จํานวน Conversion ตรงกัน
ตัวอย่างโค้ด
Java
private void runExample( GoogleAdsClient googleAdsClient, long customerId, String conversionActionId, String callerId, String callStartDateTime, double conversionValue, Long conversionCustomVariableId, String conversionCustomVariableValue, ConsentStatus adUserDataConsent) { // Create a call conversion by specifying currency as USD. CallConversion.Builder conversionBuilder = CallConversion.newBuilder() .setConversionAction(conversionActionId) .setCallerId(callerId) .setCallStartDateTime(callStartDateTime) .setConversionValue(conversionValue) .setCurrencyCode("USD"); if (conversionCustomVariableId != null && conversionCustomVariableValue != null) { conversionBuilder.addCustomVariables( CustomVariable.newBuilder() .setConversionCustomVariable( ResourceNames.conversionCustomVariable(customerId, conversionCustomVariableId)) .setValue(conversionCustomVariableValue)); } // 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. conversionBuilder.setConsent(Consent.newBuilder().setAdUserData(adUserDataConsent)); } CallConversion conversion = conversionBuilder.build(); // Uploads the call conversion to the API. try (ConversionUploadServiceClient conversionUploadServiceClient = googleAdsClient.getLatestVersion().createConversionUploadServiceClient()) { // Partial failure MUST be enabled for this request. // 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 UploadCallConversionsResponse response = conversionUploadServiceClient.uploadCallConversions( UploadCallConversionsRequest.newBuilder() .setCustomerId(String.valueOf(customerId)) .setCustomerId(Long.toString(customerId)) .addConversions(conversion) .setPartialFailure(true) .build()); // Prints any partial failure errors returned. if (response.hasPartialFailureError()) { GoogleAdsFailure googleAdsFailure = ErrorUtils.getInstance().getGoogleAdsFailure(response.getPartialFailureError()); googleAdsFailure .getErrorsList() .forEach(e -> System.out.println("Partial failure occurred: " + e.getMessage())); throw new RuntimeException( "Partial failure occurred " + response.getPartialFailureError().getMessage()); } // Prints the result if valid. CallConversionResult result = response.getResults(0); System.out.printf( "Uploaded call conversion that occurred at '%' for caller ID '%' to the conversion" + " action with resource name '%'.%n", result.getCallStartDateTime(), result.getCallerId(), result.getConversionAction()); } }
C#
public void Run(GoogleAdsClient client, long customerId, long conversionActionId, string callerId, string callStartTime, string conversionTime, double conversionValue, long? conversionCustomVariableId, string conversionCustomVariableValue, ConsentStatus? adUserDataConsent) { // Get the ConversionUploadService. ConversionUploadServiceClient conversionUploadService = client.GetService(Services.V22.ConversionUploadService); // Create a call conversion by specifying currency as USD. CallConversion callConversion = new CallConversion() { ConversionAction = ResourceNames.ConversionAction(customerId, conversionActionId), CallerId = callerId, CallStartDateTime = callStartTime, ConversionDateTime = conversionTime, ConversionValue = conversionValue, CurrencyCode = "USD", }; 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. callConversion.Consent = new Consent() { AdUserData = (ConsentStatus)adUserDataConsent }; } if (conversionCustomVariableId != null && !string.IsNullOrEmpty(conversionCustomVariableValue)) { callConversion.CustomVariables.Add(new CustomVariable() { ConversionCustomVariable = ResourceNames.ConversionCustomVariable( customerId, conversionCustomVariableId.Value), Value = conversionCustomVariableValue }); } UploadCallConversionsRequest request = new UploadCallConversionsRequest() { CustomerId = customerId.ToString(), Conversions = { callConversion }, PartialFailure = true }; try { // Issues a request to upload the call conversion. The partialFailure parameter // is set to true, and validateOnly parameter to false as required by this method // call. // 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 UploadCallConversionsResponse response = conversionUploadService.UploadCallConversions(request); // Since we set partialFailure = true, we can retrieve error messages (if any) from // the operation response. if (response.PartialFailureError != null) { Console.WriteLine("Call conversion upload failed."); // Retrieves the errors from the partial failure and prints them. List<GoogleAdsError> errors = response.PartialFailure.GetErrorsByOperationIndex(0); foreach (GoogleAdsError error in errors) { Console.WriteLine($"Operation failed with error: {error}."); } } else { // Prints the result. CallConversionResult uploadedCallConversion = response.Results[0]; Console.WriteLine($"Uploaded call conversion that occurred at " + $"'{uploadedCallConversion.CallStartDateTime}' for caller ID " + $"'{uploadedCallConversion.CallerId}' to the conversion action with " + $"resource name '{uploadedCallConversion.ConversionAction}'."); } } catch (GoogleAdsException e) { Console.WriteLine("Failure:"); Console.WriteLine($"Message: {e.Message}"); Console.WriteLine($"Failure: {e.Failure}"); Console.WriteLine($"Request ID: {e.RequestId}"); throw; } }
PHP
public static function runExample( GoogleAdsClient $googleAdsClient, int $customerId, int $conversionActionId, string $callerId, string $callStartDateTime, string $conversionDateTime, float $conversionValue, ?string $conversionCustomVariableId, ?string $conversionCustomVariableValue, ?int $adUserDataConsent ) { // Creates a call conversion by specifying currency as USD. $callConversion = new CallConversion([ 'conversion_action' => ResourceNames::forConversionAction($customerId, $conversionActionId), 'caller_id' => $callerId, 'call_start_date_time' => $callStartDateTime, 'conversion_date_time' => $conversionDateTime, 'conversion_value' => $conversionValue, 'currency_code' => 'USD' ]); if (!is_null($conversionCustomVariableId) && !is_null($conversionCustomVariableValue)) { $callConversion->setCustomVariables([new CustomVariable([ 'conversion_custom_variable' => ResourceNames::forConversionCustomVariable( $customerId, $conversionCustomVariableId ), 'value' => $conversionCustomVariableValue ])]); } // Sets the consent information, if provided. if (!empty($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. $callConversion->setConsent(new Consent(['ad_user_data' => $adUserDataConsent])); } // Issues a request to upload the call 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->uploadCallConversions( // Partial failure MUST be enabled for this request. UploadCallConversionsRequest::build($customerId, [$callConversion], true) ); // Prints the status message if any partial failure error is returned. // Note: The details of each partial failure error are not printed here, you can refer to // the example HandlePartialFailure.php to learn more. if ($response->hasPartialFailureError()) { printf( "Partial failures occurred: '%s'.%s", $response->getPartialFailureError()->getMessage(), PHP_EOL ); } else { // Prints the result if exists. /** @var CallConversionResult $uploadedCallConversion */ $uploadedCallConversion = $response->getResults()[0]; printf( "Uploaded call conversion that occurred at '%s' for caller ID '%s' to the " . "conversion action with resource name '%s'.%s", $uploadedCallConversion->getCallStartDateTime(), $uploadedCallConversion->getCallerId(), $uploadedCallConversion->getConversionAction(), PHP_EOL ); } }