Configurare il supporto per le schede di contenuto in Web SDK content-card-configuration-sdk

In questa pagina: Configura ed esegui l’esempio che recupera ed esegue il rendering delle schede di contenuto con Adobe Experience Platform Web SDK in modo da poter distribuire contenuti personalizzati lato client sulle pagine Web.

In questo esempio viene illustrato come recuperare le schede di contenuto da Adobe Journey Optimizer (AJO) tramite Adobe Experience Platform. Sfruttando Adobe Experience Platform Web SDK, il contenuto di personalizzazione viene recuperato e renderizzato interamente sul lato client.

Al caricamento della pagina iniziale, viene visualizzato lo stato predefinito della pagina. Tuttavia, se interagisci con i pulsanti Fondi di deposito o Condividi sui social media, verranno visualizzate schede di contenuto aggiuntive. Queste schede vengono attivate da condizioni lato client, garantendo che vengano visualizzate solo quando vengono intraprese azioni specifiche.

Esecuzione dell’esempio run-sample

PREREQUISITES
È necessario installare node e npm. Consulta questa documentazione
Per utilizzare le regole di squalifica con le schede di contenuto, è necessario Web SDK versione 2.28.0 o successiva.
  1. Imposta i certificati SSL locali per HTTPS. Questi esempi richiedono certificati SSL firmati localmente per distribuire il contenuto tramite HTTPS:

    1. Installa mkcert nel computer.

    2. Dopo l’installazione, eseguire mkcert -install per installare il certificato mkcert root.

  2. Clona l’archivio nel computer locale.

  3. Apri un terminale e passa alla cartella dell’esempio.

  4. Installare le dipendenze richieste eseguendo npm install.

  5. Avviare l’applicazione eseguendo npm start.

  6. Apri il browser Web e passa a https://localhost.

