フォームベースのコンポーザーを使用するTarget アクティビティのレンダリング

一部のTarget実装では、フォームベースのExperience Composerを使用するアクティビティからコンテンツを配信するために、地域のmbox (現在は「スコープ」と呼ばれます)を使用する場合があります。 at.js Targetの実装でmboxを使用する場合は、次の操作を行う必要があります。

  • getOffer()またはgetOffers()を使用するat.js実装からの参照を、同等のPlatform Web SDK メソッドに更新します。
  • インプレッションがカウントされるように、propositionDisplay イベントをトリガーするコードを追加します。

コンテンツをオンデマンドでリクエストして適用

Targetのフォームベースのコンポーザーを使用して作成され、地域のMBOXに配信されたアクティビティは、Platform Web SDKで自動的にレンダリングできません。 at.jsと同様に、特定のTargetの場所に配信されるオファーは、オンデマンドでレンダリングする必要があります。

at.js getOffer()とapplyOffer()を使用した例:
  1. getOffer()を実行して、場所のオファーをリクエストします
  2. applyOffer()を実行して、指定したセレクターにオファーをレンダリングします
  3. アクティビティのインプレッションは、getOffer() リクエスト時に自動的に増分されます
code language-javascript
// Retrieve an offer for the homepage-hero location
adobe.target.getOffer({
  "mbox": "homepage_hero",

  // Render offer to the #hero-banner selector
  "success": function(offers) {
    adobe.target.applyOffer({
      "mbox": "homepage_hero",
      "selector": "#hero-banner",
      "offer": offers
    });
  },
  "error": {
    console.log(error);
  },
  "timeout": 3000
});
applyPropositions コマンドを使用したPlatform Web SDKの同等の機能:
  1. sendEvent コマンドを実行して、1つ以上の場所(スコープ)のオファー(提案)をリクエストします
  2. 各スコープのページにコンテンツを適用する方法を示すメタデータオブジェクトを使用して、applyPropositions コマンドを実行します
  3. イベントタイプがdecisioning.propositionDisplayのsendEvent コマンドを実行して、インプレッションを追跡します
code language-javascript
// Retrieve propositions for homepage_hero location (scope)
alloy("sendEvent", {
  "decisionScopes": ["homepage_hero"]
}).then(function(result) {
  var retrievedPropositions = result.propositions;

  // Render offer (proposition) to the #hero-banner selector by supplying extra metadata
  return alloy("applyPropositions", {
    "propositions": retrievedPropositions,
    "metadata": {
      // Specify each regional mbox or scope name along with a selector and actionType
      "homepage_hero": {
        "selector": "#hero-banner",
        "actionType": "setHtml"
      }
    }
  }).then(function(applyPropositionsResult) {
    var renderedPropositions = applyPropositionsResult.propositions;

    // Send the display notifications via sendEvent command
    alloy("sendEvent", {
      "xdm": {
        "eventType": "decisioning.propositionDisplay",
        "_experience": {
          "decisioning": {
            "propositions": renderedPropositions
          }
        }
      }
    });
  });
});

Platform Web SDKでは、actionTypeを指定したapplyPropositions コマンドを使用して、フォームベースのアクティビティをページに適用する際の制御を強化しています。

actionType
説明
at.js applyOffer()
Platform Web SDK applyPropositions
setHtml
コンテナのコンテンツをクリアし、オファーをコンテナに追加します
はい(常に使用)
○
replaceHtml
コンテナを取り外して、オファーに置き換えます
×
○
appendHtml
指定したセレクターの後にオファーを追加します
×
○

その他のレンダリングオプションと例については、Platform Web SDKを使用したコンテンツのレンダリングに関する専用ドキュメント ​を参照してください。

実装例

以下のサンプルページは、前の節で説明した実装に基づいて構築されていますが、sendEvent コマンドにスコープを追加するだけです。

複数のスコープを持つPlatform Web SDKの例
code language-html
<!doctype html>
<html>
<head>
  <title>Example page</title>
  <!--Data Layer to enable rich data collection and targeting-->
  <script>
    var digitalData = {
      // Data layer information goes here
    };
  </script>

  <!--Third party libraries that may be used by Target offers and modifications-->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>

  <!--Prehiding snippet for Target with asynchronous deployment-->
  <script>
    !function(e,a,n,t){var i=e.head;if(i){
    if (a) return;
    var o=e.createElement("style");
    o.id="alloy-prehiding",o.innerText=n,i.appendChild(o),setTimeout(function(){o.parentNode&&o.parentNode.removeChild(o)},t)}}
    (document, document.location.href.indexOf("mboxEdit") !== -1, ".body { opacity: 0 !important }", 3000);
  </script>

  <!--Platform Web SDK base code-->
  <script>
    !function(n,o){o.forEach(function(o){n[o]||((n.__alloyNS=n.__alloyNS||
    []).push(o),n[o]=function(){var u=arguments;return new Promise(
    function(i,l){n[o].q.push([i,l,u])})},n[o].q=[])})}
    (window,["alloy"]);
  </script>

  <!--Platform Web SDK loaded asynchonously. Change the src to use the latest supported version.-->
  <script src="https://cdn1.adoberesources.net/alloy/2.6.4/alloy.min.js" async></script>

  <!--Configure Platform Web SDK then send event-->
  <script>
    alloy("configure", {
      "edgeConfigId": "ebebf826-a01f-4458-8cec-ef61de241c93",
      "orgId":"ADB3LETTERSANDNUMBERS@AdobeOrg"
    });
    alloy("sendEvent", {
      // Request and render VEC-based activities
      "renderDecisions": true,
      // Request content for form-based activities using the "homepage_hero" scope
      "decisionScopes": ["homepage_hero"]
    }).then(function(result) {
      var retrievedPropositions = result.propositions;

      // Render offer (proposition) to the #hero-banner selector by supplying extra metadata
      return alloy("applyPropositions", {
        "propositions": retrievedPropositions,
        "metadata": {
          // Specify each regional mbox or scope name along with a selector and actionType
          "homepage_hero": {
            "selector": "#hero-banner",
            "actionType": "setHtml"
          }
        }
      }).then(function(applyPropositionsResult) {
        var renderedPropositions = applyPropositionsResult.propositions;

        // Send the display notifications via sendEvent command
        alloy("sendEvent", {
          "xdm": {
            "eventType": "decisioning.propositionDisplay",
            "_experience": {
              "decisioning": {
                "propositions": renderedPropositions
              }
            }
          }
        });
      });
    });
  </script>
</head>
<body>
  <h1 id="title">Home Page</h1><br><br>
  <p id="bodyText">Navigation</p><br><br>
  <a id="home" class="navigationLink" href="#">Home</a><br>
  <a id="pageA" class="navigationLink" href="#">Page A</a><br>
  <a id="pageB" class="navigationLink" href="#">Page B</a><br>
  <a id="pageC" class="navigationLink" href="#">Page C</a><br>
  <div id="homepage-hero">Homepage Hero Banner Content</div>
</body>
</html>

次に、Platform Web SDK🔗を使用してTarget パラメーターを渡す方法について説明します。

NOTE
at.jsからWeb SDKへのTargetの移行を成功させるためのサポートを提供します。 移行で障害が発生した場合、またはこのガイドに重要な情報が欠けていると感じた場合は、このコミュニティのディスカッション ​に投稿してお知らせください。
recommendation-more-help
platform-learn-help-tutorial-migrate-target-websdk