Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for Adobe Journey Optimizer content cards in subscribeRulesetItems #1125

Merged
merged 113 commits into from
Aug 5, 2024

Conversation

jasonwaters
Copy link
Collaborator

@jasonwaters jasonwaters commented May 24, 2024

Description

This PR adds support for content-cards to alloy. A "content card" campaign can be created in AJO. Each content card is assigned a surface. That surface is then used in the web sdk to subscribe to content cards. Rendering content cards is an exercise left to the customer. see the alloy-samples sample for more details about usage and how-to.

Product and Technical Requirements

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change which does not add functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

# Conflicts:
#	src/core/createEventManager.js
#	test/functional/specs/Visitor/C35448.js
# Conflicts:
#	src/core/createEventManager.js
# Conflicts:
#	src/components/DecisioningEngine/index.js
#	src/components/DecisioningEngine/utils.js
#	src/utils/debounce.js
#	test/unit/specs/components/DecisioningEngine/createContextProvider.spec.js
#	test/unit/specs/components/DecisioningEngine/utils.spec.js
# Conflicts:
#	sandbox/src/components/InAppMessagesDemo/InAppMessages.js
#	src/components/DecisioningEngine/createSubscribeRulesetItems.js
#	src/components/DecisioningEngine/index.js
#	src/components/DecisioningEngine/utils.js
#	src/components/Personalization/createComponent.js
#	src/components/Personalization/createOnDecisionHandler.js
#	src/components/Personalization/createPersonalizationDetails.js
#	src/components/Personalization/index.js
#	src/core/config/createCoreConfigs.js
#	test/functional/helpers/createAlloyProxy.js
#	test/unit/specs/components/DecisioningEngine/createSubscribeRulesetItems.spec.js
#	test/unit/specs/components/Personalization/createComponent.spec.js
#	test/unit/specs/components/Personalization/createModules.spec.js
#	test/unit/specs/components/Personalization/createNotificationHandler.spec.js
#	test/unit/specs/components/Personalization/createOnDecisionHandler.spec.js
#	test/unit/specs/components/Personalization/createPersonalizationDetails.spec.js
#	test/unit/specs/components/Personalization/dom-actions/createRedirect.spec.js
#	test/unit/specs/components/Personalization/topLevel/buildAlloy.js
#	test/unit/specs/components/Personalization/topLevel/cartViewDecisions.spec.js
#	test/unit/specs/components/Personalization/topLevel/mergedMetricDecisions.spec.js
#	test/unit/specs/components/Personalization/topLevel/mixedPropositions.spec.js
#	test/unit/specs/components/Personalization/topLevel/pageWideDecisionsWithDomActionSchemaItems.spec.js
#	test/unit/specs/components/Personalization/topLevel/pageWideScopeDecisions.spec.js
#	test/unit/specs/components/Personalization/topLevel/pageWideScopeDecisionsWithoutDomActionSchemaItems.spec.js
#	test/unit/specs/components/Personalization/topLevel/productsViewDecisions.spec.js
#	test/unit/specs/components/Personalization/topLevel/redirectPageWideScopeDecision.spec.js
#	test/unit/specs/components/Personalization/topLevel/scopesFoo1Foo2Decisions.spec.js
#	test/unit/specs/utils/assignConcatArrayValues.spec.js
#	test/unit/specs/utils/createSubscription.spec.js
@ninaceban
Copy link
Contributor

Hi Jason, is the new command subscribeContentCards related to subscribeRulesetItems command functionality and usage?

@jasonwaters
Copy link
Collaborator Author

jasonwaters commented May 28, 2024

Hi Jason, is the new command subscribeContentCards related to subscribeRulesetItems command functionality and usage?

They have some similarities, but subscribeContentCards offers some conveniences to users to make rendering content cards easier.

Functionality subscribeRulesetItems subscribeContentCards
callback payload response object that contains propositions array. array of content cards
method to collect display event Build a payload based on propositions and items, then use sendEvent to send. Call the rendered function with an array of content cards.
method to collect interact event Build a payload based on propositions and items, then use sendEvent to send. Call the clicked function with an array of content cards.
method to collect dismiss event Build a payload based on propositions and items, then use sendEvent to send. Call the dismissed function with an array of content cards.
Content cards ordering Unpredictable sort from edge response. May be sorted manually by creating a list of all proposition items and manually sorting. Sorted correctly every time.

The rendered, clicked and dismissed greatly simplify the work needed from the customer in order to implement content cards. And it prevents repeat events from being collected.

@jasonwaters
Copy link
Collaborator Author

