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

Support for top and bottom of page events. Combine personalization display notifications together. #1036

Merged
merged 23 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
22d1d81
WIP add handlers for each kind of activity
jonsnyder Feb 6, 2023
efe6c16
Finalize personalization handlers
jonsnyder Feb 21, 2023
6c33b2d
Merge remote-tracking branch 'origin/main' into personalizationRefactor
jonsnyder Aug 2, 2023
3aeff9d
Add component tests with support for fetch, viewChange, and apply
jonsnyder Aug 15, 2023
63cdfb0
Refactor handlePropositions to render
jonsnyder Aug 17, 2023
4c337ec
Remove unused files
jonsnyder Aug 18, 2023
f648376
fix some tests
jonsnyder Aug 18, 2023
1cc8e88
Update all unit tests
jonsnyder Aug 21, 2023
520a0c8
Fix functional tests, and fix issues found when running functional tests
jonsnyder Aug 22, 2023
8a97a0b
Remove fetch related features, only including refactor and combining …
jonsnyder Aug 23, 2023
76038af
Add unit tests for new handler files
jonsnyder Aug 29, 2023
443745b
Revert "Remove fetch related features, only including refactor and co…
jonsnyder Aug 29, 2023
aa0474a
Save display notifications and send them at the bottom of page hit
jonsnyder Aug 29, 2023
0ca03c8
Fix default value for sendDisplayNotifications
jonsnyder Aug 31, 2023
9a9835d
Add viewName option to applyPropositions
jonsnyder Aug 31, 2023
daea723
Add showContainers call after rendering in fetch data handler
jonsnyder Sep 1, 2023
09e1a19
Merge branch 'combineNotifications' into topAndBottom2
jonsnyder Sep 7, 2023
8c56124
Change proposition to be immutable. Render based on schema. Group by …
jonsnyder Sep 14, 2023
e9b5acf
Remove unused code, fix unit tests for personalization handlers
jonsnyder Sep 14, 2023
9b664c0
Add license header
jonsnyder Sep 14, 2023
50dba9c
Fix bugs found running functional tests
jonsnyder Sep 14, 2023
a8dd78f
Merge remote-tracking branch 'origin/main' into topAndBottom2
jonsnyder Sep 14, 2023
ca33032
Update scope lowercase logic to only apply to the view cache.
jonsnyder Sep 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rollup.test.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ if (argv.reporters && argv.reporters.split(",").includes("coverage")) {

module.exports = {
output: {
sourcemap: true,
format: "iife",
// Allow non-IE browsers and IE11
// document.documentMode was added in IE8, and is specific to IE.
Expand Down
6 changes: 4 additions & 2 deletions src/components/DataCollector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,17 @@ const createDataCollector = ({ eventManager, logger }) => {
const {
renderDecisions = false,
responseHeaders = {},
responseBody = { handle: [] }
responseBody = { handle: [] },
personalization
} = options;

const event = eventManager.createEvent();

return eventManager.applyResponse(event, {
renderDecisions,
responseHeaders,
responseBody
responseBody,
personalization
});
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/components/DataCollector/validateApplyResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export default ({ options }) => {
payload: anything().required()
})
).required()
}).required()
}).required(),
personalization: objectOf({
sendDisplayNotifications: boolean().default(true)
}).default({ sendDisplayNotifications: true })
}).noUnknownFields();

return validator(options);
Expand Down
6 changes: 4 additions & 2 deletions src/components/DataCollector/validateUserEventOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export default ({ options }) => {
decisionScopes: arrayOf(string()).uniqueItems(),
personalization: objectOf({
decisionScopes: arrayOf(string()).uniqueItems(),
surfaces: arrayOf(string()).uniqueItems()
}),
surfaces: arrayOf(string()).uniqueItems(),
sendDisplayNotifications: boolean().default(true),
includePendingDisplayNotifications: boolean().default(false)
}).default({ sendDisplayNotifications: true }),
datasetId: string(),
mergeId: string(),
edgeConfigOverrides: validateConfigOverride
Expand Down
43 changes: 28 additions & 15 deletions src/components/Personalization/createApplyPropositions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

import composePersonalizationResultingObject from "./utils/composePersonalizationResultingObject";
import { isNonEmptyArray, isObject } from "../../utils";
import { DOM_ACTION, HTML_CONTENT_ITEM } from "./constants/schema";
import PAGE_WIDE_SCOPE from "../../constants/pageWideScope";
import { EMPTY_PROPOSITIONS } from "./validateApplyPropositionsOptions";

