Edit in GitHubLog an issue

Experience Cloud ID (ECID) Service

Experience Cloud ID (ECID) Integration#

Although using the Target SDKs for fetching content from Target can be powerful, the added value of using the Experience Cloud ID (ECID) for user tracking extends beyond Adobe Target. The ECID enables you to leverage Adobe Experience Cloud products and features, such as A4T reporting and Adobe Audience Manager (AAM) segments.

The ECID is generated and maintained by visitor.js, which maintains its own state. The visitor.js file creates a cookie named AMCV_{organizationId}, which is used by Target SDKs for ECID integration. When the Target response is returned, you need to update the Visitor instance on the client side with thevisitorState returned by the Target SDKs.

Copied to your clipboard
1<!doctype html>
2<html>
3<head>
4 <meta charset="UTF-8">
5 <title>ECID (Visitor API) Integration Sample</title>
6 <script src="VisitorAPI.js"></script>
7 <script>
8 Visitor.getInstance("${organizationId}", {serverState: ${visitorState}});
9 </script>
10</head>
11<body>
12 <pre>Sample content</pre>
13</body>
14</html>

Node.js#

Copied to your clipboard
1const express = require("express");
2const cookieParser = require("cookie-parser");
3const TargetClient = require("@adobe/target-nodejs-sdk");
4const CONFIG = {
5 client: "acmeclient",
6 organizationId: "1234567890@AdobeOrg"
7};
8const TEMPLATE = `
9<!doctype html>
10<html>
11<head>
12 <meta charset="UTF-8">
13 <title>ECID (Visitor API) Integration Sample</title>
14 <script src="VisitorAPI.js"></script>
15 <script>
16 Visitor.getInstance("${organizationId}", {serverState: ${visitorState}});
17 </script>
18</head>
19<body>
20 <pre>${content}</pre>
21</body>
22</html>
23`;
24
25const app = express();
26const targetClient = TargetClient.create(CONFIG);
27
28app.use(cookieParser());
29// We assume that VisitorAPI.js is stored in "public" folder
30app.use(express.static(__dirname + "/public"));
31
32function saveCookie(res, cookie) {
33 if (!cookie) {
34 return;
35 }
36
37 res.cookie(cookie.name, cookie.value, {maxAge: cookie.maxAge * 1000});
38}
39
40const getResponseHeaders = () => ({
41 "Content-Type": "text/html",
42 "Expires": new Date().toUTCString()
43});
44
45function sendSuccessResponse(res, response) {
46 res.set(getResponseHeaders());
47
48 const result = TEMPLATE
49 .replace("${organizationId}", CONFIG.organizationId)
50 .replace("${visitorState}", JSON.stringify(response.visitorState))
51 .replace("${content}", response);
52
53 saveCookie(res, response.targetCookie);
54
55 res.status(200).send(result);
56}
57
58function sendErrorResponse(res, error) {
59 res.set(getResponseHeaders());
60 res.status(500).send(error);
61}
62
63app.get("/abtest", async (req, res) => {
64 const visitorCookie = req.cookies[TargetClient.getVisitorCookieName(CONFIG.organizationId)];
65 const targetCookie = req.cookies[TargetClient.TargetCookieName];
66 const request = {
67 execute: {
68 mboxes: [{
69 address: { url: req.headers.host + req.originalUrl },
70 name: "a1-serverside-ab"
71 }]
72 }};

Java#

Copied to your clipboard
1 console.log("Request", request);
2
3 try {
4 const response = await targetClient.getOffers({ request, visitorCookie, targetCookie });
5 sendSuccessResponse(res, response);
6 } catch (error) {
7 sendErrorResponse(res, error);
8 }
9});
10
11app.listen(3000, function () {
12 console.log("Listening on port 3000 and watching!");
13});
14@Controller
15public class TargetControllerSample {
16
17 @Autowired
18 private TargetClient targetClient;
19
20 @GetMapping("/")
21 public String targetMcid(Model model, HttpServletRequest request, HttpServletResponse response) {
22 Context context = getContext(request);
23 TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder()
24 .context(context)
25 .prefetch(getPrefetchRequest())
26 .cookies(getTargetCookies(request.getCookies()))
27 .build();
28
29 TargetDeliveryResponse targetResponse = targetClient.getOffers(targetDeliveryRequest);
30 model.addAttribute("visitorState", targetResponse.getVisitorState());
31 model.addAttribute("organizationId", "0DD934B85278256B0A490D44@AdobeOrg");
32 setCookies(targetResponse.getCookies(), response);
33 return "targetMcid";
34 }
35}

ECID with Customer ID Integration#

In order to track visitor user accounts and login status details, customerIds may be passed via Target SDKs.

