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

MWPW-149470 [MILO][MEP] Remove sendTargetResponseAnalytics function #3599

Closed
wants to merge 2 commits into from
Closed
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
42 changes: 4 additions & 38 deletions libs/features/personalization/personalization.js
Original file line number Diff line number Diff line change
Expand Up @@ -1163,38 +1163,6 @@ async function updateManifestsAndPropositions(
return targetManifests;
}

function roundToQuarter(num) {
return Math.ceil(num / 250) / 4;
}

function calculateResponseTime(responseStart) {
const responseTime = Date.now() - responseStart;
return roundToQuarter(responseTime);
}

function sendTargetResponseAnalytics(failure, responseStart, timeoutLocal, message) {
// temporary solution until we can decide on a better timeout value
const responseTime = calculateResponseTime(responseStart);
const timeoutTime = roundToQuarter(timeoutLocal);
let val = `target response time ${responseTime}:timed out ${failure}:timeout ${timeoutTime}`;
if (message) val += `:${message}`;
// eslint-disable-next-line no-underscore-dangle
window._satellite?.track?.('event', {
documentUnloading: true,
xdm: {
eventType: 'web.webinteraction.linkClicks',
web: {
webInteraction: {
linkClicks: { value: 1 },
type: 'other',
name: val,
},
},
},
data: { _adobe_corpnew: { digitalData: { primaryEvent: { eventInfo: { eventName: val } } } } },
});
}

const handleAlloyResponse = (response) => ((response.propositions || response.decisions))
?.map((i) => i.items)
?.flat()
Expand All @@ -1216,19 +1184,17 @@ const handleAlloyResponse = (response) => ((response.propositions || response.de
?.filter(Boolean) ?? [];

async function handleMartechTargetInteraction(
{ config, targetInteractionPromise, calculatedTimeout },
{ config, targetInteractionPromise },
) {
let targetManifests = [];
let targetPropositions = [];
if (config?.mep?.enablePersV2 && targetInteractionPromise) {
const { targetInteractionData, respTime, respStartTime } = await targetInteractionPromise;
sendTargetResponseAnalytics(false, respStartTime, calculatedTimeout);
const { targetInteractionData, respTime } = await targetInteractionPromise;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove the respStartTime from the return value of targetInteractionPromise in utils?
Since it is used at only this page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, maybe I'm misunderstanding the comment. I am using it on line 1197. So 5 lines later

Copy link
Contributor

@swamu swamu Feb 4, 2025

Choose a reason for hiding this comment

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

@vgoodric, the targetInteractionPromise function is defined in utils.js and returns the respStartTime. Since this method is only invoked here and the respStartTime is no longer needed, we can remove it from the return value in utils.js as well.

So the code in utils.js changes from:

targetInteractionPromise = (async () => {
     const { loadAnalyticsAndInteractionData } = await import('../martech/helpers.js');
     const now = performance.now();
     performance.mark('interaction-start');
     const data = await loadAnalyticsAndInteractionData(
       { locale, env: getEnv({})?.name, calculatedTimeout, hybridPersEnabled },
     );
     performance.mark('interaction-end');
     performance.measure('total-time', 'interaction-start', 'interaction-end');
     const respTime = performance.getEntriesByName('total-time')[0];

     return { targetInteractionData: data, respTime, respStartTime: now };
   })();

to

targetInteractionPromise = (async () => {
     const { loadAnalyticsAndInteractionData } = await import('../martech/helpers.js');
     performance.mark('interaction-start');
     const data = await loadAnalyticsAndInteractionData(
       { locale, env: getEnv({})?.name, calculatedTimeout, hybridPersEnabled },
     );
     performance.mark('interaction-end');
     performance.measure('total-time', 'interaction-start', 'interaction-end');
     const respTime = performance.getEntriesByName('total-time')[0];

     return { targetInteractionData: data, respTime };
   })();

if (targetInteractionData.result) {
const roundedResponseTime = roundToQuarter(respTime);
performance.clearMarks();
performance.clearMeasures();
try {
window.lana.log(`target response time: ${roundedResponseTime}`, {
window.lana.log(`target response time: ${Math.ceil(respTime / 250) / 4}`, {
tags: 'martech',
errorType: 'e',
sampleRate: 0.5,
Expand All @@ -1252,7 +1218,7 @@ async function callMartech(config) {
const {
targetManifests,
targetPropositions,
} = await getTargetPersonalization({ handleAlloyResponse, sendTargetResponseAnalytics });
} = await getTargetPersonalization({ handleAlloyResponse });
return updateManifestsAndPropositions(
{ config, targetManifests, targetPropositions },
);
Expand Down
12 changes: 7 additions & 5 deletions libs/martech/martech.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,12 @@ function calculateResponseTime(responseStart) {
}

export const getTargetPersonalization = async (
{ handleAlloyResponse, sendTargetResponseAnalytics },
{ handleAlloyResponse },
) => {
const responseStart = Date.now();
window.addEventListener(ALLOY_SEND_EVENT, () => {
const responseTime = calculateResponseTime(responseStart);
try {
window.lana.log(`target response time: ${responseTime}`, {
window.lana.log(`target response time: ${calculateResponseTime(responseStart)}`, {
tags: 'martech',
errorType: 'e',
sampleRate: 0.5,
Expand Down Expand Up @@ -99,9 +98,12 @@ export const getTargetPersonalization = async (
}
if (response.timeout) {
waitForEventOrTimeout(ALLOY_SEND_EVENT, 5100 - timeout)
.then(() => sendTargetResponseAnalytics(true, responseStart, timeout));
.then(() => window.lana.log(`target response timed out: ${calculateResponseTime(responseStart)}`, {
tags: 'martech',
errorType: 'e',
sampleRate: 0.5,
}));
} else {
sendTargetResponseAnalytics(false, responseStart, timeout);
targetManifests = handleAlloyResponse(response.result);
targetPropositions = response.result?.propositions || [];
}
Expand Down
Loading