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

ENB-7820: Add values for event95 #3782

Open
wants to merge 6 commits into
base: stage
Choose a base branch
from
Open
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
28 changes: 23 additions & 5 deletions libs/martech/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ function getOrGenerateUserId() {
};
}

function getUpdatedVisitAttempt() {
const { hostname } = window.location;
const secondVisitAttempt = Number(localStorage.getItem('secondHit')) || 0;

const isAdobeDomain = hostname === 'www.adobe.com' || hostname === 'www.stage.adobe.com';
const consentCookieValue = getCookie('OptanonConsent');

if (consentCookieValue?.includes('C0002:1') && isAdobeDomain) {
const updatedVisitAttempt = secondVisitAttempt === 0 ? 1 : secondVisitAttempt + 1;
localStorage.setItem('secondHit', updatedVisitAttempt);
return updatedVisitAttempt;
}

return secondVisitAttempt;
}

function getPageNameForAnalytics({ locale }) {
const { host, pathname } = new URL(window.location.href);
const [modifiedPath] = pathname.split('/').filter((x) => x !== locale.prefix).join(':').split('.');
Expand Down Expand Up @@ -240,6 +256,7 @@ function createRequestPayload({ updatedContext, pageName, locale, env, hitType }
approach: 'martech-API',
edgeConfigIdLaunch: dataStreamId,
edgeConfigId: dataStreamId,
personalisation: 'hybrid',
},
},
},
Expand Down Expand Up @@ -269,6 +286,12 @@ function createRequestPayload({ updatedContext, pageName, locale, env, hitType }
data.web = { webPageDetails };
data.eventType = hitTypeEventTypeMap[hitType];

if (getUpdatedVisitAttempt() === 2) {
digitalData.adobe = {
libraryVersions: 'alloy-api',
experienceCloud: { secondVisits: 'setEvent' },
};
}
xdm.implementationDetails = {
name: 'https://ns.adobe.com/experience/alloy/reactor',
version: '1.0',
Expand Down Expand Up @@ -496,22 +519,17 @@ export const loadAnalyticsAndInteractionData = async (

const CURRENT_DATE = new Date();
const localTime = CURRENT_DATE.toISOString();

const timezoneOffset = CURRENT_DATE.getTimezoneOffset();
if (hybridPersEnabled) {
window.hybridPers = true;
}
const hitType = hybridPersEnabled ? 'pageView' : 'propositionFetch';

const pageName = getPageNameForAnalytics({ locale });

const updatedContext = getUpdatedContext({ ...getDeviceInfo(), localTime, timezoneOffset });

const requestUrl = createRequestUrl({
env,
hitType,
});

const requestPayload = { updatedContext, pageName, locale, env, hitType };
const requestBody = createRequestPayload(requestPayload);

Expand Down
Loading