สร้างการกระทําที่ถือเป็น Conversion

คู่มือนี้แสดงรายการการกระทำที่ถือเป็น Conversion ประเภทต่างๆ ที่คุณสร้างได้โดยใช้ Google Ads API, ข้อมูลเกี่ยวกับวิธีแมปเหล่านี้กับอินเทอร์เฟซเว็บ Google Ads และตัวอย่างโค้ดโดยละเอียดที่สาธิตวิธีสร้างการกระทำที่ถือเป็น Conversion ใหม่

หากต้องการวัด Conversion ให้ตั้งค่า ConversionAction สำหรับ type ของการกระทำที่ถือเป็น Conversion ที่คุณต้องการติดตาม ตัวอย่างเช่น การซื้อออนไลน์และการโทร ต้องใช้การกระทำที่ถือเป็น Conversion ที่ต่างกัน

วิธีที่ดีที่สุดในการตั้งค่าการกระทำที่ถือเป็น Conversion ใหม่ใน API คือการใช้ตัวอย่างโค้ดการกระทำที่ถือเป็น Conversion ด้านล่าง ตัวอย่างนี้จะจัดการงานการตรวจสอบสิทธิ์ในเบื้องหลังทั้งหมดให้คุณ และอธิบายวิธีสร้างConversionAction

การกระทำที่ถือเป็น Conversion ส่วนใหญ่ต้องมีขั้นตอนเพิ่มเติมเพื่อติดตามด้วย เช่น หากต้องการติดตาม Conversion ในเว็บไซต์ คุณต้องเพิ่มข้อมูลโค้ดที่เรียกว่าแท็กลงในหน้า Conversion ของเว็บไซต์ ดูข้อกำหนดอื่นๆ ของการกระทำที่ถือเป็น Conversion ได้ที่บทความในศูนย์ช่วยเหลือ

Conversion ของเว็บไซต์

Conversion ในเว็บไซต์ช่วยให้คุณติดตามการกระทำในเว็บไซต์ได้ เช่น การขายออนไลน์ การคลิกลิงก์ การดูหน้าเว็บ และการลงชื่อสมัครใช้

หากต้องการติดตาม Conversion ในเว็บไซต์ คุณต้องสร้าง ConversionAction ที่มี ConversionActionType ที่ตั้งค่าเป็น WEBPAGE และเพิ่มข้อมูลโค้ดที่เรียกว่าแท็กลงในหน้า Conversion บนเว็บไซต์

ConversionAction ประกอบด้วย Conversion ในเว็บไซต์หลายประเภท ซึ่งจำแนกภายใน API ตามช่อง type ในแต่ละ TagSnippet ที่ระบุไว้ในช่อง tag_snippets ของ ConversionAction

TagSnippet ให้โค้ดติดตามที่ต้องรวมอยู่ในเว็บไซต์เพื่อติดตามการกระทำที่ถือเป็น Conversion Conversion ในเว็บไซต์และการคลิกหมายเลขโทรศัพท์ต้องใช้ event_snippet ซึ่งควรวางไว้ในหน้าเว็บที่ระบุการกระทําที่ถือเป็น Conversion เช่น หน้ายืนยันการชําระเงินหรือหน้าส่งแบบฟอร์มโอกาสในการขาย และ global_site_tag ซึ่งต้องติดตั้งในทุกหน้าของเว็บไซต์ คุณเรียกข้อมูลแอตทริบิวต์ทั้ง 2 รายการนี้ได้ด้วย ConversionActionService ดู ศูนย์ช่วยเหลือสำหรับ ข้อมูลเพิ่มเติมเกี่ยวกับวิธีติดแท็กหน้าเว็บ

ตารางต่อไปนี้แสดงพารามิเตอร์ของ API ที่เทียบเท่ากันเพื่อใช้กับแหล่งที่มาแต่ละรายการในอินเทอร์เฟซเว็บของ Google Ads

ประเภทโค้ดติดตาม แหล่งที่มาของ Google Ads
WEBPAGE เว็บไซต์ เว็บไซต์ (Google Analytics (GA4))
WEBPAGE_ONCLICK เว็บไซต์ เว็บไซต์ (Google Analytics (GA4))
CLICK_TO_CALL การคลิกหมายเลขโทรศัพท์
--- เว็บไซต์ (Google Analytics (UA))

