Hello teams, after many times tried, our api upload enhancement conversion still not work.
import hashlib
import logging
from google.ads.googleads.client
import GoogleAdsClient
logging.basicConfig(
level=logging.DEBUG
, format=
'[%(asctime)s - %(levelname)s] %(message).5000s')
logging.getLogger(
'google.ads.googleads.client').setLevel(logging.DEBUG)
def normalize_and_hash(s):
return hashlib.sha256(s.strip().lower().encode()).hexdigest()
# 初始化client
client = GoogleAdsClient.load_from_storage(
"/Users/eric/PycharmProjects/google_ads/google-ads.yaml")
# Constructs the enhancement adjustment.
conversion_adjustment = client.get_type(
"ConversionAdjustment")
conversion_adjustment.adjustment_type = (
client.enums.ConversionAdjustmentTypeEnum.ENHANCEMENT
)
# add phone
phone_identifier = client.get_type(
"UserIdentifier")
phone_identifier.hashed_phone_number = normalize_and_hash(
"+919820703373")
conversion_adjustment.user_identifiers.append(phone_identifier)
# add order_id
conversion_adjustment.order_id =
"37656781"
# add gclid & conversion_date_time
conversion_adjustment.gclid_date_time_pair.conversion_date_time =
"2024-04-12 15:07:12+08:00"
conversion_adjustment.gclid_date_time_pair.gclid =
"CjwKCAjwt-OwBhBnEiwAgwzrUui8sK_o-3d-GO_u4VuC9Gzr6wUk_dXJKi-m9uMf2DbXLYMgfCqpDhoChN4QAvD_BwE"
# find conversion action
conversion_action_service = client.get_service(
"ConversionActionService")
conversion_adjustment.conversion_action = (conversion_action_service.conversion_action_path(
7514302876, 6731257876))
# Creates the conversion adjustment upload service client.
conversion_adjustment_upload_service = client.get_service(
"ConversionAdjustmentUploadService")
response = conversion_adjustment_upload_service.upload_conversion_adjustments(
customer_id=
"7514302876",
conversion_adjustments=[conversion_adjustment]
,
partial_failure=
True,
)
[2024-04-12 15:29:05,999 - DEBUG] Making request: POST
https://accounts.google.com/o/oauth2/token[2024-04-12 15:29:06,006 - DEBUG] Starting new HTTPS connection (1):
accounts.google.com:443[2024-04-12 15:29:07,037 - DEBUG]
https://accounts.google.com:443 "POST /o/oauth2/token HTTP/1.1" 200 None
[2024-04-12 15:29:08,940 - DEBUG] Request
-------
Method: /google.ads.googleads.v16.services.ConversionAdjustmentUploadService/UploadConversionAdjustments
Host:
googleads.googleapis.comHeaders: {
"developer-token": "REDACTED",
"login-customer-id": "7514302876",
"x-goog-api-client": "gl-python/3.9.6 grpc/1.62.0 gax/2.17.1 gccl/23.1.0 pb/4.25.3",
"x-goog-request-params": "customer_id=7514302876"
}
Request: customer_id: "7514302876"
conversion_adjustments {
gclid_date_time_pair {
gclid: "CjwKCAjwt-OwBhBnEiwAgwzrUui8sK_o-3d-GO_u4VuC9Gzr6wUk_dXJKi-m9uMf2DbXLYMgfCqpDhoChN4QAvD_BwE"
conversion_date_time: "2024-04-12 15:07:12+08:00"
}
order_id: "37656781"
conversion_action: "customers/7514302876/conversionActions/6731257876"
adjustment_type: ENHANCEMENT
user_identifiers {
hashed_phone_number: "95a6ed9f3d36ed8b892fbd689818489f63535fb3de0529e94570a8366b1355b5"
}
}
partial_failure: true
Response
-------
Headers: {
"alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
"content-disposition": "attachment",
"date": "Fri, 12 Apr 2024 07:29:08 GMT",
"request-id": "3RvYVBDBP6zMlpX5VhCodg"
}
Response: partial_failure_error {
code: 3
message: "Can\'t use enhanced conversions with the specified conversion action., at conversion_adjustments[0].conversion_action"
details {
type_url: "
type.googleapis.com/google.ads.googleads.v16.errors.GoogleAdsFailure"
value: "\n\263\001\n\003\230\007\020\022DCan\'t use enhanced conversions with the specified conversion action.\0323*1customers/7514302876/conversionActions/6731257876\"1\022\032\n\026conversion_adjustments\030\000\022\023\n\021conversion_action"
}
}
results {
}
job_id: 8562845044805615846
[2024-04-12 15:29:08,941 - INFO] Request made: ClientCustomerId: 7514302876, Host:
googleads.googleapis.com, Method: /google.ads.googleads.v16.services.ConversionAdjustmentUploadService/UploadConversionAdjustments, RequestId: 3RvYVBDBP6zMlpX5VhCodg, IsFault: False, FaultMessage: None