Invio di notifiche (Java)
- Argomenti:
- APIs/SDKs
Creato per:
- Sviluppatore
Descrizione
sendNotifications()
viene utilizzato per inviare notifiche di visualizzazione o clic a Adobe Target per la misurazione e il reporting.
execute
con parametri obbligatori si trova all'interno della richiesta stessa, l'impression verrà incrementata automaticamente per le attività idonee.I metodi SDK che incrementano automaticamente un’impression sono:
getOffers()
getAttributes()
Quando un oggetto prefetch
viene passato all'interno della richiesta, l'impression non viene incrementata automaticamente per le attività con mbox all'interno dell'oggetto prefetch
. sendNotifications()
deve essere utilizzato per le esperienze preacquisite per incrementare impressioni e conversioni.
Metodo
creare
ResponseStatus TargetClient.sendNotifications(TargetDeliveryRequest request)
Esempio
Innanzitutto, compiliamo la richiesta Target Delivery API per preacquisire il contenuto per le mbox home
e product1
.
Preacquisizione
List<MboxRequest> mboxRequests = new ArrayList<>();
mboxRequests.add((MboxRequest) new MboxRequest().name("home").index(1));
mboxRequests.add((MboxRequest) new MboxRequest().name("product1").index(2));
PrefetchRequest prefetchMboxesRequest = new PrefetchRequest().setMboxes(mboxRequests)
// Next, we fetch the offers via Target Java SDK getOffers() API
TargetDeliveryResponse targetResponse = targetJavaClient.getOffers(targetDeliveryRequest);
In caso di esito positivo, la risposta conterrà un oggetto di risposta Target Delivery API contenente contenuto prerecuperato per le mbox richieste. Un oggetto targetResponse.response
di esempio potrebbe avere il seguente aspetto:
Risposta
{
"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"
}
]
}
}
Prendere nota dei campi mbox name
e state
, nonché del campo eventToken
, in ciascuna delle opzioni di contenuto Target. Questi devono essere forniti nella richiesta sendNotifications()
, non appena viene visualizzata ogni opzione di contenuto. Supponiamo che la mbox product1
sia stata visualizzata su un dispositivo non browser. La richiesta di notifica avrà un aspetto simile al seguente:
Richiesta
TargetDeliveryRequest mboxNotificationRequest = TargetDeliveryRequest.builder().notifications(new ArrayList() {{
add(new Notification()
.id("1")
.timestamp(System.currentTimeMillis())
.type(MetricType.DISPLAY)
.mbox(new NotificationMbox()
.name("product1")
.state("J+W1Fq18hxliDDJonTPfV0S+mzxapAO3d14M43EsM9f12A6QaqL+E3XKkRFlmq9U")
)
.tokens(Arrays.asList(new String[]{"t0FRvoWosOqHmYL5G18QCZNWHtnQtQrJfmRrQugEa2qCnQ9Y9OaLL2gsdrWQTvE54PwSz67rmXWmSnkXpSSS2Q=="}))
);
}}).build();
Nella risposta di preacquisizione sono stati inclusi sia lo stato mbox che il token evento corrispondente all'offerta Target distribuita. Dopo aver generato la richiesta di notifiche, è possibile inviarla a Target tramite il metodo API sendNotifications()
:
Risposta
ResponseStatus notificationResponse = targetJavaClient.sendNotifications(mboxNotificationRequest);