Conversion ในแอป

Conversion ของแอปช่วยให้คุณติดตามการติดตั้งแอปบนอุปกรณ์เคลื่อนที่หรือการซื้อในแอปจาก Google Play Store ได้

ตารางต่อไปนี้แสดงพารามิเตอร์ API ConversionActionType ที่เทียบเท่ากันเพื่อใช้กับแหล่งที่มาแต่ละรายการในอินเทอร์เฟซเว็บของ Google Ads

ประเภทการกระทำที่ถือเป็น Conversion แหล่งที่มาของ Google Ads
GOOGLE_PLAY_DOWNLOAD Google Play > การติดตั้ง
GOOGLE_PLAY_IN_APP_PURCHASE Google Play > การซื้อในแอป

หากต้องการติดตามการกระทำอื่นๆ ในแอปบนอุปกรณ์เคลื่อนที่โดยใช้พร็อพเพอร์ตี้ Google Analytics 4 หรือการวิเคราะห์แอปจากบุคคลที่สาม ดูประเภทการกระทำที่ถือเป็น Conversion เพิ่มเติม

Conversion การโทร

การวัด Conversion การโทร ช่วยให้คุณติดตามการโทรจากโฆษณา การโทรไปยังหมายเลขในเว็บไซต์ และ การคลิกหมายเลขในเว็บไซต์ในอุปกรณ์เคลื่อนที่ได้

ตารางต่อไปนี้แสดงพารามิเตอร์ API ConversionActionType ที่เทียบเท่ากันเพื่อใช้กับแหล่งที่มาแต่ละรายการในอินเทอร์เฟซเว็บของ Google Ads

ประเภทการกระทำที่ถือเป็น Conversion แหล่งที่มาของ Google Ads
AD_CALL การโทรจากโฆษณาโดยใช้ส่วนขยายการโทรหรือโฆษณาแบบโทรออกเท่านั้น
WEBSITE_CALL การโทรไปยังหมายเลขโทรศัพท์ในเว็บไซต์
CLICK_TO_CALL การคลิกหมายเลขในเว็บไซต์บนอุปกรณ์เคลื่อนที่

ประเภท CLICK_TO_CALL แตกต่างจากประเภท AD_CALL ตรงที่ไม่ติดตามการโทรจริง แต่ CLICK_TO_CALL จะติดตามเฉพาะการคลิกหมายเลขโทรศัพท์จากอุปกรณ์เคลื่อนที่เท่านั้น วิธีนี้มีประโยชน์เมื่อคุณไม่สามารถใช้หมายเลขโอนสายของ Google ในการติดตามการโทรได้

AD_CALL

การกระทำที่ถือเป็น Conversion AD_CALL จะปรากฏเป็น Conversion ของการโทรจากโฆษณาในอินเทอร์เฟซเว็บของ Google Ads หลังจากสร้างการกระทำที่ถือเป็น Conversion AD_CALL แล้ว ให้ระบุชื่อทรัพยากรในช่อง call_conversion_action เมื่อสร้าง CallAsset ชิ้นงานการโทรช่วยให้คุณแสดงหมายเลขโทรศัพท์ในโฆษณาได้โดยตรง

ระบบจะรายงานการโทรเป็น Conversion หากมีระยะเวลานานกว่าระยะเวลาที่ระบุ ค่าเริ่มต้นคือ 60 วินาที

WEBSITE_CALL

การกระทำที่ถือเป็น Conversion WEBSITE_CALL จะปรากฏเป็น Conversion การโทรจากเว็บไซต์ในอินเทอร์เฟซเว็บของ Google Ads

ซึ่งต่างจาก AD_CALL ตรงที่ เครื่องมือติดตามนี้กําหนดให้ต้องเพิ่ม event_snippet และ global_site_tag ลงในเว็บไซต์ เพื่อดึงหมายเลขโอนสายของ Google แบบไดนามิกสำหรับการติดตามการโทร จากหมายเลขที่แสดงบนเว็บไซต์ นอกจากนี้ คุณต้องสร้างชิ้นงานการโทรและลิงก์เนื้อหาที่ระดับลูกค้า แคมเปญ หรือกลุ่มโฆษณา

นำเข้า Conversion ออฟไลน์

