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

Fixed an issue with applyResponse #914

Merged
merged 3 commits into from
Sep 28, 2022
Merged

Fixed an issue with applyResponse #914

merged 3 commits into from
Sep 28, 2022

Conversation

jonsnyder
Copy link
Contributor

@jonsnyder jonsnyder commented Sep 27, 2022

Description

Fixed an issue with applyResponse where it would not apply personalized content if it was called after a sendEvent. There is a condition here:

if (personalizationDetails.shouldFetchData()) {
which is defined here:
return this.hasScopes() || !this.isCacheInitialized();

which makes it so that the personalized content from an applyResponse command is only processed if the cache is not initialized. This is because for applyResponse commands, the scopes are always empty. In this PR, I add the page wide scope (__view__) to the applyResponse calls so that "shouldFetchData()" is always true for applyResponse commands.

Related Issue

Motivation and Context

Screenshots (if appropriate):

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)

Checklist:

  • I have signed the Adobe Open Source CLA or I'm an Adobe employee.
  • I have made any necessary test changes and all tests pass.
  • I have run the Sandbox successfully.

@@ -113,7 +114,7 @@ export default ({
.onBeforeEvent({
event,
renderDecisions,
decisionScopes: [],
decisionScopes: [PAGE_WIDE_SCOPE],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see how this solves the problem, but it's not technically accurate. I suppose an empty array of decision scopes was also inaccurate though.... so 🤷‍♂️

Since we have the responseBody here, you could instead iterate over the payload array of the personalization:decisions handle to construct a Set of scopes found in the list. then provide the list in the decisionScopes array here.

Copy link
Contributor

@ninaceban ninaceban Sep 28, 2022

Choose a reason for hiding this comment

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

In my opinion renderDecisions and decisionScopes should be passed by the customer in the applyResponses command as options. If they need the __view__ decisions to be rendered, then they would pass them in the command options. Otherwise, we make the assumption that the customer have fetched them and wants them to be rendered.

The special scope __view__ is attached to decisionScopes by Web SDK. In cases of server-side call, it is up to the customer to fetch the __view__ decisions or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably as a quick fix, @jasonwaters idea to extract the scopes from handles will work. Although with @XDex PR related to surfaces, we should think of how we should handle personalization object here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will go ahead and merge this, and work on testing it more thoroughly later. If we find a bug we can patch later.

@jonsnyder jonsnyder merged commit dcf12cb into main Sep 28, 2022
@jonsnyder jonsnyder deleted the fixApplyResponse branch September 28, 2022 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants