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

Populate _experience.decisioning.propositionEventType for display and interact personalization events. #901

Merged
merged 2 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions src/components/Personalization/constants/propositionEventType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Copyright 2022 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 const PropositionEventType = {
DISPLAY: "display",
INTERACT: "interact"
};
3 changes: 2 additions & 1 deletion src/components/Personalization/createCollect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/
import { DISPLAY } from "./constants/eventType";
import { PropositionEventType } from "./constants/propositionEventType";
import { isNonEmptyArray } from "../../utils";

export default ({ eventManager, mergeDecisionsMeta }) => {
Expand All @@ -24,7 +25,7 @@ export default ({ eventManager, mergeDecisionsMeta }) => {
};
}
if (isNonEmptyArray(decisionsMeta)) {
mergeDecisionsMeta(event, decisionsMeta);
mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.DISPLAY);
}

event.mergeXdm(data);
Expand Down
3 changes: 2 additions & 1 deletion src/components/Personalization/createOnClickHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ governing permissions and limitations under the License.

import { isNonEmptyArray } from "../../utils";
import { INTERACT } from "./constants/eventType";
import { PropositionEventType } from "./constants/propositionEventType";
import PAGE_WIDE_SCOPE from "./constants/scope";

export default ({
Expand Down Expand Up @@ -43,7 +44,7 @@ export default ({
}

event.mergeXdm(xdm);
mergeDecisionsMeta(event, decisionsMeta);
mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.INTERACT);
}
}
};
Expand Down
7 changes: 6 additions & 1 deletion src/components/Personalization/createViewChangeHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ governing permissions and limitations under the License.

import composePersonalizationResultingObject from "./utils/composePersonalizationResultingObject";
import { isNonEmptyArray } from "../../utils";
import { PropositionEventType } from "./constants/propositionEventType";