ตารางต่อไปนี้แสดงพารามิเตอร์ API ConversionActionType ที่เทียบเท่ากันที่จะใช้กับแหล่งที่มาแต่ละรายการในอินเทอร์เฟซเว็บของ Google Ads และลิงก์ไปยังเอกสารประกอบสําหรับการกระทําที่ถือเป็น Conversion แต่ละประเภท

ประเภทการกระทำที่ถือเป็น Conversion แหล่งที่มาของ Google Ads คู่มือการตั้งค่า API
UPLOAD_CLICKS ติดตาม Conversion จากการคลิกและ Conversion ที่ปรับปรุงแล้วสำหรับโอกาสในการขาย คู่มือการคลิกอัปโหลด
คู่มือ Conversion ที่ปรับปรุงแล้วสำหรับโอกาสในการขาย
UPLOAD_CALLS ติดตาม Conversion จากการโทร คู่มือการตั้งค่า API
STORE_SALES ติดตาม Conversion ยอดขายในร้าน คู่มือการตั้งค่า API

Conversion ที่ปรับปรุงแล้วสําหรับเว็บ

Conversion ที่ปรับปรุงแล้วสำหรับเว็บช่วยให้คุณส่งข้อมูล Conversion จากบุคคลที่หนึ่งสำหรับการกระทำที่ถือเป็น Conversion WEBPAGE รายการได้ภายใน 24 ชั่วโมงหลังจากเกิดเหตุการณ์ Conversion แทนการส่งพร้อมกัน วิธีนี้ช่วยให้คุณค้นหาข้อมูลจากบุคคลที่หนึ่งจากแหล่งที่มาต่างๆ ได้ เช่น ฐานข้อมูลลูกค้าหรือระบบ CRM

ประเภทการกระทำที่ถือเป็น Conversion เพิ่มเติม

Google Ads API ช่วยให้มีการกระทำที่ถือเป็น Conversion หลายประเภทมากขึ้นในรายงาน แต่อาจจำกัดหรือห้ามการสร้างหรือแก้ไขการกระทำเหล่านั้น

Conversion ของ SKAdNetwork

หากคุณใช้ App Campaign สำหรับ iOS และใช้ SKAdNetwork อยู่ คุณจะเข้าถึงข้อมูล SKAdNetwork ที่ให้ไว้กับ Google ที่ระดับ Customer และ Campaign ได้โดยใช้แหล่งข้อมูลต่อไปนี้

ช่องรายงาน คำอธิบาย
metrics.sk_ad_network_conversions จำนวน Conversion ที่รายงานโดย Apple เมตริกนี้สามารถแบ่งกลุ่มตามชุดค่าผสมใดๆ ของ segments.sk_ad_network_conversion_value และกลุ่มที่เกี่ยวข้องกับวันที่เท่านั้น
segments.sk_ad_network_conversion_value

มูลค่าของ Conversion ที่รายงานโดย Apple กลุ่มนี้ไม่สามารถใช้ กับเมตริกใดๆ ที่ไม่ใช่ metrics.sk_ad_network_conversions และ รวมกับกลุ่มที่เกี่ยวข้องกับวันที่ได้เท่านั้น

ระบบจะแสดงผลค่า 0 หาก Apple รายงานค่า 0 และไม่มีค่าอื่น ตรวจสอบ การแสดงข้อมูลในช่องเพื่อแยกความแตกต่างระหว่างทั้ง 2 กรณีนี้

นอกจากนี้คุณยังบันทึกการแมปมูลค่า Conversion ของ SKAdNetwork สําหรับลูกค้าที่ลิงก์อยู่กับแอป iOS ได้ผ่าน CustomerSkAdNetworkConversionValueSchema

ตัวอย่างโค้ด Python

#!/usr/bin/env python
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import sys

from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.errors import GoogleAdsException

def main(client, customer_id):
    """Adds a keyword plan, campaign, ad group, etc. to the customer account.

    Also handles errors from the API and prints them.

    Args:
        client: An initialized instance of GoogleAdsClient
        customer_id: A str of the customer_id to use in requests.
    """

    res = update_skan_cv_schema(
        client, customer_id, "my_app_id", "account_link_id"
    )
    print(res)