Come funziona setup

  1. Includi e configura il Web SDK nella pagina utilizzando le impostazioni del file .env nella cartella di esempio.

    code language-none
    <script src="https://cdn1.adoberesources.net/alloy/2.18.0/alloy.min.js" async></script>
    alloy("configure", {
        defaultConsent: "in",
        edgeDomain: "{{edgeDomain}}",
        edgeConfigId: "{{edgeConfigId}}",
        orgId:"{{orgId}}",
        debugEnabled: false,
        personalizationStorageEnabled: true,
        thirdPartyCookiesEnabled: false
    });
    
  2. Utilizza il comando sendEvent per recuperare il contenuto personalizzato.

    code language-none
    alloy("sendEvent", {
        renderDecisions: true,
        personalization: {
            surfaces: ["web://alloy-samples.adobe.com/#content-cards-sample"],
        },
    });
    
  3. Sottoscrivere le schede di contenuto per una superficie specifica utilizzando il comando subscribeRulesetItems. Ogni volta che vengono valutati i set di regole, gestisci l’oggetto risultato nel callback, che conterrà propositions con i dati della scheda contenuto.

    code language-none
    const contentCardManager = createContentCardManager("content-cards");
    
    alloy("subscribeRulesetItems", {
        surfaces: ["web://alloy-samples.adobe.com/#content-cards-sample"],
        schemas: ["https://ns.adobe.com/personalization/message/content-card"],
        callback: (result, collectEvent) => {
            const { propositions = [] } = result;
            contentCardManager.refresh(propositions, collectEvent);
        },
    });
    
  4. Gestisci il rendering delle schede di contenuto e invia interact e display eventi utilizzando l’oggetto contentCardsManager trovato in script.js. Estrai, ordina ed elabora schede di contenuto dalle proposte ricevute.

    code language-none
    const createContentCard = (proposition, item) => {
        const { data = {}, id } = item;
        const {
            content = {},
            meta = {},
            publishedDate,
            qualifiedDate,
            displayedDate,
        } = data;
    
        return {
            id,
            ...content,
            meta,
            qualifiedDate,
            displayedDate,
            publishedDate,
            getProposition: () => proposition,
        };
    };
    
    const extractContentCards = (propositions) =>
        propositions
            .reduce((allItems, proposition) => {
            const { items = [] } = proposition;
    
            return [
                ...allItems,
                ...items.map((item) => createContentCard(proposition, item)),
            ];
        }, [])
        .sort(
            (a, b) =>
                b.qualifiedDate - a.qualifiedDate || b.publishedDate - a.publishedDate
        );
    
    const contentCards = extractContentCards(propositions);
    
  5. Esegui il rendering delle schede di contenuto in base ai dettagli definiti per ciascuna campagna. Ogni scheda include title, body, imageUrl e altri valori di dati personalizzati.

    code language-none
    const renderContentCards = () => {
        const contentCardsContainer = document.getElementById(containerElementId);
        contentCardsContainer.addEventListener("click", handleContentCardClick);
    
        let contents = "";
    
        contentCards.forEach((card) => {
            const { id, title, body, imageUrl, meta = {} } = card;
            const { buttonLabel = "" } = meta;
    
            contents += `
                <div class="col">
                    <div data-id="${id}" class="card h-100">
                        <img src="${imageUrl}" class="card-img-top" alt="...">
                        <div class="card-body d-flex flex-column">
                            <h5 class="card-title">${title}</h5>
                            <p class="card-text">${body}</p>
                            <a href="#" class="mt-auto btn btn-primary">${buttonLabel}</a>
                        </div>
                    </div>
                 </div>
             `;
        });
    
        contentCardsContainer.innerHTML = contents;
        collectEvent(
            "display",
            contentCards.map((card) => card.getProposition())
         );
    };
    
  6. Quando viene richiamato il callback subscribeRulesetItems, viene fornita anche una funzione di convenienza denominata collectEvent. Questa funzione viene utilizzata per inviare eventi Experience Edge per monitorare interazioni, visualizzazioni e altre azioni dell’utente. In questo esempio, collectEvent tiene traccia di quando si fa clic su una scheda di contenuto. Inoltre, se fai clic sul pulsante sulla scheda dei contenuti, il browser viene indirizzato a actionUrl specificato dalla campagna.

    code language-none
    const handleContentCardClick = (evt) => {
        const cardEl = evt.target.closest(".card");
    
        if (!cardEl) {
            return;
        }
    
        const isAnchor = evt.target.nodeName === "A";
        const card = contentCards.find((card) => card.id === cardEl.dataset.id);
    
        if (!card) {
            return;
        }
    
        collectEvent("interact", [card.getProposition()]);
    
        if (isAnchor) {
            evt.preventDefault();
            evt.stopImmediatePropagation();
            const { actionUrl } = card;
            if (actionUrl && actionUrl.length > 0) {
                window.location.href = actionUrl;
            }
        }
    };
    

Osservazioni chiave key-observations

personalizationStorageEnabled

Opzione personalizationStorageEnabled impostata su true nel comando configure. In questo modo, le schede di contenuto precedentemente qualificate vengono memorizzate e continuano a essere visualizzate nelle diverse sessioni utente.

Trigger

Le schede di contenuto supportano trigger personalizzati valutati sul lato client. Quando viene soddisfatta una regola di attivazione, vengono visualizzate schede di contenuto aggiuntive. In questo esempio vengono utilizzate quattro campagne diverse, una per ogni scheda di contenuto, che condividono tutte la stessa superficie: web://alloy-samples.adobe.com/#content-cards-sample. La tabella seguente illustra le regole di attivazione per ogni campagna e come soddisfarle.

Regola di attivazione
Scheda
Come soddisfare la regola di attivazione
Nessuna
comando sendEvent. Nessuna regola lato client da soddisfare.
Nessuna
comando sendEvent. Nessuna regola lato client da soddisfare.

Il comando evaluateRulesets viene attivato quando si fa clic sui pulsanti “Fondi di deposito” e “Condividi sui social media”. Ogni pulsante specifica il decisionContext pertinente per soddisfare le regole definite per le rispettive campagne.

document.getElementById("action-button-1").addEventListener("click", () => {
    alloy("evaluateRulesets", {
        renderDecisions: true,
        personalization: {
            decisionContext: {
                action: "deposit-funds",
            },
        },
    });
});

document.getElementById("action-button-2").addEventListener("click", () => {
    alloy("evaluateRulesets", {
        renderDecisions: true,
        personalization: {
            decisionContext: {
                action: "social-media",
            },
        },
    });
});
AI Knowledge Reference

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 set up and run the sample that retrieves content cards from Adobe Journey Optimizer and fetches and renders them entirely on the client side with the Adobe Experience Platform Web SDK.

