diff --git a/src/components/Personalization/createComponent.js b/src/components/Personalization/createComponent.js index 50f1eaffb..645b83b57 100644 --- a/src/components/Personalization/createComponent.js +++ b/src/components/Personalization/createComponent.js @@ -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, flatMap } from "../../utils"; +import { noop, flatMap, isNonEmptyArray } from "../../utils"; import createPersonalizationDetails from "./createPersonalizationDetails"; import { AUTHORING_ENABLED } from "./constants/loggerMessage"; import validateApplyPropositionsOptions from "./validateApplyPropositionsOptions"; @@ -102,11 +102,14 @@ export default ({ return Promise.all(decisionsMetaPromises).then(decisionsMetas => { // We only want to call mergeDecisionsMeta once, but we can get the propositions // from two places: the pending display notifications and the view change handler. - mergeDecisionsMeta( - event, - flatMap(decisionsMetas, dms => dms), - PropositionEventType.DISPLAY - ); + const decisionsMeta = flatMap(decisionsMetas, dms => dms); + if (isNonEmptyArray(decisionsMeta)) { + mergeDecisionsMeta( + event, + decisionsMeta, + PropositionEventType.DISPLAY + ); + } }); }, onClick({ event, clickedElement }) { diff --git a/src/components/Personalization/dom-actions/createRedirect.js b/src/components/Personalization/dom-actions/createRedirect.js new file mode 100644 index 000000000..3d6c692ac --- /dev/null +++ b/src/components/Personalization/dom-actions/createRedirect.js @@ -0,0 +1,13 @@ +/* +Copyright 2019 Adobe. All rights reserved. +This file is licensed to you under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. You may obtain a copy +of the License at http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +export default window => url => window.location.replace(url); diff --git a/src/components/Personalization/event.js b/src/components/Personalization/event.js index 93cb0872b..196283ed4 100644 --- a/src/components/Personalization/event.js +++ b/src/components/Personalization/event.js @@ -19,11 +19,6 @@ export const mergeDecisionsMeta = ( eventType, eventLabel = "" ) => { - // Do not send a display notification with no decisions. Even empty view changes - // should include a proposition. - if (decisionsMeta.length === 0) { - return; - } const xdm = { _experience: { decisioning: { diff --git a/src/components/Personalization/handlers/createProcessRedirect.js b/src/components/Personalization/handlers/createProcessRedirect.js index 4f03aa5ae..f7b37c314 100644 --- a/src/components/Personalization/handlers/createProcessRedirect.js +++ b/src/components/Personalization/handlers/createProcessRedirect.js @@ -18,7 +18,10 @@ export default ({ logger, executeRedirect, collect }) => item => { } const render = () => { - return collect({ decisionsMeta: [item.getMeta()] }).then(() => { + return collect({ + decisionsMeta: [item.getMeta()], + documentMayUnload: true + }).then(() => { executeRedirect(content); // We've already sent the display notification, so don't return anything }); diff --git a/src/components/Personalization/index.js b/src/components/Personalization/index.js index 2c33063a9..dadec5c6d 100644 --- a/src/components/Personalization/index.js +++ b/src/components/Personalization/index.js @@ -38,6 +38,7 @@ import createProcessDomAction from "./handlers/createProcessDomAction"; import createProcessHtmlContent from "./handlers/createProcessHtmlContent"; import createProcessRedirect from "./handlers/createProcessRedirect"; import createProcessPropositions from "./handlers/createProcessPropositions"; +import createRedirect from "./dom-actions/createRedirect"; const createPersonalization = ({ config, logger, eventManager }) => { const { targetMigrationEnabled, prehidingStyle } = config; @@ -58,6 +59,7 @@ const createPersonalization = ({ config, logger, eventManager }) => { }); const viewCache = createViewCacheManager({ createProposition }); + const executeRedirect = createRedirect(window); const schemaProcessors = { [schema.DEFAULT_CONTENT_ITEM]: processDefaultContent, [schema.DOM_ACTION]: createProcessDomAction({ @@ -68,7 +70,7 @@ const createPersonalization = ({ config, logger, eventManager }) => { [schema.HTML_CONTENT_ITEM]: createProcessHtmlContent({ modules, logger }), [schema.REDIRECT_ITEM]: createProcessRedirect({ logger, - executeRedirect: url => window.location.replace(url), + executeRedirect, collect }) }; diff --git a/src/core/createEvent.js b/src/core/createEvent.js index 84f1a50a3..33474069d 100644 --- a/src/core/createEvent.js +++ b/src/core/createEvent.js @@ -148,12 +148,7 @@ export default () => { return shouldSendEvent; }, getViewName() { - if ( - !userXdm || - !userXdm.web || - !userXdm.web.webPageDetails || - !userXdm.web.webPageDetails.viewName - ) { + if (!userXdm || !userXdm.web || !userXdm.web.webPageDetails) { return undefined; } diff --git a/test/unit/specs/components/Personalization/dom-actions/createRedirect.spec.js b/test/unit/specs/components/Personalization/dom-actions/createRedirect.spec.js new file mode 100644 index 000000000..0818f0680 --- /dev/null +++ b/test/unit/specs/components/Personalization/dom-actions/createRedirect.spec.js @@ -0,0 +1,14 @@ +import createRedirect from "../../../../../../src/components/Personalization/dom-actions/createRedirect"; + +describe("createRedirect", () => { + it("redirects", () => { + const window = { + location: { + replace: jasmine.createSpy() + } + }; + const redirect = createRedirect(window); + redirect("myurl"); + expect(window.location.replace).toHaveBeenCalledWith("myurl"); + }); +}); diff --git a/test/unit/specs/components/Personalization/handlers/createProcessRedirect.spec.js b/test/unit/specs/components/Personalization/handlers/createProcessRedirect.spec.js index f69b91f7d..402a8c37c 100644 --- a/test/unit/specs/components/Personalization/handlers/createProcessRedirect.spec.js +++ b/test/unit/specs/components/Personalization/handlers/createProcessRedirect.spec.js @@ -64,7 +64,10 @@ describe("createProcessRedirect", () => { expect(executeRedirect).not.toHaveBeenCalled(); const renderPromise = result.render(); await flushPromiseChains(); - expect(collect).toHaveBeenCalledWith({ decisionsMeta: ["mymetavalue"] }); + expect(collect).toHaveBeenCalledWith({ + decisionsMeta: ["mymetavalue"], + documentMayUnload: true + }); expect(executeRedirect).not.toHaveBeenCalled(); collectDefer.resolve(); await flushPromiseChains();