def update_skan_cv_schema(client, customer_id, app_id, account_link_id):
    skan_service = client.get_service(
        "CustomerSkAdNetworkConversionValueSchemaService"
    )

    req = client.get_type(
        "MutateCustomerSkAdNetworkConversionValueSchemaRequest"
    )
    operation = client.get_type(
        "CustomerSkAdNetworkConversionValueSchemaOperation"
    )
    schema_instance = client.get_type(
        "CustomerSkAdNetworkConversionValueSchema"
    )

    new_schema = operation.update
    new_schema.resource_name = (
        skan_service.customer_sk_ad_network_conversion_value_schema_path(
            "customer_id", "account_link_id"
        )
    )
    new_schema.schema.app_id = app_id
    new_schema.schema.measurement_window_hours = 48

    skan_cv_mapping = (
        schema_instance.SkAdNetworkConversionValueSchema.FineGrainedConversionValueMappings()
    )
    skan_cv_mapping.fine_grained_conversion_value = 0  # 0 - 63
    skan_cv_mapping.conversion_value_mapping.min_time_post_install_hours = 0
    skan_cv_mapping.conversion_value_mapping.max_time_post_install_hours = 48

    skan_cv_event = schema_instance.SkAdNetworkConversionValueSchema.Event()
    skan_cv_event.mapped_event_name = "TEST"
    skan_cv_event.event_revenue_value = 10

    skan_cv_mapping.conversion_value_mapping.mapped_events.append(skan_cv_event)
    new_schema.schema.fine_grained_conversion_value_mappings.append(
        skan_cv_mapping
    )

    req.operation = operation
    req.customer_id = customer_id

    res = skan_service.mutate_customer_sk_ad_network_conversion_value_schema(
        req
    )
    return res

if __name__ == "__main__":
    # GoogleAdsClient will read the google-ads.yaml configuration file in the
    # home directory if none is specified.
    googleads_client = GoogleAdsClient.load_from_storage(
        version="v16"
    )

    parser = argparse.ArgumentParser(
        description="Creates a keyword plan for specified customer."
    )
    # The following argument(s) should be provided to run the example.
    parser.add_argument(
        "-c",
        "--customer_id",
        type=str,
        required=True,
        help="The Google Ads customer ID.",
    )
    args = parser.parse_args()

    try:
        main(googleads_client, args.customer_id)
    except GoogleAdsException as ex:
        print(
            f'Request with ID "{ex.request_id}" failed with status '
            f'"{ex.error.code().name}" and includes the following errors:'
        )
        for error in ex.failure.errors:
            print(f'\tError with message "{error.message}".')
            if error.location:
                for field_path_element in error.location.field_path_elements:
                    print(f"\t\tOn field: {field_path_element.field_name}")
        sys.exit(1)
  

Google Analytics

Conversion จากพร็อพเพอร์ตี้ Google Analytics ที่ลิงก์มีค่าใดค่าหนึ่งต่อไปนี้ type

  • Conversion ของพร็อพเพอร์ตี้ GA4:

    • GOOGLE_ANALYTICS_4_CUSTOM
    • GOOGLE_ANALYTICS_4_PURCHASE

    คุณยังดึงข้อมูลรหัสพร็อพเพอร์ตี้ GA4, ชื่อพร็อพเพอร์ตี้ และชื่อเหตุการณ์จากช่อง google_analytics_4_settings ได้ด้วย

  • Conversion พร็อพเพอร์ตี้ Universal Analytics:

    • UNIVERSAL_ANALYTICS_GOAL
    • UNIVERSAL_ANALYTICS_TRANSACTION

คุณจะทําการเปลี่ยนแปลงต่อไปนี้กับ Conversion ของพร็อพเพอร์ตี้ GA4 ได้

การพยายามแก้ไขแอตทริบิวต์อื่นๆ ของ Conversion ของ GA4 ที่นําเข้าหรือแอตทริบิวต์ใดก็ตามของ Conversion ของ Universal Analytics ที่นําเข้าจะทำให้เกิดข้อผิดพลาด MUTATE_NOT_ALLOWED คุณทําการเปลี่ยนแปลงได้โดยใช้ UI ของ Google Ads เท่านั้น

Firebase และการวิเคราะห์แอปของบุคคลที่สาม