Copied to your clipboard
1<!doctype html>
2<html>
3<head>
4 <meta charset="UTF-8">
5 <title>ECID (Visitor API) Integration Sample</title>
6 <script src="VisitorAPI.js"></script>
7 <script>
8 Visitor.getInstance("${organizationId}", {serverState: ${visitorState}});
9 </script>
10</head>
11<body>
12 <pre>Sample content</pre>
13</body>
14</html>

Node.js#

Copied to your clipboard
1const express = require("express");
2const cookieParser = require("cookie-parser");
3const TargetClient = require("@adobe/target-nodejs-sdk");
4const CONFIG = {
5 client: "acmeclient",
6 organizationId: "1234567890@AdobeOrg"
7};
8const TEMPLATE = `
9<!doctype html>
10<html>
11<head>
12 <meta charset="UTF-8">
13 <title>ECID (Visitor API) with Customer IDs Integration Sample</title>
14 <script src="VisitorAPI.js"></script>
15 <script>
16 Visitor.getInstance("${organizationId}", {serverState: ${visitorState}});
17 </script>
18</head>
19<body>
20 <pre>${content}</pre>
21</body>
22</html>
23`;
24
25const app = express();
26const targetClient = TargetClient.create(CONFIG);
27
28app.use(cookieParser());
29// We assume that VisitorAPI.js is stored in "public" folder
30app.use(express.static(__dirname + "/public"));
31
32function saveCookie(res, cookie) {
33 if (!cookie) {
34 return;
35 }
36
37 res.cookie(cookie.name, cookie.value, {maxAge: cookie.maxAge * 1000});
38}
39
40const getResponseHeaders = () => ({
41 "Content-Type": "text/html",
42 "Expires": new Date().toUTCString()
43});
44
45function sendSuccessResponse(res, response) {
46 res.set(getResponseHeaders());
47
48 const result = TEMPLATE
49 .replace("${organizationId}", CONFIG.organizationId)
50 .replace("${visitorState}", JSON.stringify(response.visitorState))
51 .replace("${content}", response);
52
53 saveCookie(res, response.targetCookie);
54
55 res.status(200).send(result);
56}
57
58function sendErrorResponse(res, error) {
59 res.set(getResponseHeaders());
60 res.status(500).send(error);
61}
62
63app.get("/abtest", async (req, res) => {
64 const visitorCookie = req.cookies[TargetClient.getVisitorCookieName(CONFIG.organizationId)];
65 const targetCookie = req.cookies[TargetClient.TargetCookieName];
66 const customerIds = {
67 "userid": {
68 "id": "67312378756723456",
69 "authState": TargetClient.AuthState.AUTHENTICATED
70 }
71 };
72 const request = {
73 execute: {
74 mboxes: [{
75 address: { url: req.headers.host + req.originalUrl },
76 name: "a1-serverside-ab"
77 }]
78 }};
79
80 try {
81 const response = await targetClient.getOffers({ request, visitorCookie, targetCookie, customerIds });
82 sendSuccessResponse(res, response);
83 } catch (error) {
84 sendErrorResponse(res, error);
85 }
86});
87
88app.listen(3000, function () {
89 console.log("Listening on port 3000 and watching!");
90});

Java#

Copied to your clipboard
1@Controller
2public class TargetControllerSample {
3
4 @Autowired
5 private TargetClient targetJavaClient;
6
7 @GetMapping("/targetMcid")
8 public String targetMcid(Model model, HttpServletRequest request, HttpServletResponse response) {
9 Context context = getContext(request);
10 Map<String, CustomerState> customerIds = new HashMap<>();
11 customerIds.put("userid", CustomerState.authenticated("67312378756723456"));
12 customerIds.put("puuid", CustomerState.unknown("550e8400-e29b-41d4-a716-446655440000"));
13 TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder()
14 .context(context)
15 .prefetch(getPrefetchRequest())
16 .cookies(getTargetCookies(request.getCookies()))
17 .customerIds(customerIds)
18 .build();
19
20 TargetDeliveryResponse targetResponse = targetJavaClient.getOffers(targetDeliveryRequest);
21 model.addAttribute("visitorState", targetResponse.getVisitorState());
22 model.addAttribute("organizationId", "0DD934B85278256B0A490D44@AdobeOrg");
23 setCookies(targetResponse.getCookies(), response);
24 return "targetMcid";
25 }
26}

ECID and Analytics Integration#

To get the most out of the Target SDKs, and to use the powerful analytics capabilities provided by Adobe Analytics, you can use integrations across ECID, Analytics, and Target.

Using integrations across ECID, Analytics, and Target lets you:

  • Use segments from Adobe Audience Manager (AAM)
  • Customize the user experience based on the content retrieved from Target
  • Ensure that all events and success metrics are collected in Analytics
  • Use Analytics' powerful queries and benefit from its awesome report visualizations