Here is a comparison of subscribeContentCards vs subscribeRulesetItems to render content cards and collect appropriate exp edge events.

Using subscribeContentCards

      alloy("subscribeContentCards", {
        "web://aepdemo.com/contentCards",
        callback: ({ items = [], rendered, clicked, dismissed }) => {
          setClickHandler(() => clicked);
          setDismissHandler(() => dismissed);
          setContentCards(items);
          rendered(items);
        },
      });

Using subscribeRulesetItems.

I am assuming there may be some desire not to add a new command for content cards. But i'd like to provide as much convenience to our customers as possible. So one idea is to enhance subscribeRulesetItems with a collectEvent function that could be used in a similar fashion as the rendered, clicked and dismissed functions in subscribeContentCards. As you can see, there is a bit more legwork for the customer to use content cards using subscribeRulesetItems. But if the desire is to not add a new command, it could be done this way.

const createContentCard = (proposition, item) => {
  const { data = {} } = item;
  const {
    content = {},
    meta = {},
    publishedDate,
    qualifiedDate,
    displayedDate,
  } = data;

  return {
    ...content,
    meta,
    qualifiedDate,
    displayedDate,
    publishedDate,
    getProposition: () => proposition,
  };
};

alloy("subscribeRulesetItems", {
  surfaces: ["web://aepdemo.com/contentCards"],
  schemas: ["https://ns.adobe.com/personalization/message/content-card"],
  callback: (result, collectEvent) => {
    const { propositions = [] } = result;

    const contentCards = 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
      );

    setClickHandler(
      () => (items) =>
        collectEvent(
          "interact",
          items.map((item) => item.getProposition())
        )
    );

    setDismissHandler(
      () => (items) =>
        collectEvent(
          "dismiss",
          items.map((item) => item.getProposition())
        )
    );

    collectEvent("display", propositions);
    setContentCards(contentCards);
  },
});

# Conflicts:
#	src/components/Personalization/index.js
@jfkhoury
Copy link
Contributor

---->>> There are none! 🏆

This is my favorite! 😆

@jasonwaters The team will be reviewing this feature starting Monday.
Thank you

@jasonwaters
Copy link
Collaborator Author

This PR has been updated:

  1. The subscribeContentCards command was removed.
  2. The subscribeRulesetItems command was enhanced to include a collectEvent function passed into the callback function so there is some added convenience to collect events for propositions.. This is described in detail in a prior comment.

Todo:

  • Add a new sample to alloy-samples to illustrate how to do content cards using the subscribeRulesetItems command.
  • Add the content cards schema to the tags extension.

cc: @ninaceban @jfkhoury

@@ -35,6 +35,7 @@ export default ({ options }) => {
data: objectOf({}),
documentUnloading: boolean(),
renderDecisions: boolean(),
decisionContext: objectOf({}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please provide more details why this is needed?

New options related to personalization should go under personalization block.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, good catch. it's actually already in personalization, looks like we just forgot to remove it from top level. i'll remove it

@@ -23,8 +23,8 @@ export const REDIRECT_ITEM =

export const MESSAGE_IN_APP =
"https://ns.adobe.com/personalization/message/in-app";
export const MESSAGE_FEED_ITEM =
"https://ns.adobe.com/personalization/message/feed-item";
export const MESSAGE_CONTENT_CARD =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message Feed Item was renamed to Content Card?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, "Feed item" isn't a thing anymore.

@jonsnyder jonsnyder changed the title FEATURE: Content Cards Added support for Adobe Journey Optimizer content cards in subscribeRuleSetItem Jul 30, 2024
Copy link
Contributor

@jonsnyder jonsnyder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working with Nina! This looks great.

  • Can you update the description of this PR to reflect the final state of the API?
  • I see that message-feed-item is renamed to content-card. Is this backward compatible? Will customers need to do anything when they upgrade Web SDK?

@jonsnyder jonsnyder added the 2.22.0 Feature planned for version 2.22.0 label Jul 30, 2024
# Conflicts:
#	src/components/DecisioningEngine/createSubscribeRulesetItems.js
@jasonwaters jasonwaters merged commit 8367856 into main Aug 5, 2024
5 checks passed
@jasonwaters jasonwaters deleted the message-feed branch August 5, 2024 22:40
@jonsnyder jonsnyder changed the title Added support for Adobe Journey Optimizer content cards in subscribeRuleSetItem Added support for Adobe Journey Optimizer content cards in subscribeRulesetItems Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.22.0 Feature planned for version 2.22.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants