用于服务器端转换的 Facebook Business SDK:散列还是不散列用户数据?
Facebook Business SDK for server side conversions: to hash or not to hash user data?
我正在研究这个文档:
https://developers.facebook.com/docs/marketing-api/conversions-api/using-the-api
它说:
Hashing
Please check our customer information parameters page to see which
parameters should be hashed before they are sent to Facebook. If you
are using one of our Business SDKs, the hashing is done for you by the
SDK.
但是,使用 Business SDK 的 Python 代码示例提供了已经散列的数据:
from facebook_business.adobjects.adspixel import AdsPixel
from facebook_business.api import FacebookAdsApi
access_token = '<ACCESS_TOKEN>'
app_secret = '<APP_SECRET>'
app_id = '<APP_ID>'
id = '<ADS_PIXEL_ID>'
FacebookAdsApi.init(access_token=access_token)
fields = [
]
params = {
'data': [{'event_name':'PageView','event_time':1603429918,'user_data':{'fbc':'fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890','fbp':'fb.1.1558571054389.1098115397','em':'309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd'}}],
}
print AdsPixel(id).create_event(
fields=fields,
params=params,
)
特别是,我指的是 'em'
字段(应该是电子邮件):
'em':'309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd'
那么,如果我使用 facebook_business.adobjects.adspixel.AdsPixel
,我应该散列客户数据吗?还是它会自动为我执行此操作?
如果没有,我该如何在 Python 中做到这一点?有许多不同的哈希方法和函数:Facebook期望的是哪种?
这对我有用:
import hashlib
from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adspixel import AdsPixel
FacebookAdsApi.init(access_token=FACEBOOK_PIXEL_TOKEN)
params = {
data: [
"event_name": "CompleteRegistration",
"event_time": int(datetime.now().timestamp()),
"user_data": {
"em": hashlib.sha256(email.encode("utf-8")).hexdigest()
}
],
"test_event_code": "TEST9876",
}
AdsPixel(FACEBOOK_PIXEL_ID).create_event(fields=[], params=params)
HTH
我正在研究这个文档: https://developers.facebook.com/docs/marketing-api/conversions-api/using-the-api
它说:
Hashing
Please check our customer information parameters page to see which parameters should be hashed before they are sent to Facebook. If you are using one of our Business SDKs, the hashing is done for you by the SDK.
但是,使用 Business SDK 的 Python 代码示例提供了已经散列的数据:
from facebook_business.adobjects.adspixel import AdsPixel
from facebook_business.api import FacebookAdsApi
access_token = '<ACCESS_TOKEN>'
app_secret = '<APP_SECRET>'
app_id = '<APP_ID>'
id = '<ADS_PIXEL_ID>'
FacebookAdsApi.init(access_token=access_token)
fields = [
]
params = {
'data': [{'event_name':'PageView','event_time':1603429918,'user_data':{'fbc':'fb.1.1554763741205.AbCdEfGhIjKlMnOpQrStUvWxYz1234567890','fbp':'fb.1.1558571054389.1098115397','em':'309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd'}}],
}
print AdsPixel(id).create_event(
fields=fields,
params=params,
)
特别是,我指的是 'em'
字段(应该是电子邮件):
'em':'309a0a5c3e211326ae75ca18196d301a9bdbd1a882a4d2569511033da23f0abd'
那么,如果我使用 facebook_business.adobjects.adspixel.AdsPixel
,我应该散列客户数据吗?还是它会自动为我执行此操作?
如果没有,我该如何在 Python 中做到这一点?有许多不同的哈希方法和函数:Facebook期望的是哪种?
这对我有用:
import hashlib
from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adspixel import AdsPixel
FacebookAdsApi.init(access_token=FACEBOOK_PIXEL_TOKEN)
params = {
data: [
"event_name": "CompleteRegistration",
"event_time": int(datetime.now().timestamp()),
"user_data": {
"em": hashlib.sha256(email.encode("utf-8")).hexdigest()
}
],
"test_event_code": "TEST9876",
}
AdsPixel(FACEBOOK_PIXEL_ID).create_event(fields=[], params=params)
HTH