Integrations across ECID, Analytics, and Target do not require any special handling for analytics on the server side. Instead, once you have the ECID integrated, add AppMeasurement.js (Analytics library) on the client side. Analytics then uses the Visitor instance to synchronize with Target.

Copied to your clipboard
1<!doctype html>
2<html>
3<head>
4 <meta charset="UTF-8">
5 <title>ECID and Analytics integration Sample</title>
6 <script src="VisitorAPI.js"></script>
7 <script>
8 Visitor.getInstance("${organizationId}", {serverState: ${visitorState}});
9 </script>
10</head>
11<body>
12 <p>Sample content</p>
13 <script src="AppMeasurement.js"></script>
14 <script>var s_code=s.t();if(s_code)document.write(s_code);</script>
15</body>
16</html>

Node.js#

Copied to your clipboard
1const express = require("express");
2const cookieParser = require("cookie-parser");
3const TargetClient = require("@adobe/target-nodejs-sdk");
4const CONFIG = {
5 client: "acmeclient",
6 organizationId: "1234567890@AdobeOrg"
7};
8const TEMPLATE = `
9<!doctype html>
10<html>
11<head>
12 <meta charset="UTF-8">
13 <title>ECID and Analytics integration Sample</title>
14 <script src="VisitorAPI.js"></script>
15 <script>
16 Visitor.getInstance("${organizationId}", {serverState: ${visitorState}});
17 </script>
18</head>
19<body>
20 <p>${content}</p>
21 <script src="AppMeasurement.js"></script>
22 <script>var s_code=s.t();if(s_code)document.write(s_code);</script>
23</body>
24</html>
25`;
26
27const app = express();
28const targetClient = TargetClient.create(CONFIG);
29
30app.use(cookieParser());
31// We assume that VisitorAPI.js and AppMeasurement.js are stored in "public" directory
32app.use(express.static(__dirname + "/public"));
33
34function saveCookie(res, cookie) {
35 if (!cookie) {
36 return;
37 }
38
39 res.cookie(cookie.name, cookie.value, {maxAge: cookie.maxAge * 1000});
40}
41
42const getResponseHeaders = () => ({
43 "Content-Type": "text/html",
44 "Expires": new Date().toUTCString()
45});
46
47function sendSuccessResponse(res, response) {
48 res.set(getResponseHeaders());
49
50 const result = TEMPLATE
51 .replace("${organizationId}", CONFIG.organizationId)
52 .replace("${visitorState}", JSON.stringify(response.visitorState))
53 .replace("${content}", response);
54
55 saveCookie(res, response.targetCookie);
56
57 res.status(200).send(result);
58}
59
60function sendErrorResponse(res, error) {
61 res.set(getResponseHeaders());
62
63 res.status(500).send(error);
64}
65
66app.get("/abtest", async (req, res) => {
67 const visitorCookie = req.cookies[TargetClient.getVisitorCookieName(CONFIG.organizationId)];
68 const targetCookie = req.cookies[TargetClient.TargetCookieName];
69 const request = {
70 execute: {
71 mboxes: [{
72 address: { url: req.headers.host + req.originalUrl },
73 name: "a1-serverside-ab"
74 }]
75 }};
76
77 try {
78 const response = await targetClient.getOffers({ request, visitorCookie, targetCookie });
79 sendSuccessResponse(res, response);
80 } catch (error) {
81 sendErrorResponse(res, error);
82 }
83});
84
85app.listen(3000, function () {
86 console.log("Listening on port 3000 and watching!");
87});

Java#

Copied to your clipboard
1@Controller
2public class TargetControllerSample {
3
4 @Autowired
5 private TargetClient targetJavaClient;
6
7 @GetMapping("/targetAnalytics")
8 public String targetMcid(Model model, HttpServletRequest request, HttpServletResponse response) {
9 Context context = getContext(request);
10 Map<String, CustomerState> customerIds = new HashMap<>();
11 customerIds.put("userid", CustomerState.authenticated("67312378756723456"));
12 customerIds.put("puuid", CustomerState.unknown("550e8400-e29b-41d4-a716-446655440000"));
13 TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder()
14 .context(context)
15 .prefetch(getPrefetchRequest())
16 .cookies(getTargetCookies(request.getCookies()))
17 .customerIds(customerIds)
18 .trackingServer("imsbrims.sc.omtrds.net")
19 .build();
20
21 TargetDeliveryResponse targetResponse = targetJavaClient.getOffers(targetDeliveryRequest);
22 model.addAttribute("visitorState", targetResponse.getVisitorState());
23 model.addAttribute("organizationId", "0DD934B85278256B0A490D44@AdobeOrg");
24 setCookies(targetResponse.getCookies(), response);
25 return "targetAnalytics";
26 }
Was this helpful?
  • Privacy
  • Terms of Use
  • Do not sell my personal information
  • AdChoices
Copyright © 2022 Adobe. All rights reserved.