如何找到用于 Google 广告 API 的转化操作 ID?
How do I find the Conversion Action ID for use in the Google Ads API?
我正在使用最新的 (v7) Google 广告 API 上传 Google 广告的离线转化数据,使用 Python 客户端库。这是我使用的标准代码:
import os
from google.ads.googleads.client import GoogleAdsClient
client = GoogleAdsClient.load_from_env(version='v7')
def process_adwords_conversion(
conversion_date_time,
gclid,
conversion_action_id,
conversion_value
):
conversion_date_time = convert_datetime(conversion_date_time)
customer_id = os.environ['GOOGLE_ADS_LOGIN_CUSTOMER_ID']
click_conversion = client.get_type("ClickConversion")
conversion_action_service = client.get_service("ConversionActionService")
click_conversion.conversion_action = (
conversion_action_service.conversion_action_path(
customer_id, conversion_action_id
)
)
click_conversion.gclid = gclid
click_conversion.conversion_value = float(conversion_value)
click_conversion.conversion_date_time = conversion_date_time
click_conversion.currency_code = "USD"
conversion_upload_service = client.get_service("ConversionUploadService")
request = client.get_type("UploadClickConversionsRequest")
request.customer_id = customer_id
request.conversions = [click_conversion]
request.partial_failure = True
conversion_upload_response = (
conversion_upload_service.upload_click_conversions(
request=request,
)
)
uploaded_click_conversion = conversion_upload_response.results[0]
print(conversion_upload_response)
print(
f"Uploaded conversion that occurred at "
f'"{uploaded_click_conversion.conversion_date_time}" from '
f'Google Click ID "{uploaded_click_conversion.gclid}" '
f'to "{uploaded_click_conversion.conversion_action}"'
)
return False
我相信代码没问题,但我在查找要使用的 conversion_action_id 值时遇到问题。在 Google 广告 UI 中有一个屏幕列出了不同的转化操作,任何地方都没有 ID 的迹象。您可以点击名称查看更多详情,但仍然没有ID:
The conversion action detail screen in Google Ads UI
我试过以下方法:
- 使用此详细信息页面中的 ocid、ctId、euid、__u、uscid、__c、subid URL 参数作为 conversion_action_id。总是报错:
partial_failure_error {
code: 3
message: "This customer does not have an import conversion action that matches the conversion action provided., at conversions[0].conversion_action"
details {
type_url: "type.googleapis.com/google.ads.googleads.v7.errors.GoogleAdsFailure"
value: "\n5[=13=]1\n[=13=]30[=13=]6\t2dThis customer does not have an import conversion action that matches the conversion action provided.20*.customers/9603123598/conversionActions/6095821\"&27\n3conversions0[=13=]023\n1conversion_action"
}
}
- 使用标准 Google 答案:
Google 建议创建一个新的 Conversion Action 并在此过程中获取 ID。不幸的是,他们的说明与当前的 UI 版本不符,至少对我而言是这样。我遵循的顺序是:
- 点击“转化操作”页面上的 + 图标
- Select“导入”作为我想要的那种转换
- Select“其他数据源或 CRM”,然后“跟踪点击带来的转化”
- 点击“创建并继续”
然后我得到屏幕:
Screen following Conversion Action creation
推荐的答案是:
The conversion action is now created and you are ready to set up the tag to add it to your website. You have three options and the recommended answer in this thread is discussing the Google Tag Manager option, which is the only option that uses the Conversion ID and Conversion Label. If you do not click on the Google Tag Manager option you will not be presented with the Conversion ID and Conversion Label.
不是这样!哪三个选项?第一个“了解更多”link 提到了 Google 跟踪代码管理器,但在收集我已经拥有的 GCLID 的上下文中。官方回答中提到的“三个选项”已经没有了。单击“完成”只会将我带回“转化操作”列表。
- 使用 REST API
我已经尝试验证和询问端点:
https://googleads.googleapis.com/v7/customers/9603123598/conversionActions/
希望能提供转化操作列表,但事实并非如此。它只是给出了 404.
是否有人知道从 UI 或以编程方式(通过客户端库、REST 或其他方法)获取转化操作 ID 的方法?
谢谢!
我找到 this post 以及如何获取转化操作 ID 的解决方案:
(…) I found out that conversionActionId can be found also in Google
Ads panel. When you go to conversion action details, in URL there is
parameter "ctId=123456789" which represent conversion action id.
顺便说一句,我尝试了 something similar 但它仍然无法正常工作,但是使用此转化操作 ID,我至少收到了一条不同的“部分失败”消息。
如果您使用的是 Python,您可以通过下一个代码段列出您的转化:
ads: GoogleAdsServiceClient = client.get_service('GoogleAdsService')
pages = ads.search(query="SELECT conversion_action.id, conversion_action.name FROM conversion_action", customer_id='YOUR_MCC_ID')
for page in pages:
print(page.conversion_action)
您也可以在 UI 中打开转化操作并找到 &ctId=
,即转化操作 ID。
至少在 Google 广告 API (REST) v10,
如果字段 conversionAction 设置为 value:
'customers/{customerId}/conversionActions/{ctId}'
customerId - 没有连字符
ctId - 转化动作id,如上评论所述,
打开特定转换时取自 Google 广告面板中的 GET 参数。
也可以使用 API 方法以编程方式找到。
我正在使用最新的 (v7) Google 广告 API 上传 Google 广告的离线转化数据,使用 Python 客户端库。这是我使用的标准代码:
import os
from google.ads.googleads.client import GoogleAdsClient
client = GoogleAdsClient.load_from_env(version='v7')
def process_adwords_conversion(
conversion_date_time,
gclid,
conversion_action_id,
conversion_value
):
conversion_date_time = convert_datetime(conversion_date_time)
customer_id = os.environ['GOOGLE_ADS_LOGIN_CUSTOMER_ID']
click_conversion = client.get_type("ClickConversion")
conversion_action_service = client.get_service("ConversionActionService")
click_conversion.conversion_action = (
conversion_action_service.conversion_action_path(
customer_id, conversion_action_id
)
)
click_conversion.gclid = gclid
click_conversion.conversion_value = float(conversion_value)
click_conversion.conversion_date_time = conversion_date_time
click_conversion.currency_code = "USD"
conversion_upload_service = client.get_service("ConversionUploadService")
request = client.get_type("UploadClickConversionsRequest")
request.customer_id = customer_id
request.conversions = [click_conversion]
request.partial_failure = True
conversion_upload_response = (
conversion_upload_service.upload_click_conversions(
request=request,
)
)
uploaded_click_conversion = conversion_upload_response.results[0]
print(conversion_upload_response)
print(
f"Uploaded conversion that occurred at "
f'"{uploaded_click_conversion.conversion_date_time}" from '
f'Google Click ID "{uploaded_click_conversion.gclid}" '
f'to "{uploaded_click_conversion.conversion_action}"'
)
return False
我相信代码没问题,但我在查找要使用的 conversion_action_id 值时遇到问题。在 Google 广告 UI 中有一个屏幕列出了不同的转化操作,任何地方都没有 ID 的迹象。您可以点击名称查看更多详情,但仍然没有ID:
The conversion action detail screen in Google Ads UI
我试过以下方法:
- 使用此详细信息页面中的 ocid、ctId、euid、__u、uscid、__c、subid URL 参数作为 conversion_action_id。总是报错:
partial_failure_error {
code: 3
message: "This customer does not have an import conversion action that matches the conversion action provided., at conversions[0].conversion_action"
details {
type_url: "type.googleapis.com/google.ads.googleads.v7.errors.GoogleAdsFailure"
value: "\n5[=13=]1\n[=13=]30[=13=]6\t2dThis customer does not have an import conversion action that matches the conversion action provided.20*.customers/9603123598/conversionActions/6095821\"&27\n3conversions0[=13=]023\n1conversion_action"
}
}
- 使用标准 Google 答案:
Google 建议创建一个新的 Conversion Action 并在此过程中获取 ID。不幸的是,他们的说明与当前的 UI 版本不符,至少对我而言是这样。我遵循的顺序是:
- 点击“转化操作”页面上的 + 图标
- Select“导入”作为我想要的那种转换
- Select“其他数据源或 CRM”,然后“跟踪点击带来的转化”
- 点击“创建并继续”
然后我得到屏幕:
Screen following Conversion Action creation
推荐的答案是:
The conversion action is now created and you are ready to set up the tag to add it to your website. You have three options and the recommended answer in this thread is discussing the Google Tag Manager option, which is the only option that uses the Conversion ID and Conversion Label. If you do not click on the Google Tag Manager option you will not be presented with the Conversion ID and Conversion Label.
不是这样!哪三个选项?第一个“了解更多”link 提到了 Google 跟踪代码管理器,但在收集我已经拥有的 GCLID 的上下文中。官方回答中提到的“三个选项”已经没有了。单击“完成”只会将我带回“转化操作”列表。
- 使用 REST API
我已经尝试验证和询问端点:
https://googleads.googleapis.com/v7/customers/9603123598/conversionActions/
希望能提供转化操作列表,但事实并非如此。它只是给出了 404.
是否有人知道从 UI 或以编程方式(通过客户端库、REST 或其他方法)获取转化操作 ID 的方法?
谢谢!
我找到 this post 以及如何获取转化操作 ID 的解决方案:
(…) I found out that conversionActionId can be found also in Google Ads panel. When you go to conversion action details, in URL there is parameter "ctId=123456789" which represent conversion action id.
顺便说一句,我尝试了 something similar 但它仍然无法正常工作,但是使用此转化操作 ID,我至少收到了一条不同的“部分失败”消息。
如果您使用的是 Python,您可以通过下一个代码段列出您的转化:
ads: GoogleAdsServiceClient = client.get_service('GoogleAdsService')
pages = ads.search(query="SELECT conversion_action.id, conversion_action.name FROM conversion_action", customer_id='YOUR_MCC_ID')
for page in pages:
print(page.conversion_action)
您也可以在 UI 中打开转化操作并找到 &ctId=
,即转化操作 ID。
至少在 Google 广告 API (REST) v10,
如果字段 conversionAction 设置为 value:
'customers/{customerId}/conversionActions/{ctId}'
customerId - 没有连字符
ctId - 转化动作id,如上评论所述,
打开特定转换时取自 Google 广告面板中的 GET 参数。
也可以使用 API 方法以编程方式找到。