AAM セグメント

Adobe Audience Manager個のセグメントはAdobe Target個のSDKを使用して活用できます。 AAM セグメントを活用するには、次のフィールドを指定する必要があります。

NOTE
AAM セグメントは、オンデバイス判定アクティビティではサポートされていません。
フィールド名
必須
説明
locationHint
○
DCS Location Hintは、プロファイルを取得するためにヒットするAAM DCS エンドポイントを決定するために使用されます。 >= 1にする必要があります。
marketingCloudVisitorId
○
Marketing Cloud 訪問者 ID
blob
○
AAM Blobは、AAMにデータを送信するために使用されます。 空白にせず、サイズ <= 1024を指定してください。

SDKでは、getOffers メソッド呼び出しを行う際に、これらのフィールドが自動的に入力されますが、有効な訪問者Cookieが提供されていることを確認する必要があります。 このCookieを取得するには、ブラウザーにVisitorAPI.jsを実装する必要があります。

実装ガイド

Cookieの使用

Cookieは、Adobe Audience Manager件のリクエストとAdobe Target件のリクエストを関連付けるために使用されます。 この実装で使用されるCookieです。

Cookie
名前
説明
訪問者Cookie
AMCVS_XXXXXXXXXXXXXXXXXXXXXXXX%40AdobeOrg
このCookieは、ターゲット getOffers応答からvisitorStateで初期化されたときにVisitorAPI.jsによって設定されます。
ターゲット Cookie
mbox
Web サーバーは、ターゲット getOffers応答のtargetCookieの名前と値を使用してこのCookieを設定する必要があります。

手順の概要

ユーザーがWeb サーバーにリクエストを送信するブラウザーにURLを入力するとします。 その要求を満たす場合:

  1. サーバーは、リクエストから訪問者とターゲット Cookieを読み取ります。

  2. サーバーはTarget SDKのgetOffers メソッドを呼び出し、訪問者とターゲット Cookieが使用可能な場合は指定します。

  3. getOffers呼び出しが満たされると、応答のtargetCookieとvisitorStateの値が使用されます。

    1. targetCookieから取得した値を使用して、応答にCookieが設定されます。 これは、Set-Cookie応答ヘッダーを使用して実行されます。このヘッダーは、ターゲット Cookieを保持するようにブラウザーに指示します。
    2. VisitorAPI.jsを初期化し、ターゲット応答からvisitorStateに渡すHTML応答が用意されています。
  4. HTMLの応答がブラウザーに読み込まれます…

    1. VisitorAPI.jsが文書ヘッダーに含まれています。
    2. VisitorAPIは、getOffers SDK応答からvisitorStateで初期化されます。 これにより、訪問者のCookieがブラウザーで設定され、その後のリクエストでサーバーに送信されます。

サンプルコード

次のコードサンプルは、上記の各手順を実装しています。 各ステップは、実装の横にインラインコメントとしてコードに表示されます。

Node.js

このサンプルは、Node.js web フレームワーク 🔗であるexpressに依存しています。

server.js
code language-js line-numbers
const fs = require("fs");
const express = require("express");
const cookieParser = require("cookie-parser");
const Handlebars = require("handlebars");
const TargetClient = require("@adobe/target-nodejs-sdk");

const CONFIG = {
  client: "acmeclient",
  organizationId: "1234567890@AdobeOrg",
  timeout: 10000,
  logger: console,
};
const targetClient = TargetClient.create(CONFIG);
const TEMPLATE = fs.readFileSync(`${__dirname}/index.handlebars`).toString();
const handlebarsTemplate = Handlebars.compile(TEMPLATE);

Handlebars.registerHelper("toJSON", function (object) {
  return new Handlebars.SafeString(JSON.stringify(object, null, 4));
});

const app = express();
app.use(cookieParser());
app.use(express.static(__dirname + "/public"));

app.get("/", async (req, res) => {
  // The server reads the visitor and target cookies from the request.
  const visitorCookie =
    req.cookies[
      encodeURIComponent(
        TargetClient.getVisitorCookieName(CONFIG.organizationId)
      )
    ];
  const targetCookie = req.cookies[TargetClient.TargetCookieName];
  const address = { url: req.headers.host + req.originalUrl };

  const targetRequest = {
    execute: {
      mboxes: [
        { name: "homepage", index: 1, address },
        { name: "SummerShoesOffer", index: 2, address },
        { name: "SummerDressOffer", index: 3, address }
      ],
    },
  };

  res.set({
    "Content-Type": "text/html",
    Expires: new Date().toUTCString(),
  });

  try {
    // The server makes a call to the `getOffers` method of the Target SDK specifying the visitor and target cookies if available.
    const targetResponse = await targetClient.getOffers({
      request: targetRequest,
      visitorCookie,
      targetCookie,
    });

    // When the `getOffers` call is fulfilled, values for `targetCookie` and `visitorState` from the response are used.
    // A cookie is set on the response with values taken from `targetCookie`.  This is done using the `Set-Cookie` response header which tells the browser to persist the target cookie.
    res.cookie(
      targetResponse.targetCookie.name,
      targetResponse.targetCookie.value,
      { maxAge: targetResponse.targetCookie.maxAge * 1000 }
    );

    // An HTML response is prepared that initializes VisitorAPI.js and passes in `visitorState` from the target response.
    const html = handlebarsTemplate({
      organizationId: CONFIG.organizationId,
      targetResponse,
    });

    res.status(200).send(html);
  } catch (error) {
    console.error("Target:", error);
    res.status(500).send(error);
  }
});