หากต้องการนำเข้า การวิเคราะห์แอปจากบุคคลที่สาม หรือ Conversion ของ Firebase ให้เปลี่ยน status ของ ConversionAction จาก HIDDEN เป็น ENABLED โดยใช้เมธอด mutate ของ ConversionActionService ไม่รองรับการอัปเดต app_id สำหรับการกระทำที่ถือเป็น Conversion เหล่านี้

  • FIREBASE_ANDROID_FIRST_OPEN
  • FIREBASE_ANDROID_IN_APP_PURCHASE
  • FIREBASE_ANDROID_CUSTOM
  • FIREBASE_IOS_FIRST_OPEN
  • FIREBASE_IOS_IN_APP_PURCHASE
  • FIREBASE_IOS_CUSTOM
  • THIRD_PARTY_APP_ANALYTICS_ANDROID_FIRST_OPEN
  • THIRD_PARTY_APP_ANALYTICS_ANDROID_IN_APP_PURCHASE
  • THIRD_PARTY_APP_ANALYTICS_ANDROID_CUSTOM
  • THIRD_PARTY_APP_ANALYTICS_IOS_FIRST_OPEN
  • THIRD_PARTY_APP_ANALYTICS_IOS_IN_APP_PURCHASE
  • THIRD_PARTY_APP_ANALYTICS_IOS_CUSTOM

ยอดขายในร้าน

แม้ว่าคุณจะสร้างการกระทำที่ถือเป็น Conversion STORE_SALES หรือ STORE_SALES_DIRECT_UPLOAD โดยใช้ Google Ads API ไม่ได้ แต่ API จะรองรับการอัปโหลดธุรกรรมยอดขายในร้าน

  • STORE_SALES
  • STORE_SALES_DIRECT_UPLOAD

เบ็ดเตล็ด

การกระทําที่ถือเป็น Conversion ประเภทต่อไปนี้เป็นแบบอ่านอย่างเดียวใน Google Ads API และมีไว้เพื่อวัตถุประสงค์ในการรายงาน

  • ANDROID_APP_PRE_REGISTRATION
  • ANDROID_INSTALLS_ALL_OTHER_APPS
  • FLOODLIGHT_ACTION
  • FLOODLIGHT_TRANSACTION
  • GOOGLE_HOSTED
  • LEAD_FORM_SUBMIT
  • SALESFORCE
  • SEARCH_ADS_360
  • SMART_CAMPAIGN_AD_CLICKS_TO_CALL
  • SMART_CAMPAIGN_MAP_CLICKS_TO_CALL
  • SMART_CAMPAIGN_MAP_DIRECTIONS
  • SMART_CAMPAIGN_TRACKED_CALLS
  • STORE_VISITS
  • WEBPAGE_CODELESS

ไม่ทราบ

หากบัญชี Google Ads มีการกระทําที่ถือเป็น Conversion ประเภทอื่นๆ คุณอาจพบว่าการค้นหาและรายงานดังกล่าวแสดงผลการกระทําที่ถือเป็น Conversion โดยที่ ConversionAction.type คือ UNKNOWN API ไม่รองรับการจัดการการกระทำที่ถือเป็น Conversion เหล่านี้ แต่แสดงผลในรายงานเพื่อให้ผลลัพธ์ที่สมบูรณ์สำหรับเมตริก Conversion ที่สำคัญ เช่น metrics.conversions และ metrics.conversions_value

ตัวอย่างโค้ด

ตัวอย่างโค้ดต่อไปนี้จะอธิบายขั้นตอนการสร้างการกระทำที่ถือเป็น Conversion ใหม่ กล่าวอย่างเจาะจงคือ จะมีการสร้างการกระทำที่ถือเป็น Conversion โดยมี type ที่ตั้งค่าเป็น UPLOAD_CLICKS ขั้นตอนนี้จะเป็นขั้นตอนเดียวกับ UI ของ Google Ads กับการสร้างการกระทำที่ถือเป็น Conversion ใหม่โดยใช้ นำเข้า > นำเข้าด้วยตนเองโดยใช้ API หรือการอัปโหลด > ติดตาม Conversion จากการคลิก และยังตั้งค่า category เป็น DEFAULT อีกด้วย

ระบบจะใช้การตั้งค่าเริ่มต้นต่อไปนี้

Java

