Skip to content

Commit f7b7ab2

Browse files
XDexartur-ciocanu
authored andcommitted
Samples for Target Node.js SDK v1.0.0 using Delivery API (adobe#5)
1 parent 91fe112 commit f7b7ab2

File tree

185 files changed

+24981
-24937
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+24981
-24937
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# package directories
22
node_modules
33
jspm_packages
4+
.idea

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1-
# Marketing Cloud Client Samples
2-
3-
This repository contains samples that use Marketing Cloud Client. Here is the list of samples:
4-
- `target-only` - shows how Marketing Cloud Client can be used in isolation
5-
- `mcid-integration` - shows how Marketing Cloud Client can be used in conjunction with MCID (Visitor API)
6-
- `mcid-customer-ids-integration` - shows how Marketing Cloud Client can be used in conjunction with MCID (Visitor API) and customer IDs. Customer IDs are useful in scenarios when user is logged in.
7-
- `mcid-analytics-integration` - shows how Marketing Cloud Client can be used in conjunction with MCID (Visitor API) and Adobe Analytics.
8-
- `mcid-analytics-atjs-integration` - shows how Marketing Cloud Client can be used in conjunction with MCID (Visitor API), Adobe Analytics and at.js. This sample shows how you can execute "hybrid" tests, when the test is started on the server side and then it is handed off to at.js on the client side.
9-
- `target-traces` - shows how Marketing Cloud Client can be used to retrieve Target execution traces.
10-
- `batch-mbox-v2-api-mcid-analytics-atjs-integration` - shows how Marketing Cloud Client can be used to execute Batch Mbox v2 API requests.
11-
12-
For more documentation please check: https://www.npmjs.com/package/@adobe/target-node-client.
1+
# Target Node.js SDK Samples & Demos
2+
3+
This repository contains samples and demos for the [Target Node.js SDK](https://www.npmjs.com/package/@adobe/target-nodejs-sdk)
4+
5+
## Demos
6+
7+
- [react-shopping-cart-demo](react-shopping-cart-demo) - a demo showing how to fetch and inject Target offers in a
8+
[React Redux](https://react-redux.js.org/) app on the server side and then instantly apply the offers on the client side,
9+
without any additional client-side Target calls. Check out the [Live Demo](http://target-nodejs-react-sample.eu-west-1.elasticbeanstalk.com).
10+
- [next-server-side-rendering-demo](next-server-side-rendering-demo) - a demo showing how to fetch and inject Target offers
11+
in a [Next.js](https://nextjs.org/) server-side rendered app, and then instantly apply the offers on the client side,
12+
without any additional client-side Target calls. Check out the [Live Demo](http://target-nodejs-ssr-sample.eu-west-1.elasticbeanstalk.com).
13+
14+
## Samples
15+
16+
- [target-only](target-only) - shows how Target Node.js SDK can be used in isolation
17+
- [ecid-integration](ecid-integration) - shows how Target Node.js SDK can be used in conjunction with ECID (Visitor API)
18+
- [ecid-customer-ids-integration](ecid-customer-ids-integration) - shows how Target Node.js SDK can be used in
19+
conjunction with ECID (Visitor API) and Customer IDs, useful for tracking user authentication.
20+
- [ecid-analytics-integration](ecid-analytics-integration) - shows how Target Node.js SDK can be used in conjunction
21+
with ECID (Visitor API) and Adobe Analytics.
22+
- [ecid-analytics-atjs-integration](ecid-analytics-atjs-integration) - shows how Target Node.js SDK can be used in
23+
conjunction with ECID (Visitor API), Adobe Analytics and at.js. This sample shows how to run testing in "hybrid" mode,
24+
when the test is started on the server side and then it is handed off to at.js on the client side.
25+
- [advanced-atjs-integration-serverstate](advanced-atjs-integration-serverstate) - shows how to use at.js v2.2+ **serverState** feature to apply Target offers fetched on the server side, without any additional client side content-fetching Target calls.
26+
- [target-traces](target-traces) - shows how Target Node.js SDK can be used to retrieve Target execution traces.
27+
- [shared-ecid-analytics-integration](shared-ecid-analytics-integration) - shows how to properly handle multiple Target
28+
Node.js SDK API calls when processing a client request, sharing the same ECID instance.
29+
- [multiple-mbox-ecid-analytics-atjs-integration](multiple-mbox-ecid-analytics-atjs-integration) - shows how Target
30+
Node.js SDK can be used to request content for multiple mboxes in the same Target call.
31+
32+
For Target Node.js SDK documentation, see [Target Node.js SDK NPM page](https://www.npmjs.com/package/@adobe/target-nodejs-sdk).
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Advanced at.js integration via serverState sample
2+
3+
In the `ecid-analytics-atjs-integration` sample, we've showcased "hybrid" Target integration, where both the server-side and the client-side Target libraries are hitting the same Target edge cluster, sharing the same Target session and visitor state. However, at.js still needs to go over the wire for fetching Target content in the browser, prehiding the whole page BODY until Target offers are fetched and applied.
4+
5+
But what if we could prefetch the Target content on the server-side, include it in the page returned to the client, and then just have at.js apply the Target offers immediately, without making another expensive network call?
6+
Also, in this case at.js will be able to prehide only the specific DOM elements for which Target offers have been fetched on the server-side, thus no longer requiring the prehiding of the whole page BODY.
7+
8+
Target `serverState` is a new feature available in at.js v2.2+, that allows at.js to apply Target offers directly from content fetched on the server side and returned to the client as part of the page being served.
9+
10+
In order to use this feature with Target Node.js SDK we just have to set `window.targetGlobalSettings.serverState` object in the returned page, from Target Delivery API request and response objects available after a successfull `getOffers()` API call, as follows:
11+
12+
```js
13+
// First, we fetch the offers via Target Node.js SDK API, as usual
14+
const targetResponse = await targetClient.getOffers(options);
15+
// A successfull response will contain Target Delivery API request and response objects, which we need to set as serverState
16+
const serverState = {
17+
request: targetResponse.request,
18+
response: targetResponse.response
19+
};
20+
// Finally, we should set window.targetGlobalSettings.serverState in the returned page, by replacing it in a page template, for example
21+
const PAGE_TEMPLATE = `
22+
<!doctype html>
23+
<html>
24+
<head>
25+
...
26+
<script>
27+
window.targetGlobalSettings = {
28+
overrideMboxEdgeServer: true,
29+
serverState: ${JSON.stringify(serverState, null, " ")}
30+
};
31+
</script>
32+
<script src="at.js"></script>
33+
</head>
34+
...
35+
</html>
36+
`;
37+
// Return PAGE_TEMPLATE to the client ...
38+
```
39+
40+
Once the page is loaded in the browser, at.js will apply all the Target offers from `serverState` immediately, without firing any network calls against the Target edge. Additionally, at.js will only prehide the DOM elements for which Target offers are available in the content fetched server-side, thus greatly improving page load performance and end-user experience.
41+
42+
Note: In case of SPAs using [Target Views and triggerView() at.js API](https://docs.adobe.com/content/help/en/target/using/implement-target/client-side/functions-overview/adobe-target-triggerview-atjs-2.html), at.js will cache the content for all Views prefetched on the server-side and apply these as soon as each View is triggered via `triggerView()`, again without firing any additional content-fetching calls to Target.
43+
44+
## Usage
45+
1. Install dependencies: `npm i`
46+
2. Start: `npm start`

0 commit comments

Comments
 (0)