export default ({
mergeDecisionsMeta,
Expand All @@ -27,7 +28,11 @@ export default ({
return executeDecisions(viewDecisions).then(decisionsMeta => {
// if there are decisions to be rendered we render them and attach the result in experience.decisions.propositions
if (isNonEmptyArray(decisionsMeta)) {
mergeDecisionsMeta(event, decisionsMeta);
mergeDecisionsMeta(
event,
decisionsMeta,
PropositionEventType.DISPLAY
);
onResponse(() => {
return composePersonalizationResultingObject(viewDecisions, true);
});
Expand Down
9 changes: 7 additions & 2 deletions src/components/Personalization/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

export const mergeDecisionsMeta = (event, decisionsMeta) => {
const EVENT_TYPE_TRUE = 1;

export const mergeDecisionsMeta = (event, decisionsMeta, eventType) => {
event.mergeXdm({
_experience: {
decisioning: {
propositions: decisionsMeta
propositions: decisionsMeta,
propositionEventType: {
[eventType]: EVENT_TYPE_TRUE
}
}
}
});
Expand Down
7 changes: 7 additions & 0 deletions test/functional/specs/Personalization/C28760.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,11 @@ test("Test C28760: A notification collect should be triggered if a VEC dom actio
notificationRequestBody.events[0].xdm._experience.decisioning.propositions
)
.eql(notificationPayload);
await t
.expect(
// eslint-disable-next-line no-underscore-dangle
notificationRequestBody.events[0].xdm._experience.decisioning
.propositionEventType.display
)
.eql(1);
});
7 changes: 7 additions & 0 deletions test/functional/specs/Personalization/C5805675.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,11 @@ test("Test C5805675: Default content offers should be delivered", async () => {
notificationRequestBody.events[0].xdm._experience.decisioning.propositions
)
.eql(notificationPayload);
await t
.expect(
// eslint-disable-next-line no-underscore-dangle
notificationRequestBody.events[0].xdm._experience.decisioning
.propositionEventType.display
)
.eql(1);
});
22 changes: 21 additions & 1 deletion test/functional/specs/Personalization/C6364798.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ const simulatePageLoad = async alloy => {
notificationRequestBody.events[0].xdm._experience.decisioning.propositions
)
.eql(pageWideScopeDecisionsMeta);
await t
.expect(
// eslint-disable-next-line no-underscore-dangle
notificationRequestBody.events[0].xdm._experience.decisioning
.propositionEventType.display
)
.eql(1);
// notification for view rendered decisions
const viewNotificationRequest = networkLogger.edgeEndpointLogs.requests[2];
const viewNotificationRequestBody = JSON.parse(
Expand All @@ -135,6 +142,13 @@ const simulatePageLoad = async alloy => {
.propositions
)
.eql(productsViewDecisionsMeta);
await t
.expect(
// eslint-disable-next-line no-underscore-dangle
viewNotificationRequestBody.events[0].xdm._experience.decisioning
.propositionEventType.display
)
.eql(1);
const allPropositionsWereRendered = resultingObject.propositions.every(
proposition => proposition.renderAttempted
);
Expand Down Expand Up @@ -174,7 +188,13 @@ const simulateViewChange = async (alloy, personalizationPayload) => {
viewChangeRequestBody.events[0].xdm._experience.decisioning.propositions
)
.eql(cartViewDecisionsMeta);

await t
.expect(
// eslint-disable-next-line no-underscore-dangle
viewChangeRequestBody.events[0].xdm._experience.decisioning
.propositionEventType.display
)
.eql(1);
// assert we return the renderAttempted flag set to true
const allPropositionsWereRendered = resultingObject.propositions.every(
proposition => proposition.renderAttempted
Expand Down
22 changes: 21 additions & 1 deletion test/functional/specs/Personalization/C782718.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ const simulatePageLoad = async alloy => {
notificationRequestBody.events[0].xdm._experience.decisioning.propositions
)
.eql(pageWideScopeDecisionsMeta);
await t
.expect(
// eslint-disable-next-line no-underscore-dangle
notificationRequestBody.events[0].xdm._experience.decisioning
.propositionEventType.display
)
.eql(1);
// notification for view rendered decisions
const viewNotificationRequest = networkLogger.edgeEndpointLogs.requests[2];
const viewNotificationRequestBody = JSON.parse(
Expand All @@ -134,6 +141,13 @@ const simulatePageLoad = async alloy => {
.propositions
)
.eql(productsViewDecisionsMeta);
await t
.expect(
// eslint-disable-next-line no-underscore-dangle
viewNotificationRequestBody.events[0].xdm._experience.decisioning
.propositionEventType.display
)
.eql(1);
const allPropositionsWereRendered = resultingObject.propositions.every(
proposition => proposition.renderAttempted
);
Expand Down Expand Up @@ -173,7 +187,13 @@ const simulateViewChange = async (alloy, personalizationPayload) => {
viewChangeRequestBody.events[0].xdm._experience.decisioning.propositions
)
.eql(cartViewDecisionsMeta);

await t
.expect(
// eslint-disable-next-line no-underscore-dangle
viewChangeRequestBody.events[0].xdm._experience.decisioning
.propositionEventType.display
)
.eql(1);
// assert we return the renderAttempted flag set to true
const allPropositionsWereRendered = resultingObject.propositions.every(
proposition => proposition.renderAttempted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/
import createCollect from "../../../../../src/components/Personalization/createCollect";
import { PropositionEventType } from "../../../../../src/components/Personalization/constants/propositionEventType";

describe("Personalization::createCollect", () => {
let eventManager;
Expand Down Expand Up @@ -39,7 +40,11 @@ describe("Personalization::createCollect", () => {
expect(event.mergeXdm).toHaveBeenCalledWith({
eventType: "decisioning.propositionDisplay"
});
expect(mergeDecisionsMeta).toHaveBeenCalledWith(event, decisionsMeta);
expect(mergeDecisionsMeta).toHaveBeenCalledWith(
event,
decisionsMeta,
PropositionEventType.DISPLAY
);
expect(eventManager.sendEvent).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/
import createOnClickHandler from "../../../../../src/components/Personalization/createOnClickHandler";
import { PropositionEventType } from "../../../../../src/components/Personalization/constants/propositionEventType";

describe("Personalization::createOnClickHandler", () => {
let mergeDecisionsMeta;
Expand Down Expand Up @@ -58,7 +59,11 @@ describe("Personalization::createOnClickHandler", () => {
webPageDetails: { viewName: "foo" }
}
});
expect(mergeDecisionsMeta).toHaveBeenCalledWith(event, decisionsMeta);
expect(mergeDecisionsMeta).toHaveBeenCalledWith(
event,
decisionsMeta,
PropositionEventType.INTERACT
);
expect(collectClicks).toHaveBeenCalledWith(
clickedElement,
selectors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ governing permissions and limitations under the License.
*/

import createViewChangeHandler from "../../../../../src/components/Personalization/createViewChangeHandler";
import { PropositionEventType } from "../../../../../src/components/Personalization/constants/propositionEventType";
import { CART_VIEW_DECISIONS } from "./responsesMock/eventResponses";

describe("Personalization::createViewChangeHandler", () => {
Expand Down Expand Up @@ -59,7 +60,11 @@ describe("Personalization::createViewChangeHandler", () => {
onResponse
});
expect(executeDecisions).toHaveBeenCalledWith(CART_VIEW_DECISIONS);
expect(mergeDecisionsMeta).toHaveBeenCalledWith(event, CART_VIEW_DECISIONS);
expect(mergeDecisionsMeta).toHaveBeenCalledWith(
event,
CART_VIEW_DECISIONS,
PropositionEventType.DISPLAY
);
expect(collect).not.toHaveBeenCalled();
});

Expand Down
8 changes: 6 additions & 2 deletions test/unit/specs/components/Personalization/event.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
mergeDecisionsMeta,
mergeQuery
} from "../../../../../src/components/Personalization/event";
import { PropositionEventType } from "../../../../../src/components/Personalization/constants/propositionEventType";

describe("Personalization::event", () => {
let event;
Expand All @@ -34,7 +35,7 @@ describe("Personalization::event", () => {
scope: "cart"
}
];
mergeDecisionsMeta(event, decisionsMeta);
mergeDecisionsMeta(event, decisionsMeta, PropositionEventType.DISPLAY);
expect(event.mergeXdm).toHaveBeenCalledWith({
_experience: {
decisioning: {
Expand All @@ -47,7 +48,10 @@ describe("Personalization::event", () => {
id: "def",
scope: "cart"
}
]
],
propositionEventType: {
display: 1
}
}
}
});
Expand Down