private void runExample(GoogleAdsClient googleAdsClient, long customerId) {

  // Creates a ConversionAction.
  ConversionAction conversionAction =
      ConversionAction.newBuilder()
          // Note that conversion action names must be unique. If a conversion action already
          // exists with the specified conversion_action_name the create operation will fail with
          // a ConversionActionError.DUPLICATE_NAME error.
          .setName("Earth to Mars Cruises Conversion #" + getPrintableDateTime())
          .setCategory(ConversionActionCategory.DEFAULT)
          .setType(ConversionActionType.WEBPAGE)
          .setStatus(ConversionActionStatus.ENABLED)
          .setViewThroughLookbackWindowDays(15L)
          .setValueSettings(
              ValueSettings.newBuilder()
                  .setDefaultValue(23.41)
                  .setAlwaysUseDefaultValue(true)
                  .build())
          .build();

  // Creates the operation.
  ConversionActionOperation operation =
      ConversionActionOperation.newBuilder().setCreate(conversionAction).build();

  try (ConversionActionServiceClient conversionActionServiceClient =
      googleAdsClient.getLatestVersion().createConversionActionServiceClient()) {
    MutateConversionActionsResponse response =
        conversionActionServiceClient.mutateConversionActions(
            Long.toString(customerId), Collections.singletonList(operation));
    System.out.printf("Added %d conversion actions:%n", response.getResultsCount());
    for (MutateConversionActionResult result : response.getResultsList()) {
      System.out.printf(
          "New conversion action added with resource name: '%s'%n", result.getResourceName());
    }
  }
}
      

C#

public void Run(GoogleAdsClient client, long customerId)
{
    // Get the ConversionActionService.
    ConversionActionServiceClient conversionActionService =
        client.GetService(Services.V16.ConversionActionService);

    // Note that conversion action names must be unique.
    // If a conversion action already exists with the specified name the create operation
    // will fail with a ConversionAction.DUPLICATE_NAME error.
    string ConversionActionName = "Earth to Mars Cruises Conversion #"
        + ExampleUtilities.GetRandomString();

    // Add a conversion action.
    ConversionAction conversionAction = new ConversionAction()
    {
        Name = ConversionActionName,
        Category = ConversionActionCategory.Default,
        Type = ConversionActionType.Webpage,
        Status = ConversionActionStatus.Enabled,
        ViewThroughLookbackWindowDays = 15,
        ValueSettings = new ConversionAction.Types.ValueSettings()
        {
            DefaultValue = 23.41,
            AlwaysUseDefaultValue = true
        }
    };

    // Create the operation.
    ConversionActionOperation operation = new ConversionActionOperation()
    {
        Create = conversionAction
    };

    try
    {
        // Create the conversion action.
        MutateConversionActionsResponse response =
            conversionActionService.MutateConversionActions(customerId.ToString(),
                    new ConversionActionOperation[] { operation });

        // Display the results.
        foreach (MutateConversionActionResult newConversionAction in response.Results)
        {
            Console.WriteLine($"New conversion action with resource name = " +
                $"'{newConversionAction.ResourceName}' was added.");
        }
    }
    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)
{
    // Creates a conversion action.
    $conversionAction = new ConversionAction([
        // Note that conversion action names must be unique.
        // If a conversion action already exists with the specified conversion_action_name
        // the create operation will fail with a ConversionActionError.DUPLICATE_NAME error.
        'name' => 'Earth to Mars Cruises Conversion #' . Helper::getPrintableDatetime(),
        'category' => ConversionActionCategory::PBDEFAULT,
        'type' => ConversionActionType::WEBPAGE,
        'status' => ConversionActionStatus::ENABLED,
        'view_through_lookback_window_days' => 15,
        'value_settings' => new ValueSettings([
            'default_value' => 23.41,
            'always_use_default_value' => true
        ])
    ]);

    // Creates a conversion action operation.
    $conversionActionOperation = new ConversionActionOperation();
    $conversionActionOperation->setCreate($conversionAction);

    // Issues a mutate request to add the conversion action.
    $conversionActionServiceClient = $googleAdsClient->getConversionActionServiceClient();
    $response = $conversionActionServiceClient->mutateConversionActions(
        MutateConversionActionsRequest::build($customerId, [$conversionActionOperation])
    );

    printf("Added %d conversion actions:%s", $response->getResults()->count(), PHP_EOL);

    foreach ($response->getResults() as $addedConversionAction) {
        /** @var ConversionAction $addedConversionAction */
        printf(
            "New conversion action added with resource name: '%s'%s",
            $addedConversionAction->getResourceName(),
            PHP_EOL
        );
    }
}
      

