Hello there,
I am using NodeSDK on the react code base to send requests to prefetch offers. I am seeing most of the values are coming back undefined from the Adobe server, is there a reason? Am I missing anything in the request?
My request is simple:
prefetch: {
mboxes: [
{
index: 0,
name: 'mbox Name'
}
]
}
Views
Replies
Total Likes
Hi @Pravinrams1
At initial level, check that your Node SDK is properly initialized with the correct credentials. Incorrect or missing configuration for the Adobe services (like credentials, API keys, or tenant information) could result in invalid responses.
2) Make sure your Mbox is active and exists in Adobe Target.
3) When using the prefetch
method, ensure that you're not confusing it with execute
in your code. prefetch
is for retrieving offers in advance, but if the configuration or targeting is off, it could return undefined.
4) Caching issues - Sometimes cached offers or mismatches in timing (when the prefetch request is made vs when it's used) can cause issues. Please clear your cache.
5) Use logger optional object - in order to debug.
Here is the sample code again
import AdobeTargetClient from '@adobe/target-nodejs-sdk';
// Initialize client
const client = AdobeTargetClient.create({
client: '<YOUR_CLIENT_ID>',
organizationId: '<YOUR_ORG_ID>',
apiKey: '<YOUR_API_KEY>',
targetHostname: 'your-target-url',
logger: console
});
// Prefetch offers
client.getOffers({
sessionId: '<SESSION_ID>',
visitorId: '<VISITOR_ID>',
context: {
channel: 'web',
address: {
url: 'https://your-site.com',
},
browser: {
host: 'your-site.com',
userAgent: navigator.userAgent,
},
},
prefetch: {
mboxes: [
{
name: 'your-mbox-name',
index: 0
}
]
}
}).then((response) => {
console.log(response);
}).catch((error) => {
console.error('Error fetching offers:', error);
});
Views
Replies
Total Likes
Thank you @Gokul_Agiwal
It was an issue with windows.targetGlobalsettings and it's now working and getting a response from the server with the content. I can see prefetch only has getoffers not applyoffers like Client Side. How do I then apply the script I received from Adobe to the actual webpage page?
One more question: On the request I see you used navigator.userAgent to get the browser details but it only works on the client side because navigator is not available on the server side right?
AT Response (I masked some of the info because not sure if it can be public):
Views
Replies
Total Likes
Hi @Pravinrams1 Sorry for late, did you solve your prefetch issues or you still looking for answer.
and yes about Navigator you're correct.
Also May I ask which option / method you set / update in windows.targetGlobalsettings so that others also get benefit to know.
Thanks.,
Views
Replies
Total Likes
Hello Gokul,
I am now able to see the content from the Adobe Target to our server-side using prefetch but how do I then execute the script using prefetch is what I am confused about. If you see the screenshot in my last message you can see the response has the script that needs to be executed on the page but I don't know how to get that executed on the actual page?
It would be really helpful if you could help me apply the script on the actual page. Thanks!
For windows.targetglobalsettings below is what I set:
window.targetGlobalSettings = {
overrideMboxEdgeServer: true,
clientCode: props.target.client,
imsOrgId: props.target.organizationId,
serverDomain: props.target.serverDomain,
serverState: JSON.stringify(props?.target?.serverState || {}, null, ' ')
};;
Thanks
Praveen
Views
Replies
Total Likes
Hi Praveen @Pravinrams1
Sorry for delay in response . As next steps you can use the method called sendNotifications(). This method must be used for prefetched experiences for incrementing impressions and conversions.
on below link - there is sample code where you need to provide mbox name and state field to sendNotification() method.
So you can use the those attribute from your response ( refer screenshot you added ) you received in Prefetch.
So basically, Prefetching allows clients like mobile apps and servers to fetch content for multiple mboxes or views in one request, cache it locally, and later notify Target when the visitor visits those mboxes or views.
You can read more about Prefetch and Notifications.
Let me know how its goes.
Hope this helps.
Views
Replies
Total Likes
Hi @Pravinrams1 Is this your issues sorted? Are you able to execute the offer on page?
Views
Replies
Total Likes