DigitalConsumer.FixMyGlass/src/router/methods/helpers/consume-referral-info.js
2026-02-25 13:01:59 -05:00

44 lines
2.2 KiB
JavaScript

import { getQuerystringParameter } from "@/helpers/querystring-helper";
import { queryStrings } from "@/constants/query-strings";
import store from "@/store";
import { storeMutations } from "@/constants/store-mutations";
import { updateOrCreateFunnelCookie } from "@/helpers/heritage-integration/cookie-helper";
import { getFunnelCookie } from "@/helpers/heritage-integration/cookie-helper";
export async function consumeReferralQuerystrings() {
let referralNumber = getQuerystringParameter(queryStrings.REFERRAL_NUMBER);
let parentAccount = getQuerystringParameter(queryStrings.PARENT_ACCOUNT);
let correlationId = getQuerystringParameter(queryStrings.CORRELATION_ID);
let referralDate = null;
let savedSessionId = null;
// If no referral number in querystring, check if heritage funnel updated last.
// This would indicate a customer that went to heritage but did not return through the
// normal route. ie: left the site in search of a discount and returned without querystrings.
//or if a referral number is in query string check if heritage funnel updated last
// This would indicate a customer that returned through normal route like from sfa email
const didHeritageFunnelUpdateLast = getFunnelCookie()?.DidHeritageFunnelUpdateLast;
if (didHeritageFunnelUpdateLast) {
referralNumber = referralNumber ?? getFunnelCookie().ReferralNumber;
parentAccount = parentAccount ?? getFunnelCookie().ReferralParentAccountNumber;
correlationId = correlationId ?? getFunnelCookie().ReferralCorrelationId;
referralDate = getFunnelCookie().ReferralDate;
savedSessionId = getFunnelCookie().SavedSessionId;
}
if (referralNumber) {
store.commit(storeMutations.UPDATE_REFERRAL_NUMBER, referralNumber);
store.commit(storeMutations.UPDATE_PARENT_ACCT_NUMBER, parentAccount);
store.commit(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, correlationId);
if (referralDate) {
store.commit(storeMutations.UPDATE_REFERRAL_DATE, referralDate);
}
if (savedSessionId) {
store.commit(storeMutations.UPDATE_SAVED_SESSION_ID, savedSessionId);
}
updateOrCreateFunnelCookie();
}
}