Python

def main(client, customer_id):
    conversion_action_service = client.get_service("ConversionActionService")

    # Create the operation.
    conversion_action_operation = client.get_type("ConversionActionOperation")

    # Create conversion action.
    conversion_action = conversion_action_operation.create

    # Note that conversion action names must be unique. If a conversion action
    # already exists with the specified conversion_action_name, the create
    # operation will fail with a ConversionActionError.DUPLICATE_NAME error.
    conversion_action.name = f"Earth to Mars Cruises Conversion {uuid.uuid4()}"
    conversion_action.type_ = (
        client.enums.ConversionActionTypeEnum.UPLOAD_CLICKS
    )
    conversion_action.category = (
        client.enums.ConversionActionCategoryEnum.DEFAULT
    )
    conversion_action.status = client.enums.ConversionActionStatusEnum.ENABLED
    conversion_action.view_through_lookback_window_days = 15

    # Create a value settings object.
    value_settings = conversion_action.value_settings
    value_settings.default_value = 15.0
    value_settings.always_use_default_value = True

    # Add the conversion action.
    conversion_action_response = (
        conversion_action_service.mutate_conversion_actions(
            customer_id=customer_id,
            operations=[conversion_action_operation],
        )
    )

    print(
        "Created conversion action "
        f'"{conversion_action_response.results[0].resource_name}".'
    )
      

Ruby

def add_conversion_action(customer_id)
  # GoogleAdsClient will read a config file from
  # ENV['HOME']/google_ads_config.rb when called without parameters
  client = Google::Ads::GoogleAds::GoogleAdsClient.new


  # Add a conversion action.
  conversion_action = client.resource.conversion_action do |ca|
    ca.name = "Earth to Mars Cruises Conversion #{(Time.new.to_f * 100).to_i}"
    ca.type = :UPLOAD_CLICKS
    ca.category = :DEFAULT
    ca.status = :ENABLED
    ca.view_through_lookback_window_days = 15

    # Create a value settings object.
    ca.value_settings = client.resource.value_settings do |vs|
      vs.default_value = 15
      vs.always_use_default_value = true
    end
  end

  # Create the operation.
  conversion_action_operation = client.operation.create_resource.conversion_action(conversion_action)

  # Add the ad group ad.
  response = client.service.conversion_action.mutate_conversion_actions(
    customer_id: customer_id,
    operations: [conversion_action_operation],
  )

  puts "New conversion action with resource name = #{response.results.first.resource_name}."
end
      

Perl

sub add_conversion_action {
  my ($api_client, $customer_id) = @_;

  # Note that conversion action names must be unique.
  # If a conversion action already exists with the specified conversion_action_name,
  # the create operation fails with error ConversionActionError.DUPLICATE_NAME.
  my $conversion_action_name = "Earth to Mars Cruises Conversion #" . uniqid();

  # Create a conversion action.
  my $conversion_action =
    Google::Ads::GoogleAds::V16::Resources::ConversionAction->new({
      name                          => $conversion_action_name,
      category                      => DEFAULT,
      type                          => WEBPAGE,
      status                        => ENABLED,
      viewThroughLookbackWindowDays => 15,
      valueSettings                 =>
        Google::Ads::GoogleAds::V16::Resources::ValueSettings->new({
          defaultValue          => 23.41,
          alwaysUseDefaultValue => "true"
        })});

  # Create a conversion action operation.
  my $conversion_action_operation =
    Google::Ads::GoogleAds::V16::Services::ConversionActionService::ConversionActionOperation
    ->new({create => $conversion_action});

  # Add the conversion action.
  my $conversion_actions_response =
    $api_client->ConversionActionService()->mutate({
      customerId => $customer_id,
      operations => [$conversion_action_operation]});

  printf "New conversion action added with resource name: '%s'.\n",
    $conversion_actions_response->{results}[0]{resourceName};

  return 1;
}
      

ตัวอย่างนี้ยังพบได้ในโฟลเดอร์รีมาร์เก็ตติ้งของไลบรารีไคลเอ็นต์และในคอลเล็กชันตัวอย่างโค้ด: ตัวอย่างโค้ดการกระทำที่ถือเป็น Conversion

