シングルページアプリケーション(SPA)の実装 web-spa-implementation
Adobe Experience Platform Web SDK には、シングルページアプリケーション(SPA)などの次世代のクライアントサイドテクノロジーでパーソナライゼーションをビジネスで実行するためのリッチな機能が用意されています。
従来のweb サイトは、「ページからページへ」のナビゲーションモデル(マルチページアプリケーション)で動作します。このモデルでは、web サイトのデザインとURLを密接に関連付け、あるweb ページから別のweb ページへの移行にページ読み込みが必要になります。
シングルページアプリケーション(SPA)などの最新型 web アプリケーションは、代わりにブラウザーの UI レンダリングの迅速な使用を推進するモデルを採用しています。多くの場合、ブラウザーの UI レンダリングは、ページの再読み込みとは独立しています。 これらのエクスペリエンスは、スクロール、クリック、カーソル移動などの顧客のインタラクションによってトリガーされる場合があります。 最新の web の枠組みが進化するにつれて、パーソナライゼーションと実験をデプロイするためのページ読み込みなどの従来の汎用イベントは機能しなくなりました。
SPA に Web SDK を使用するメリット web-spa-benefits
シングルページアプリケーション(SPA)に Web SDK を使用するメリットは次のとおりです。
- ページ読み込み時にすべてのオファーをキャッシュし、複数のサーバー呼び出しを単一のサーバー呼び出しに減らす機能。
- 従来のサーバー呼び出しで発生する遅延時間なしで、キャッシュ経由でオファーが即座に表示されるため、サイトでのユーザーエクスペリエンスが著しく向上します。
- 1 回限りの開発者設定により、マーケターは、Adobe Journey Optimizer web ビジュアルエディターを使用して、SPA でのパーソナライゼーションや実験のアクティビティを作成および実行できます。
XDM ビューとシングルページアプリケーション web-spa-xdm
Journey Optimizer web エディターでは、ビューという概念を利用しています。
ビューは、SPA エクスペリエンスを構成する視覚要素の論理的なグループです。 このため、シングルページアプリケーションは、URL ではなくユーザーのインタラクションによりビュー間を移行するものと考えられます。 通常、ビューはサイト全体、シングルページまたはページ内のグループ化された視覚要素を表せます。
次の例では、ビューの詳細を説明するために、架空のオンライン e コマースサイトを使用しています。
-
ホームページに移動すると、季節のコレクションや、サイトで使用可能な様々な製品カタログがヒーロー画像で宣伝されています。 この場合、ホーム画面全体に対してビューを定義できます。 このビューは、シンプルに「ホーム」と呼ぶことができます。
-
顧客が販売されている製品に興味を引かれたため、「男性」リンクをクリックすることにします。 ホームページと同様、男性ページ全体をビューとして定義できます。 このビューには「men」という名前を付けることができます。
-
ビューは、サイト全体またはサイト上の視覚要素のグループとして定義できるので、製品サイトに表示される 4 つの製品をグループ化し、ビューとして考慮できます。 このビューには「products」という名前を付けることができます。
-
お客様が「すべての男性用の製品」ボタンをクリックしてサイト上の他の製品を検索することを決定した場合、web サイトの URL は変更されませんが、表示される製品の 2 行目のみを表すビューをここで作成できます。 ビュー名は「products-page-2」にすることができます。
-
顧客はサイトから製品を購入し、チェックアウト画面に進みます。 買い物かご画面自体は、「買い物かご」という名前のビューに関連付けることができます。 または、チェックアウト画面内に別のビューを表示して、以下の推奨製品を処理することもできます。
ビューの概念は、これよりはるかに拡張できます。 これらは、サイトで定義できるビューのほんの一例です。
XDM ビューの実装 implement-xdm-views
XDM ビューを Adobe Journey Optimizer で活用すると、マーケターは Journey Optimizer web ビジュアルエディターを使用して、SPA での web パーソナライゼーションおよび実験キャンペーンを実行できます。
1 回限りの開発者設定を完了するには、次の手順を実行する必要があります。
-
Adobe Experience Platform Web SDK をインストールし、Web チャネルの前提条件ページを確認します。
-
パーソナライズするシングルページアプリケーションのすべての XDM ビューを決定します。
-
XDM ビューを定義した後、これらのビューにコンテンツを配信するには、
renderDecisionsをtrueに設定してsendEvent()関数と、対応する XDM ビューをシングルページアプリケーションに実装する必要があります。 XDM ビューは、xdm.web.webPageDetails.viewNameに渡す必要があります。 このステップにより、マーケターは Journey Optimizer web エディター内でこれらのビューを確認し、これらにコンテンツの変更を適用できます。
alloy("sendEvent", {
"renderDecisions": true,
"xdm": {
"web": {
"webPageDetails": {
"viewName":"home"
}
}
}
});
sendEvent() 呼び出し時に、エンドユーザーにレンダリングされる必要があるすべての XDM ビューが取得され、キャッシュされます。 XDM ビューを渡して後続の sendEvent() を呼び出すと、キャッシュから読み取られ、サーバーへの呼び出しなしでレンダリングされます。sendEvent() 関数の例
この節では、架空の e コマース SPA に対して React で sendEvent() 関数を呼び出す方法を示す 2 つの例の概要について説明します。
例 1:A/B テストのホームページ web-spa-sample-1
マーケティングチームは、ホームページ全体でA/B テストを実行したいと考えています。
ホームサイト全体で A/B テストを実行するには、XDM の viewName を home に設定して sendEvent() を呼び出す必要があります。
function onViewChange() {
var viewName = window.location.hash; // or use window.location.pathName if router works on path and not hash
viewName = viewName || 'home'; // view name cannot be empty
// Sanitize viewName to get rid of any trailing symbols derived from URL
if (viewName.startsWith('#') || viewName.startsWith('/')) {
viewName = viewName.substr(1);
}
alloy("sendEvent", {
"renderDecisions": true,
"xdm": {
"web": {
"webPageDetails": {
"viewName":"home"
}
}
}
});
}
// react router v4
const history = syncHistoryWithStore(createBrowserHistory(), store);
history.listen(onViewChange);
// react router v3
<Router history={hashHistory} onUpdate={onViewChange} >
例 2:パーソナライズされた製品 web-spa-sample-2
マーケティングチームは、ユーザーがクリックして、すべての男性用の製品を表示した後、2 行目の製品の価格ラベルカラーを赤に変更して、パーソナライズしたいと考えています。
function onViewChange(viewName) {
alloy("sendEvent", {
"renderDecisions": true,
"xdm": {
"web": {
"webPageDetails": {
"viewName": viewName
}
}
}
});
}
class Products extends Component {
render() {
return (
<
button type = "button"
onClick = {
this.handleLoadMoreClicked
} > All Men 's Products</button>
);
}
handleLoadMoreClicked() {
var page = this.state.page + 1; // assuming page number is derived from component's state
this.setState({
page: page
});
onViewChange('PRODUCTS-PAGE-' + page);
}
}
This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.
For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.
- TL;DR: This page explains how to implement XDM views in single-page applications (SPAs) with Adobe Experience Platform Web SDK, so that marketers can run web personalization and experimentation campaigns on SPAs via the Journey Optimizer web visual editor.
Intents:
- Understand how single-page applications (SPAs) differ from traditional websites that work on “page-to-page” navigation models.
- Determine all XDM views in a single-page application that you want to personalize.
- Implement the
sendEvent()function withrenderDecisionsset totrueand the corresponding XDM view passed inxdm.web.webPageDetails.viewName. - Complete the one-time developer setup that allows marketers to discover XDM views inside the Journey Optimizer web editor and apply content modifications for them.
- Invoke the
sendEvent()function in React for a hypothetical e-commerce SPA, for an A/B test on the home page or for personalized products.
Glossary:
- Single-page application (SPA): A modern web application that adopts a model that propels rapid use of browser UI rendering, which is often independent of page reloads. Experiences can be triggered by customer interactions, such as scrolls, clicks, and cursor movements.
- Multi-page application: The “page-to-page” navigation model of traditional websites, where website designs are tightly coupled to URLs and transitions from one web page to another require a page load.
- View (product-specific): A logical group of visual elements which together make up an SPA experience. A single-page application can be considered as transitioning through views, instead of URLs, based on user interactions. A view can typically represent a whole site, a single page or grouped visual elements within a page.
Prerequisites and permissions:
- Adobe Experience Platform Web SDK is installed, and the web channel prerequisites page is checked, as the first step of the one-time developer setup for XDM views.
Terminology:
- Canonical name: Single-page application — Acronym: SPA — variants: single-page applications, SPAs
- Canonical name: Experience Data Model — Acronym: XDM
- Canonical name: XDM view — variants: view, views
- Canonical name: Journey Optimizer web visual editor — variants: Journey Optimizer web editor, Adobe Journey Optimizer Web visual editor
- Canonical name: Adobe Experience Platform Web SDK — variants: Web SDK
- Canonical name: Adobe Journey Optimizer — Acronym: AJO — variants: Journey Optimizer
FAQ:
- What are the benefits of using Web SDK for single-page applications? Web SDK offers the ability to cache all offers on page-load to reduce multiple server calls to a single server call, and shows offers immediately via the cache, without lag time introduced by traditional server calls. A one-time developer setup enables marketers to create and run personalization and experimentation activities via the Adobe Journey Optimizer Web visual editor on your SPA.
- Where must the XDM view be passed? The XDM view must be passed in
xdm.web.webPageDetails.viewName, in asendEvent()call withrenderDecisionsset totrue. - What happens on the first
sendEvent()call? On the firstsendEvent()call, all XDM views that should be rendered to the end-user are fetched and cached. SubsequentsendEvent()calls with XDM views passed in are read from the cache and rendered without a server call. - Can a view be created when the website URL does not change? Yes. In the page example, when the customer selects the ALL MEN’S PRODUCTS button, the website URL does not change, but a view can be created to represent only the second row of products that are shown.
- What does implementing
sendEvent()with XDM views allow marketers to do? It allows marketers to discover these views inside the Journey Optimizer web editor and apply content modifications for them.
Examples:
- Views on a hypothetical online e-commerce site: a view named “home” for the entire home screen; a view named “men” for the entirety of the Men page; a view named “products” for the four products shown on the products site; a view named “products-page-2” for only the second row of products shown after the ALL MEN’S PRODUCTS button; a view named “cart” for the cart screen, or a different view inside the checkout screen to handle the recommended products below.
- Example 1: A/B test home page: to run A/B tests on the whole home site,
sendEvent()must be invoked with the XDMviewNameset tohome. The React sample calls anonViewChange()function throughhistory.listen(onViewChange)(react router v4) oronUpdate={onViewChange}on theRouter(react router v3). - Example 2: Personalized products: the marketing team personalizes the second row of products by changing the price label color to red after a user clicks to see all Men products. In the React sample, the
handleLoadMoreClicked()function increments the page number and callsonViewChange('PRODUCTS-PAGE-' + page), which invokessendEvent()with thatviewName.
Related pages:
Personas:
- developer: Can implement the
sendEvent()function withrenderDecisionsset totrueand the corresponding XDM view passed inxdm.web.webPageDetails.viewName. The page states that on the firstsendEvent()call, all XDM views that should be rendered to the end-user will be fetched and cached. Where: “Implementing XDM views”.
Onboarding:
- Level: Intermediate
- First minimal step: Install Adobe Experience Platform Web SDK and check the web channel prerequisites page.
- Success check: Marketers are able to discover these views inside the Journey Optimizer web editor and apply content modifications for them.
- Previous: As the first step of the one-time developer setup, check the web channel prerequisites page: web channel prerequisites