Edit in GitHubLog an issue

Send Notifications

Description#

send_notifications() is used to send display or click notifications to Adobe Target for measurement and reporting.

SDK methods that will increment an impression automatically are:

  • get_offers()
  • get_attributes()

When a prefetch object is passed within the request, the impression is not automatically incremented for the activities with mboxes within the prefetch object. Send_notifications() must be used for prefetched experiences for incrementing impressions and conversions.

Method#

Copied to your clipboard
target_client.send_notifications(options)

Parameters#

options has the following structure:

NameTypeRequiredDefaultDescription
requestDeliveryRequestYesNoneConforms to the Target Delivery API request
target_cookiestrnoNoneTarget cookie
target_location_hintstrnoNoneTarget location hint
consumer_idstrnoNoneWhen stitching multiple calls, different consumer IDs should be provided
customer_idslist[CustomerId]noNoneA list of Customer Ids in VisitorId-compatible format
session_idstrnoNoneUsed for linking multiple requests
callbackcallablenoNoneIf handling request asynchronously, the callback is invoked when response is ready
err_callbackcallablenoNoneIf handling request asynchronously, error callback is invoked when exception is raised

Returns#

Returns a TargetDeliveryResponse if called synchronously (default), or an AsyncResult if called with a callback. TargetDeliveryResponse has the following structure:

NameTypeDescription
responseDeliveryResponseConforms to the Target Delivery API response
target_cookiedictTarget cookie
target_location_hint_cookiedictTarget location hint cookie
analytics_detailslist[AnalyticsResponse]Analytics payload, in case of client side Analytics usage
tracelist[dict]
response_tokenslist[dict]A list of ​Response Tokens
metadictAdditional decisioning metadata for use with on-device-decisioning

Example#

First, let's build the Target Delivery API request for prefetching content for the home and product1 mboxes.

Copied to your clipboard
1mboxes = [MboxRequest(name="home"),
2 MboxRequest(name="product1")]
3prefetch = PrefetchRequest(mboxes=mboxes)
4delivery_request = DeliveryRequest(prefetch=prefetch)
5
6# Next, we fetch the offers via Target Python SDK getOffers() API
7response = target_client.get_offers({ "request": delivery_request })

A successful response will contain a Target Delivery API response object, which contains prefetched content for the requested mboxes. A sample target_response["response"] object (formatted as a dict) may appear as follows:

Copied to your clipboard
1{
2 "status": 200,
3 "requestId": "e8ac2dbf5f7d4a9f9280f6071f24a01e",
4 "id": {
5 "tntId": "08210e2d751a44779b8313e2d2692b96.21_27"
6 },
7 "client": "adobetargetmobile",
8 "edgeHost": "mboxedge21.tt.omtrdc.net",
9 "prefetch": {
10 "mboxes": [
11 {
12 "index": 0,
13 "name": "home",
14 "options": [
15 {
16 "type": "html",
17 "content": "HOME OFFER",
18 "eventToken": "t0FRvoWosOqHmYL5G18QCZNWHtnQtQrJfmRrQugEa2qCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==",
19 "responseTokens": {
20 "profile.memberlevel": "0",
21 "geo.city": "dublin",
22 "activity.id": "302740",
23 "experience.name": "Experience B",
24 "geo.country": "ireland"
25 }
26 }
27 ],
28 "state": "J+W1Fq18hxliDDJonTPfV0S+mzxapAO3d14M43EsM9f12A6QaqL+E3XKkRFlmq9U"
29 },
30 {
31 "index": 1,
32 "name": "product1",
33 "options": [
34 {
35 "type": "html",
36 "content": "TEST OFFER 1",
37 "eventToken": "t0FRvoWosOqHmYL5G18QCZNWHtnQtQrJfmRrQugEa2qCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q==",
38 "responseTokens": {
39 "profile.memberlevel": "0",
40 "geo.city": "dublin",
41 "activity.id": "302740",
42 "experience.name": "Experience B",
43 "geo.country": "ireland"
44 }
45 }
46 ],
47 "state": "J+W1Fq18hxliDDJonTPfV0S+mzxapAO3d14M43EsM9f12A6QaqL+E3XKkRFlmq9U"
48 }
49 ]
50 }
51}

Note the mbox name and state fields, as well as the eventToken field, in each of the Target content options. These should be provided in the send_notifications() request, as soon as each content option is displayed. Let's suppose the product1 mbox has been displayed on a non-browser device. The notifications request will appear as follows:

Copied to your clipboard
1notification_mbox = NotificationMbox(name="product1",
2 state="J+W1Fq18hxliDDJonTPfV0S+mzxapAO3d14M43EsM9f12A6QaqL+E3XKkRFlmq9U")
3notification = Notification(
4 id="1",
5 type=MetricType.DISPLAY,
6 timestamp=1621530726000, # Epoch time in milliseconds
7 mbox=notification_mbox,
8 tokens=["t0FRvoWosOqHmYL5G18QCZNWHtnQtQrJfmRrQugEa2qCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q=="]
9)
10notification_request = DeliveryRequest(notifications=[notification])

Notice we have included both the mbox state and the event token corresponding to the Target offer delivered in the prefetch response. Having built the notifications request, we can send it to Target via the send_notifications() API method:

Copied to your clipboard
response = target_client.send_notifications({ "request": notification_request })
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.