A3 : Learn what's under the hood in the Target Node.js SDK - adobe-target/serverside-testing GitHub Wiki
Level | Beginner |
---|---|
Time | 5 mins |
IMPORTANT
The node client used in this demo application is a proof of concept and shouldn't be used in your production applications. If you are interested in using Target in a node.js rendered application, please reach out to [email protected] or your customer success manager.
Target Node Client
Target Node Client is a very simple NodeJS library that eases the usage of Adobe Target Server to Server API in a NodeJS application. The library can be found here. The library is in beta and is not recommended for use in production applications. If you are interested in using it in a production app, please reach out to your account team.
The current Target Node Client library exposes just a single function that is used to instantiate the client. The function takes an options
JavaScript object that provides the necessary configurations. Here are the available configurations:
Name | Required | Default | Description |
---|---|---|---|
client | Yes | None | Adobe Target client code |
timeout | No | 3000 | Request timeout in ms |
host | No | tt.omtrdc.net | Target Edge Host |
secure | No | true | Use HTTPS or HTTP |
debug | No | false | If used outputs debug info about Adobe Target requests and responses |
Here is an example how you might use the configuration to instantiate the Target Client:
const createTargetNodeClient = require("@adobe/target-node-client");
const targetNodeClient = createTargetNodeClient({
client: "acmecompany",
host: "acmecompany.tt.omtrdc.net",
secure: false,
timeout: 10000,
debug: true
});
Executing requests
After figuring out the necessary configurations we can instantiate the client. Once client instance is created we can start firing requests against Adobe Target servers. To do that we have to invoke the execute()
method passing a data
payload object and optionally request
and response
.
When executing requests against Adobe Target servers there are two modes of operations:
- with user tracking
- without user tracking
By user tracking we are referring to the possibility of sending cookies to user's browser, such that on subsequent requests from the same browser Adobe Target will be able to identify and use the same user profile. In order for this to work we will have to pass to execute()
method the request
and response
parameters. These parameters are NodeJS HTTP request and response objects, that are used to read and write cookies, which allow us to track the user.
In case default cookie based user tracking is not enough, like for example when your NodeJS application uses other session storage mechanism, then we can pass to execute()
method just the data
parameter, omitting the optional ones.
Here are a few examples, how you might use the instantiated Target Node Client:
- With user tracking
targetNodeClient.execute(data, req, res)
.then(response => {
console.log('response', response);
return {
content: response.content
};
})
.catch(error => {
console.log('error', error);
return null;
});
- Without user tracking
targetNodeClient.execute(data)
.then(response => {
console.log('response', response);
return {
content: response.content
};
})
.catch(error => {
console.log('error', error);
return null;
});
Marketing Cloud ID Service integration
The Target React Sample App has the Marketing Cloud ID Service integration included out of the box. In order to use Marketing Cloud ID Service in the NodeJS application, we have to include Visitor API server module, that can be found here.
The Visitor API server module is responsible for:
- Adobe Analytics to Adobe Target integration
- Adobe Audience Manager to Adobe Target integration
NOTE: In the server side scenario, segments from Adobe Audience Manager can be used ONLY after the first hit for a completely new visitor.
Adobe Analytics integration
The Target React Sample App has the Adobe Analytics integration included out of the box. In this particular application we have a hybrid approach, since Adobe Target requests are fired from server side while Adobe Analytics hits are fired from client side.
In order to verify that Adobe Analytics hits are fired, you could open Chrome Developer Tools -> Network tab and search for Adobe Analytics requests. You should see something like this: