Skip to content

Commit

Permalink
Historical events fix (#1051)
Browse files Browse the repository at this point in the history
* save payloads based on activityId

* CJM-53824

* right keys for the day and hour

* corrected payload

* npm link to local rule engine, will change to the deployed version before merging

* saved by activityId in the local storage

* constants shared between the two components src/constants

* using v2.0.2 of ruleEngine to support historical search
  • Loading branch information
shandilya3 authored Oct 12, 2023
1 parent bd77c84 commit e64e9f9
Show file tree
Hide file tree
Showing 28 changed files with 363 additions and 119 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
}
],
"dependencies": {
"@adobe/aep-rules-engine": "^2.0.1",
"@adobe/aep-rules-engine": "^2.0.2",
"@adobe/reactor-cookie": "^1.0.0",
"@adobe/reactor-load-script": "^1.1.1",
"@adobe/reactor-object-assign": "^1.0.0",
Expand Down
19 changes: 9 additions & 10 deletions sandbox/src/components/MessageFeedDemo/MessageFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const mockResponse = {
],
activity: {
id:
"39ae8d4b-b55e-43dc-a143-77f50195b487#b47fde8b-57c1-4bbe-ae22-64d5b782d183"
"8e24e51d-5203-4d0b-99c9-2b3c95ff48f2#05885219-ea84-43bc-874e-1ef4a85b6fbb"
},
correlationID: "02c77ea8-7c0e-4d33-8090-4a5bfd3d7503"
},
Expand Down Expand Up @@ -148,7 +148,7 @@ const mockResponse = {
],
activity: {
id:
"39ae8d4b-b55e-43dc-a143-77f50195b487#b47fde8b-57c1-4bbe-ae22-64d5b782d183"
"cf087a6e-131d-4147-adc7-bc1ea947f09c#ff64e6e6-e43f-479d-b5c0-f5568c771b3b"
},
correlationID: "02c77ea8-7c0e-4d33-8090-4a5bfd3d7503"
},
Expand Down Expand Up @@ -179,9 +179,9 @@ const mockResponse = {
definition: {
events: [
{
type: "decisioning.propositionDisplay",
id:
"1ae11bc5-96dc-41c7-8f71-157c57a5290e"
"iam.eventType": "display",
"iam.id":
"cf087a6e-131d-4147-adc7-bc1ea947f09c#ff64e6e6-e43f-479d-b5c0-f5568c771b3b"
}
],
matcher: "ge",
Expand Down Expand Up @@ -251,7 +251,7 @@ const mockResponse = {
],
activity: {
id:
"39ae8d4b-b55e-43dc-a143-77f50195b487#b47fde8b-57c1-4bbe-ae22-64d5b782d183"
"57712381-1690-4d19-9469-0a35ea5bd4e3#74f8e5cf-d770-41c3-b595-557b3ee00ba3"
},
correlationID: "02c77ea8-7c0e-4d33-8090-4a5bfd3d7503"
},
Expand Down Expand Up @@ -282,9 +282,9 @@ const mockResponse = {
definition: {
events: [
{
type: "decisioning.propositionDisplay",
id:
"d1f7d411-a549-47bc-a4d8-c8e638b0a46b"
"iam.eventType": "trigger",
"iam.id":
"57712381-1690-4d19-9469-0a35ea5bd4e3#74f8e5cf-d770-41c3-b595-557b3ee00ba3"
}
],
matcher: "ge",
Expand Down Expand Up @@ -424,7 +424,6 @@ export default function MessageFeed() {
surface: "web://target.jasonwaters.dev/aep.html",
callback: ({ items = [], rendered, clicked }) => {
setClickHandler(() => clicked);

setMessageFeedItems(items);
rendered(items);
}
Expand Down
6 changes: 4 additions & 2 deletions src/components/DecisioningEngine/createContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export default ({ eventRegistry, window }) => {
pageLoadTimestamp,
currentTimestamp,
currentDate: now.getDate(),
currentDay: now.getDay(),
currentHour: now.getHours(),
// Day of the week starts on Monday as is practiced in ISO 8601, but we want it to start on Sunday to match the authoring UI rule
"~state.com.adobe.module.lifecycle/lifecyclecontextdata.dayofweek":
now.getDay() + 1,
"~state.com.adobe.module.lifecycle/lifecyclecontextdata.hourofday": now.getHours(),
currentMinute: now.getMinutes(),
currentMonth: now.getMonth(),
currentYear: now.getFullYear(),
Expand Down
8 changes: 3 additions & 5 deletions src/components/DecisioningEngine/createDecisionHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

const QUALIFIED_EVENT_TYPE = "decisioning.propositionQualified";
import { PropositionEventType } from "../../constants/propositionEventType";

export default ({ eventRegistry }) => {
const recordQualified = item => {
const { id } = item;
const recordQualified = id => {
if (!id) {
return undefined;
}
return eventRegistry.addEvent(item, QUALIFIED_EVENT_TYPE, id);
return eventRegistry.addEvent({}, PropositionEventType.TRIGGER, id);
};

return { recordQualified };
Expand Down
10 changes: 6 additions & 4 deletions src/components/DecisioningEngine/createDecisionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ governing permissions and limitations under the License.
*/
import createEvaluableRulesetPayload from "./createEvaluableRulesetPayload";
import createDecisionHistory from "./createDecisionHistory";
import { getActivityId } from "./utils";

export default ({ eventRegistry }) => {
const payloads = {};
const payloadsBasedOnActivityId = {};

const decisionHistory = createDecisionHistory({ eventRegistry });

const addPayload = payload => {
if (!payload.id) {
const activityId = getActivityId(payload);
if (!activityId) {
return;
}

Expand All @@ -29,12 +31,12 @@ export default ({ eventRegistry }) => {
);

if (evaluableRulesetPayload.isEvaluable) {
payloads[payload.id] = evaluableRulesetPayload;
payloadsBasedOnActivityId[activityId] = evaluableRulesetPayload;
}
};

const evaluate = (context = {}) =>
Object.values(payloads)
Object.values(payloadsBasedOnActivityId)
.map(payload => payload.evaluate(context))
.filter(payload => payload.items.length > 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
JSON_CONTENT_ITEM,
RULESET_ITEM
} from "../Personalization/constants/schema";
import { DISPLAY } from "../Personalization/constants/eventType";
import { DISPLAY } from "../../constants/eventType";
import { getActivityId } from "./utils";

import flattenArray from "../../utils/flattenArray";
import createConsequenceAdapter from "./createConsequenceAdapter";
Expand Down Expand Up @@ -42,6 +43,7 @@ const isRulesetItem = item => {

export default (payload, eventRegistry, decisionHistory) => {
const consequenceAdapter = createConsequenceAdapter();
const activityId = getActivityId(payload);
const items = [];

const addItem = item => {
Expand All @@ -59,7 +61,7 @@ export default (payload, eventRegistry, decisionHistory) => {
};

const evaluate = context => {
const displayEvent = eventRegistry.getEvent(DISPLAY, payload.id);
const displayEvent = eventRegistry.getEvent(DISPLAY, activityId);

const displayedDate = displayEvent
? displayEvent.firstTimestamp
Expand All @@ -72,7 +74,7 @@ export default (payload, eventRegistry, decisionHistory) => {
.map(item => {
const {
firstTimestamp: qualifiedDate
} = decisionHistory.recordQualified(item);
} = decisionHistory.recordQualified(activityId);

return {
...item,
Expand Down
48 changes: 38 additions & 10 deletions src/components/DecisioningEngine/createEventRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ governing permissions and limitations under the License.
import {
createRestoreStorage,
createSaveStorage,
getExpirationDate
getExpirationDate,
getActivityId
} from "./utils";
import { EVENT_TYPE_TRUE } from "../../constants/eventType";

const STORAGE_KEY = "events";
const MAX_EVENT_RECORDS = 1000;
const DEFAULT_SAVE_DELAY = 500;
const RETENTION_PERIOD = 30;

const prefixed = key => `iam.${key}`;
export const createEventPruner = (
limit = MAX_EVENT_RECORDS,
retentionPeriod = RETENTION_PERIOD
Expand All @@ -36,7 +39,7 @@ export const createEventPruner = (
.sort((a, b) => a.firstTimestamp - b.firstTimestamp)
.slice(-1 * limit)
.forEach(entry => {
pruned[eventType][entry.event.id] = entry;
pruned[eventType][entry.event[prefixed("id")]] = entry;
});
});
return pruned;
Expand All @@ -53,11 +56,10 @@ export default ({ storage, saveDelay = DEFAULT_SAVE_DELAY }) => {
);

const events = restore({});
const addEvent = (event, eventType, eventId) => {
const addEvent = (event, eventType, eventId, action) => {
if (!events[eventType]) {
events[eventType] = {};
}

const existingEvent = events[eventType][eventId];

const count = existingEvent ? existingEvent.count : 0;
Expand All @@ -67,7 +69,12 @@ export default ({ storage, saveDelay = DEFAULT_SAVE_DELAY }) => {
: timestamp;

events[eventType][eventId] = {
event: { ...event, id: eventId, type: eventType },
event: {
...event,
[prefixed("id")]: eventId,
[prefixed("eventType")]: eventType,
[prefixed("action")]: action
},
firstTimestamp,
timestamp,
count: count + 1
Expand All @@ -90,13 +97,34 @@ export default ({ storage, saveDelay = DEFAULT_SAVE_DELAY }) => {
) {
return;
}

const { decisioning = {} } = _experience;
const { propositions = [] } = decisioning;
const {
propositionEventType: propositionEventTypeObj = {},
propositionAction = {},
propositions = []
} = decisioning;

const propositionEventTypesList = Object.keys(propositionEventTypeObj);

// https://wiki.corp.adobe.com/pages/viewpage.action?spaceKey=CJM&title=Proposition+Event+Types
if (propositionEventTypesList.length === 0) {
return;
}

propositions.forEach(proposition =>
addEvent({ proposition }, eventType, proposition.id)
);
const { id: action } = propositionAction;

propositionEventTypesList.forEach(propositionEventType => {
if (propositionEventTypeObj[propositionEventType] === EVENT_TYPE_TRUE) {
propositions.forEach(proposition => {
addEvent(
{},
propositionEventType,
getActivityId(proposition),
action
);
});
}
});
};
const getEvent = (eventType, eventId) => {
if (!events[eventType]) {
Expand Down
8 changes: 8 additions & 0 deletions src/components/DecisioningEngine/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,11 @@ export const ensureSchemaBasedRulesetConsequences = event => {
}
});
};

export const getActivityId = proposition => {
const { scopeDetails = {} } = proposition;
const { activity = {} } = scopeDetails;
const { id } = activity;

return id;
};
4 changes: 2 additions & 2 deletions src/components/Personalization/createCollect.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
import { DISPLAY } from "./constants/eventType";
import { getPropositionEventType } from "./constants/propositionEventType";
import { DISPLAY } from "../../constants/eventType";
import { getPropositionEventType } from "../../constants/propositionEventType";
import { isNonEmptyArray } from "../../utils";

export default ({ eventManager, mergeDecisionsMeta }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Personalization/createOnClickHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ governing permissions and limitations under the License.
*/

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

export default ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTA
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/
import { PropositionEventType } from "./constants/propositionEventType";
import { PropositionEventType } from "../../constants/propositionEventType";

export default ({ pendingDisplayNotifications, mergeDecisionsMeta }) => ({
event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
string
} from "../../utils/validation";
import { MESSAGE_FEED_ITEM } from "./constants/schema";
import { DISPLAY, INTERACT } from "./constants/eventType";
import { DISPLAY, INTERACT } from "../../constants/eventType";

const validateOptions = ({ options }) => {
const validator = objectOf({
Expand Down
2 changes: 1 addition & 1 deletion src/components/Personalization/createViewChangeHandler.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 { PropositionEventType } from "./constants/propositionEventType";
import { PropositionEventType } from "../../constants/propositionEventType";

export default ({ mergeDecisionsMeta, processPropositions, viewCache }) => {
return ({ personalizationDetails, event, onResponse }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Personalization/event.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.
*/

const EVENT_TYPE_TRUE = 1;
import { EVENT_TYPE_TRUE } from "../../constants/eventType";

/* eslint-disable no-underscore-dangle */
export const mergeDecisionsMeta = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getNonce } from "../../dom-actions/dom";
import { createElement, parseAnchor, removeElementById } from "../utils";
import { TEXT_HTML } from "../../constants/contentType";
import { assign } from "../../../../utils";
import { getEventType } from "../../constants/propositionEventType";
import { getEventType } from "../../../../constants/propositionEventType";

const ALLOY_MESSAGING_CONTAINER_ID = "alloy-messaging-container";
const ALLOY_OVERLAY_CONTAINER_ID = "alloy-overlay-container";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export const DISPLAY = "decisioning.propositionDisplay";
export const INTERACT = "decisioning.propositionInteract";
export const TRIGGER = "decisioning.propositionTrigger";
export const DISMISS = "decisioning.propositionDismiss";
export const EVENT_TYPE_TRUE = 1;
File renamed without changes.
Loading

0 comments on commit e64e9f9

Please sign in to comment.