app.listen(3000, function () {
  console.log("Listening on port 3000 and watching!");
});
index.handlebars
code language-html line-numbers
<!doctype html>
<html>
<head>
  <meta charset="UTF-8">
  <title>ECID (Visitor API) Integration Sample</title>

  <!-- VisitorAPI.js is included in the document header. -->
  <script src="VisitorAPI.js"></script>
  <script>
    // VisitorAPI is initialized with visitorState from the `getOffers` SDK response. This will cause the visitor cookie to be set in the browser so it will be sent to the server on subsequent requests.
    Visitor.getInstance("{{organizationId}}", {serverState: {{toJSON targetResponse.visitorState}} });
  </script>
</head>
<body>
  <h1>response</h1>
  <pre>{{toJSON targetResponse}}</pre>
</body>
</html>

Java

このサンプルでは、Java web フレームワーク 🔗であるspringを使用しています。

ClientSampleApplication.java
code language-java line-numbers
@SpringBootApplication
public class ClientSampleApplication {

    public static void main(String[] args) {
        System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "DEBUG");
        SpringApplication.run(ClientSampleApplication.class, args);
    }

    @Bean
    TargetClient marketingCloudClient() {
        ClientConfig clientConfig = ClientConfig.builder()
                .client("acmeclient")
                .organizationId("1234567890@AdobeOrg")
                .defaultDecisioningMethod(DecisioningMethod.SERVER_SIDE)
                .build();

        return TargetClient.create(clientConfig);
    }
}
TargetController.java
code language-java line-numbers
@Controller
@RequestMapping("/")
public class TargetController {

    @Autowired
    private TargetClientService targetClientService;

    @GetMapping
    public String index(Model model, HttpServletRequest request, HttpServletResponse response) {
        // The server reads the visitor and target cookies from the request.
        List<TargetCookie> targetCookies = getTargetCookies(request.getCookies());

        Address address = getAddress(request);

        List<MboxRequest> mboxRequests = new ArrayList<>();
        mboxRequests.add((MboxRequest) new MboxRequest().name("homepage").index(1).address(address));
        mboxRequests.add((MboxRequest) new MboxRequest().name("SummerShoesOffer").index(2).address(address));
        mboxRequests.add((MboxRequest) new MboxRequest().name("SummerDressOffer").index(3).address(address));

        TargetDeliveryResponse targetDeliveryResponse = targetClientService.getOffers(mboxRequests, targetCookies, request,
                response);

        // An HTML response is prepared that initializes VisitorAPI.js and passes in `visitorState` from the target response.
        model.addAttribute("visitorState", targetDeliveryResponse.getVisitorState());
        model.addAttribute("targetResponse", targetDeliveryResponse);
        model.addAttribute("organizationId", "1234567890@AdobeOrg");

        return "index";
    }
}
TargetClientService.java
code language-java line-numbers
@Service
public class TargetClientService {

    private final TargetClient targetJavaClient;

    public TargetClientService(TargetClient targetJavaClient) {
        this.targetJavaClient = targetJavaClient;
    }

    public TargetDeliveryResponse getOffers(List<MboxRequest> executeMboxes, List<TargetCookie> cookies, HttpServletRequest request, HttpServletResponse response) {

        Context context = getContext(request);
        ExecuteRequest executeRequest = new ExecuteRequest();
        executeRequest.setMboxes(executeMboxes);

        TargetDeliveryRequest targetDeliveryRequest = TargetDeliveryRequest.builder()
                .context(context)
                .execute(executeRequest)
                .cookies(cookies)
                .build();

        // The server makes a call to the `getOffers` method of the Target SDK specifying the visitor and target cookies if available.
        TargetDeliveryResponse targetResponse = targetJavaClient.getOffers(targetDeliveryRequest);

        // When the `getOffers` call is fulfilled, values for `targetCookie` and `visitorState` from the response are used.
        // A cookie is set on the response with values taken from `targetCookie`.  This is done using the `Set-Cookie` response header which tells the browser to persist the target cookie.
        setCookies(targetResponse.getCookies(), response);
        return targetResponse;
    }
}
TargetRequestUtils.java
code language-java line-numbers
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Target Only : GetOffer</title>

    <!-- VisitorAPI.js is included in the document header. -->
    <script src="../../js/VisitorAPI.js"></script>
    <script th:inline="javascript">
        // VisitorAPI is initialized with visitorState from the `getOffers` SDK response. This will cause the visitor cookie to be set in the browser so it will be sent to the server on subsequent requests.
        Visitor.getInstance(/*[[${organizationId}]]*/ "", {serverState: /*[[${visitorState}]]*/ {}});
    </script>
</head>
<body>
    <h1>response</h1>
    <pre>[[${targetResponse}]]</pre>
</body>
</html>

TargetRequestUtils.javaについて詳しくは、​ ユーティリティ メソッド (Java) ​を参照してください

recommendation-more-help
target-dev-help-dev