傳送通知(Python)
說明
send_notifications()
是用來傳送顯示或點選通知給Adobe Target以進行測量和報告。
NOTE
當具有必要引數的
execute
物件位於請求本身中時,曝光將自動遞增以符合活動資格。會自動增加曝光次數的SDK方法為:
get_offers()
get_attributes()
當在要求中傳遞prefetch
物件時,曝光次數不會自動遞增到具有prefetch
物件中mbox的活動。 Send_notifications()
必須用於預先擷取的體驗,以增加曝光次數和轉換次數。
方法
send_notifications
target_client.send_notifications(options)
參數
options
具有以下結構:
名稱
類型
必要
預設值
說明
target_cookie
str
no
無
Target Cookie
target_location_hint
str
no
無
Target位置提示
consumer_id
str
no
無
拼接多個呼叫時,應提供不同的消費者ID
customer_ids
清單[CustomerId]
no
無
VisitorId相容格式的客戶ID清單
session_id
str
no
無
用於連結多個請求
callBack
可呼叫
no
無
如果以非同步方式處理請求,則會在回應就緒時叫用回呼
err_callback
可呼叫
no
無
如果以非同步方式處理請求,則會在引發例外狀況時叫用錯誤回呼
傳回值
Returns
同步呼叫(預設)時為TargetDeliveryResponse
,或呼叫回撥時為AsyncResult
。 TargetDeliveryResponse
具有以下結構:
名稱
類型
說明
target_cookie
dict
Target Cookie
target_location_hint_cookie
dict
Target位置提示Cookie
analytics_details
清單[AnalyticsResponse]
使用者端Analytics使用狀況下的Analytics承載
trace
清單[dict]
meta
dict
用於裝置上決策的其他決策中繼資料
範例
首先,讓我們建置Target Delivery API要求,以預先擷取home
和product1
mbox的內容。
Python
mboxes = [MboxRequest(name="home"),
MboxRequest(name="product1")]
prefetch = PrefetchRequest(mboxes=mboxes)
delivery_request = DeliveryRequest(prefetch=prefetch)
# Next, we fetch the offers via Target Python SDK getOffers() API
response = target_client.get_offers({ "request": delivery_request })
成功的回應將包含Target Delivery API回應物件,其中包含要求mbox的預先擷取內容。 範例target_response["response"]
物件(格式為dict)可能如下所示:
Python
{
"status": 200,
"requestId": "e8ac2dbf5f7d4a9f9280f6071f24a01e",
"id": {
"tntId": "08210e2d751a44779b8313e2d2692b96.21_27"
},
"client": "adobetargetmobile",
"edgeHost": "mboxedge21.tt.omtrdc.net",
"prefetch": {
"mboxes": [
{
"index": 0,
"name": "home",
"options": [
{
"type": "html",
"content": "HOME OFFER",
"eventToken": "t0FRvoWosOqHmYL5G18QCZNWHtnQtQrJfmRrQugEa2qCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==",
"responseTokens": {
"profile.memberlevel": "0",
"geo.city": "dublin",
"activity.id": "302740",
"experience.name": "Experience B",
"geo.country": "ireland"
}
}
],
"state": "J+W1Fq18hxliDDJonTPfV0S+mzxapAO3d14M43EsM9f12A6QaqL+E3XKkRFlmq9U"
},
{
"index": 1,
"name": "product1",
"options": [
{
"type": "html",
"content": "TEST OFFER 1",
"eventToken": "t0FRvoWosOqHmYL5G18QCZNWHtnQtQrJfmRrQugEa2qCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==",
"responseTokens": {
"profile.memberlevel": "0",
"geo.city": "dublin",
"activity.id": "302740",
"experience.name": "Experience B",
"geo.country": "ireland"
}
}
],
"state": "J+W1Fq18hxliDDJonTPfV0S+mzxapAO3d14M43EsM9f12A6QaqL+E3XKkRFlmq9U"
}
]
}
}
記下每個Target內容選項中的mbox name
和state
欄位,以及eventToken
欄位。 每個內容選項一顯示,即應在send_notifications()
請求中提供這些選項。 假設product1
mbox已顯示在非瀏覽器裝置上。 通知要求會顯示如下:
Python
notification_mbox = NotificationMbox(name="product1",
state="J+W1Fq18hxliDDJonTPfV0S+mzxapAO3d14M43EsM9f12A6QaqL+E3XKkRFlmq9U")
notification = Notification(
id="1",
type=MetricType.DISPLAY,
timestamp=1621530726000, # Epoch time in milliseconds
mbox=notification_mbox,
tokens=["t0FRvoWosOqHmYL5G18QCZNWHtnQtQrJfmRrQugEa2qCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q=="]
)
notification_request = DeliveryRequest(notifications=[notification])
請注意,我們已在預先擷取回應中納入對應至已傳遞Target選件的mbox狀態和事件權杖。 建立通知要求後,我們可以透過send_notifications()
API方法將其傳送至Target:
Python
response = target_client.send_notifications({ "request": notification_request })
recommendation-more-help
6906415f-169c-422b-89d3-7118e147c4e3