การตรวจสอบความถูกต้อง

Google Ads และ Google Ads API รองรับการกระทําที่ถือเป็น Conversion ได้หลายรูปแบบ กฎการตรวจสอบความถูกต้องบางข้อจึงแตกต่างกันไปตามtypeของการดําเนินการ

ข้อผิดพลาดที่พบบ่อยที่สุดขณะสร้างการกระทําที่ถือเป็น Conversion คือ DUPLICATE_NAME ตรวจสอบว่าคุณใช้ชื่อที่ไม่ซ้ำกันสําหรับการกระทําที่ถือเป็น Conversion แต่ละรายการ

เคล็ดลับบางส่วนในการตั้งค่าช่อง ConversionAction มีดังนี้

ช่อง enum ทั้งหมด
การพยายามตั้งค่าช่อง enum เป็น UNKNOWN จะเกิดข้อผิดพลาด RequestError.INVALID_ENUM_VALUE รายการ
app_id
แอตทริบิวต์ app_id จะเปลี่ยนแปลงไม่ได้และตั้งค่าได้เมื่อสร้าง Conversion ของแอปใหม่เท่านั้น
attribution_model_settings
การตั้งค่านี้เป็นตัวเลือกที่เลิกใช้งานแล้วจะทำให้เกิดข้อผิดพลาด CANNOT_SET_RULE_BASED_ATTRIBUTION_MODELS Google Ads รองรับเฉพาะ GOOGLE_ADS_LAST_CLICK และ GOOGLE_SEARCH_ATTRIBUTION_DATA_DRIVEN
click_through_lookback_window_days

การตั้งค่าแอตทริบิวต์นี้เป็นค่าที่อยู่นอกช่วงที่อนุญาตจะทำให้เกิดข้อผิดพลาด RangeError.TOO_LOW หรือ RangeError.TOO_HIGH

แอตทริบิวต์นี้ต้องอยู่ในช่วง [1,60] สำหรับการกระทำที่ถือเป็น Conversion AD_CALL หรือ WEBSITE_CALL สำหรับการกระทำที่ถือเป็น Conversion อื่นๆ ส่วนใหญ่ ช่วงที่อนุญาตคือ [1,30]

include_in_conversions_metric

การตั้งค่านี้ในการดำเนินการ create หรือ update ไม่สำเร็จโดยมีข้อผิดพลาด FieldError.IMMUTABLE_FIELD แต่ให้ตั้งค่า primary_for_goal ตามที่อธิบายไว้ในคู่มือเป้าหมาย Conversion แทน

phone_call_duration_seconds

การพยายามตั้งค่าแอตทริบิวต์นี้ในการกระทำที่ถือเป็น Conversion ที่ไม่ใช่สำหรับการโทรจะทำให้เกิดข้อผิดพลาด FieldError.VALUE_MUST_BE_UNSET

type

แอตทริบิวต์ type จะเปลี่ยนแปลงไม่ได้และตั้งค่าได้เมื่อสร้าง Conversion ใหม่เท่านั้น

การอัปเดตการกระทำที่ถือเป็น Conversion ที่มี type เท่ากับ UNKNOWN จะทำให้เกิดข้อผิดพลาด MutateError.MUTATE_NOT_ALLOWED รายการ

value_settings

value_settings สำหรับการกระทำที่ถือเป็น Conversion WEBSITE_CALL หรือ AD_CALL ต้องมีการตั้งค่า always_use_default_value เป็น true การระบุค่า false เมื่อสร้างหรืออัปเดตค่านี้ทำให้เกิดข้อผิดพลาด INVALID_VALUE

view_through_lookback_window_days

การตั้งค่าแอตทริบิวต์นี้เป็นค่าที่อยู่นอกช่วงที่อนุญาตจะทำให้เกิดข้อผิดพลาด RangeError.TOO_LOW หรือ RangeError.TOO_HIGH ช่วงที่อนุญาตสำหรับการกระทำที่ถือเป็น Conversion ส่วนใหญ่คือ [1,30]

ตั้งค่าแอตทริบิวต์นี้กับการกระทำที่ถือเป็น Conversion AD_CALL หรือ WEBSITE_CALL ไม่ได้ การระบุค่าจะทําให้เกิดข้อผิดพลาด VALUE_MUST_BE_UNSET