Intents:

  • Set up local SSL certificates with mkcert, install the dependencies with npm install and start the sample with npm start.
  • Include and configure the Web SDK on the page using settings from the .env file in the sample folder.
  • Fetch personalized content with the sendEvent command.
  • Subscribe to content cards for a specific surface with the subscribeRulesetItems command.
  • Manage the rendering of content cards and send interact and display events with the contentCardsManager object found in script.js.
  • Display additional content cards through client-side trigger rules with the evaluateRulesets command and a decisionContext.

Glossary:

  • personalizationStorageEnabled: Option of the configure command. When it is set to true, previously qualified content cards are stored and continue to be displayed across user sessions.
  • subscribeRulesetItems: Command that subscribes to content cards for a specific surface. Each time rulesets are evaluated, the callback receives a result object that contains propositions with content card data.
  • collectEvent: Convenience function provided when the subscribeRulesetItems callback is invoked. It is used to send Experience Edge events to track interactions, displays, and other user actions.
  • Trigger rule: Custom trigger of content cards, evaluated on the client side. When a trigger rule is met, additional content cards are displayed. (product-specific)
  • decisionContext: Set by each button of the sample in the personalization option of the evaluateRulesets command to fulfill the rules defined for the respective campaigns.

Prerequisites and permissions:

  • You need to install node and npm.
  • The samples require locally signed SSL certificates to serve content over HTTPS.
  • To use disqualification rules with content cards, Web SDK version 2.28.0 or later is required.

Terminology:

  • Canonical name: Adobe Journey Optimizer — Acronym: AJO — variants: Journey Optimizer
  • Canonical name: Adobe Experience Platform — Acronym: AEP — variants: Platform
  • Canonical name: Adobe Experience Platform Web SDK — variants: Web SDK
  • Canonical name: Content cards — variants: Content Cards

FAQ:

  • Where are content cards fetched and rendered in this sample? Entirely on the client side, with the Adobe Experience Platform Web SDK.
  • Why do additional content cards appear after interacting with the Deposit Funds or Share on social media buttons? These cards are triggered by client-side conditions. The evaluateRulesets command is triggered when these buttons are selected, and each button specifies the relevant decisionContext to fulfill the rules defined for the respective campaigns.
  • How do previously qualified content cards continue to be displayed across user sessions? The personalizationStorageEnabled option is set to true in the configure command.
  • Which Web SDK version is required to use disqualification rules with content cards? Web SDK version 2.28.0 or later.
  • What happens when a content card is selected in this sample? collectEvent sends an interact event. If the button on the content card is selected, the browser is directed to the actionUrl specified by the campaign.
  • Where do I open the sample once it is started? Go to https://localhost in your web browser.

Examples:

  • Upon the initial page load, the sample page displays its default state. Interacting with the Deposit Funds or Share on social media buttons makes additional content cards appear.
  • The sample uses four different campaigns, one for each content card, all sharing the same surface: web://alloy-samples.adobe.com/#content-cards-sample. For two cards the trigger rule is None: the way to satisfy it is the sendEvent command, with no client side rule to satisfy.
  • In the sample code, the click on action-button-1 calls evaluateRulesets with the decisionContext action: "deposit-funds", and the click on action-button-2 calls it with action: "social-media".
  • Each card includes a title, body, imageUrl, and other custom data values, rendered based on the details defined for each campaign.

Personas:

  • admin: Can install node and npm, then set up local SSL certificates with mkcert to serve the sample over HTTPS. Can install the dependencies with npm install, start the sample with npm start and open https://localhost in a web browser. The page states that to use disqualification rules with content cards, Web SDK version 2.28.0 or later is required. Where: “Running the sample”.

Onboarding:

  • Level: Experienced
  • First minimal step: Set up local SSL certificates for HTTPS by installing mkcert on your computer and running mkcert -install.
  • Success check: Upon the initial page load, the page displays its default state. If you interact with the Deposit Funds or Share on social media buttons, additional content cards will appear.
recommendation-more-help
journey-optimizer-help