export const SUPPORTED_SCHEMAS = [DOM_ACTION, HTML_CONTENT_ITEM];
const SUPPORTED_SCHEMAS = [DOM_ACTION, HTML_CONTENT_ITEM];

export default ({ executeDecisions }) => {
export default ({
processPropositions,
createProposition,
pendingDisplayNotifications,
viewCache
}) => {
const filterItemsPredicate = item =>
SUPPORTED_SCHEMAS.indexOf(item.schema) > -1;

Expand Down Expand Up @@ -71,20 +74,30 @@ export default ({ executeDecisions }) => {
.filter(proposition => isNonEmptyArray(proposition.items));
};

const applyPropositions = ({ propositions, metadata }) => {
return ({ propositions = [], metadata = {}, viewName }) => {
const propositionsToExecute = preparePropositions({
propositions,
metadata
});
return executeDecisions(propositionsToExecute).then(() => {
return composePersonalizationResultingObject(propositionsToExecute, true);
});
};
}).map(proposition => createProposition(proposition));

return Promise.resolve()
.then(() => {
if (viewName) {
return viewCache.getView(viewName);
}
return [];
})
.then(additionalPropositions => {
const { render, returnedPropositions } = processPropositions([
...propositionsToExecute,
...additionalPropositions
]);

pendingDisplayNotifications.concat(render());

return ({ propositions, metadata = {} }) => {
if (isNonEmptyArray(propositions)) {
return applyPropositions({ propositions, metadata });
}
return Promise.resolve(EMPTY_PROPOSITIONS);
return {
propositions: returnedPropositions
};
});
};
};
77 changes: 0 additions & 77 deletions src/components/Personalization/createAutoRenderingHandler.js

This file was deleted.

45 changes: 27 additions & 18 deletions src/components/Personalization/createComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

import { noop, defer } from "../../utils";
import { noop } from "../../utils";
import createPersonalizationDetails from "./createPersonalizationDetails";
import { AUTHORING_ENABLED } from "./constants/loggerMessage";
import validateApplyPropositionsOptions from "./validateApplyPropositionsOptions";
Expand All @@ -26,7 +26,8 @@ export default ({
viewCache,
showContainers,
applyPropositions,
setTargetMigration
setTargetMigration,
pendingNotificationsHandler
}) => {
return {
lifecycle: {
Expand All @@ -51,7 +52,7 @@ export default ({

// If we are in authoring mode we disable personalization
mergeQuery(event, { enabled: false });
return;
return Promise.resolve();
}

const personalizationDetails = createPersonalizationDetails({
Expand All @@ -60,33 +61,41 @@ export default ({
decisionScopes,
personalization,
event,
viewCache,
isCacheInitialized: viewCache.isInitialized(),
logger
});

const handlerPromises = [];
if (personalizationDetails.shouldAddPendingDisplayNotifications()) {
handlerPromises.push(pendingNotificationsHandler({ event }));
}

if (personalizationDetails.shouldFetchData()) {
const decisionsDeferred = defer();
const cacheUpdate = viewCache.createCacheUpdate(
personalizationDetails.getViewName()
);
onRequestFailure(() => cacheUpdate.cancel());

viewCache.storeViews(decisionsDeferred.promise);
onRequestFailure(() => decisionsDeferred.reject());
fetchDataHandler({
decisionsDeferred,
cacheUpdate,
personalizationDetails,
event,
onResponse
});
return;
}

if (personalizationDetails.shouldUseCachedData()) {
} else if (personalizationDetails.shouldUseCachedData()) {
// eslint-disable-next-line consistent-return
return viewChangeHandler({
personalizationDetails,
event,
onResponse,
onRequestFailure
});
handlerPromises.push(
viewChangeHandler({
personalizationDetails,
event,
onResponse,
onRequestFailure
})
);
}
// We can wait for personalization to be applied and for
// the fetch data request to complete in parallel.
return Promise.all(handlerPromises);
},
onClick({ event, clickedElement }) {
onClickHandler({ event, clickedElement });
Expand Down
82 changes: 0 additions & 82 deletions src/components/Personalization/createExecuteDecisions.js

This file was deleted.

Loading