Merge pull request #675 from Safelite/defect/CSR-759

Defect/csr 759
This commit is contained in:
katieoh-safelite 2022-08-18 12:01:59 -04:00 committed by GitHub
commit a6ad6a5ed9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 17 deletions

View file

@ -9,9 +9,6 @@ export function updateOrCreateFunnelCookie() {
const wasClaimRegistrationDelayed = getFunnelCookie()?.HasDelayedClaimRegistration; const wasClaimRegistrationDelayed = getFunnelCookie()?.HasDelayedClaimRegistration;
const shouldSuppressConceptFunnel = getFunnelCookie()?.SuppressConceptFunnel; const shouldSuppressConceptFunnel = getFunnelCookie()?.SuppressConceptFunnel;
// Create the cookie
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()};`;
// Set up cookie with all the props. // Set up cookie with all the props.
setFunnelCookieProperties({ setFunnelCookieProperties({
LastTouched: new Date().toUTCString(), LastTouched: new Date().toUTCString(),
@ -48,14 +45,14 @@ export function getFunnelCookie() {
Removes cookie from browser. Removes cookie from browser.
*/ */
export function deleteFunnelCookie() { export function deleteFunnelCookie() {
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=; Max-Age=0; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()}`; createOrUpdateCookie(cookieNames.FUNNEL_SESSION_INFO, undefined, { maxAge: 0 });
} }
/* /*
Gets cookie domain value. Localhost will be empty "". Gets cookie domain value. Localhost will be empty "".
*/ */
export function getCookieDomainValue() { export function getCookieDomainValue() {
return location.hostname.includes("localhost") ? "" : `domain=${getDomainWithoutSubdomain()};`; return isLocalhost() ? "" : `domain=${getDomainWithoutSubdomain()};`;
} }
/* /*
@ -106,10 +103,17 @@ export function getSessionIdValue(){
return '00000000-0000-0000-0000-000000000000'; return '00000000-0000-0000-0000-000000000000';
} }
export function setCookieProperties(properties) { /*
Updates session ID cookie with new expiration date
*/
export function updateSessionIdCookie() {
createOrUpdateCookie(cookieNames.SESSION_ID, getSessionIdValue(), { maxAge: 60 * 30 });
}
export function setCookieProperties(properties, { useDefaultFunnelCookieAttributes = true, maxAge, isSecure }) {
if (typeof properties == "object") { if (typeof properties == "object") {
Object.keys(properties).forEach(key => { Object.keys(properties).forEach(key => {
document.cookie = `${key}=${properties[key]}`; createOrUpdateCookie(key, properties[key], { useDefaultFunnelCookieAttributes, maxAge, isSecure });
}); });
} }
} }
@ -133,20 +137,39 @@ function setFunnelCookieProperties(properties) {
Object.keys(properties).forEach(key => { Object.keys(properties).forEach(key => {
cookie[key] = properties[key]; cookie[key] = properties[key];
}); });
const cookieValueJson = JSON.stringify(cookie);
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${cookieValueJson}; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()}`;
} }
const cookieValueJson = JSON.stringify(cookie ?? {});
createOrUpdateCookie(cookieNames.FUNNEL_SESSION_INFO, cookieValueJson, {});
} }
} }
/*
Used to create a cookie.
`useDefaultFunnelCookieAttributes` will set the path and domain to our defaults
*/
function createOrUpdateCookie(key, value = "", { useDefaultFunnelCookieAttributes = true, maxAge, isSecure = true }) {
let cookieToAdd = `${key}=${value}; `;
if (useDefaultFunnelCookieAttributes) {
cookieToAdd += `path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()} `;
}
if (isSecure && !isLocalhost()) {
cookieToAdd += `secure; `;
}
if (!isNaN(maxAge)) {
cookieToAdd += `max-age=${maxAge};`;
}
document.cookie = cookieToAdd;
}
/* /*
Gets current domain without the subdomain for cookie. Gets current domain without the subdomain for cookie.
*/ */
function getDomainWithoutSubdomain() { function getDomainWithoutSubdomain() {
let url = location.hostname; let url = location.hostname;
if (url.includes("localhost")) { if (isLocalhost()) {
return "localhost"; return "localhost";
} }
@ -169,4 +192,8 @@ function getCookieValueByName(name) {
return parts.pop().split(";").shift(); return parts.pop().split(";").shift();
} }
return ""; return "";
}
function isLocalhost() {
return location.hostname.includes("localhost");
} }

View file

@ -6,7 +6,7 @@ import { fmgPageValues } from "@/router/router-constants/fmgPage-values";
import { cookieNames } from "@/constants/cookie-names"; import { cookieNames } from "@/constants/cookie-names";
import { Form } from "vee-validate"; import { Form } from "vee-validate";
import baseMixin from "@/mixins/base-mixin"; import baseMixin from "@/mixins/base-mixin";
import { getCookieDomainValue } from "@/helpers/heritage-integration/cookie-helper"; import { getCookieDomainValue, setCookieProperties } from "@/helpers/heritage-integration/cookie-helper";
import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents, ValueToLogTypes } from "@/constants/analytics"; import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents, ValueToLogTypes } from "@/constants/analytics";
import { queryStrings } from "@/constants/query-strings"; import { queryStrings } from "@/constants/query-strings";
import { routerParams } from "@/router/router-constants/router-params"; import { routerParams } from "@/router/router-constants/router-params";
@ -106,7 +106,7 @@ export function setupCookies({ funnelCookieValue = "", includeHeritageCookie = t
Object.keys(cookies).forEach(key => { Object.keys(cookies).forEach(key => {
const cookieValue = key == cookieNames.FUNNEL_SESSION_INFO ? funnelCookieValue : cookies[key]; const cookieValue = key == cookieNames.FUNNEL_SESSION_INFO ? funnelCookieValue : cookies[key];
if (includeHeritageCookie || key != cookieNames.FUNNEL_SESSION_INFO) if (includeHeritageCookie || key != cookieNames.FUNNEL_SESSION_INFO)
document.cookie = `${key}=${cookieValue}; path=/; ${getCookieDomainValue()}`; setCookieProperties({ [key]: cookieValue }, { isSecure: false });
}); });
} }

View file

@ -126,10 +126,14 @@ export default {
if (response.data) { if (response.data) {
if (response.data.sessionKey && skey === 0) { if (response.data.sessionKey && skey === 0) {
setCookieProperties({ [cookieNames.SESSION_KEY]: response.data.sessionKey}); setCookieProperties({ [cookieNames.SESSION_KEY]: response.data.sessionKey}, {
useDefaultFunnelCookieAttributes: false
});
} }
if (response.data.sessionId && sid === '00000000-0000-0000-0000-000000000000') { if (response.data.sessionId && sid === '00000000-0000-0000-0000-000000000000') {
setCookieProperties({ [cookieNames.SESSION_ID]: response.data.sessionId}); setCookieProperties({ [cookieNames.SESSION_ID]: response.data.sessionId}, {
maxAge: 60 * 30 // 30 minutes
});
} }
} }
}, },

View file

@ -10,7 +10,7 @@ import { getDeviceIdValue } from "@/helpers/heritage-integration/cookie-helper";
// Heritage integration // Heritage integration
import { isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper"; import { isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper";
import { updateOrCreateFunnelCookie, getFunnelCookie } from "@/helpers/heritage-integration/cookie-helper"; import { updateOrCreateFunnelCookie, getFunnelCookie, updateSessionIdCookie } from "@/helpers/heritage-integration/cookie-helper";
import { loadOrderIfPresent, saveOrder } from "@/helpers/heritage-integration/order-helper"; import { loadOrderIfPresent, saveOrder } from "@/helpers/heritage-integration/order-helper";
import { getPageToRouteExistingOrderTo, navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; import { getPageToRouteExistingOrderTo, navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper";
@ -31,6 +31,9 @@ const routes = [
if (analyticsMixin.methods.noSession()) { if (analyticsMixin.methods.noSession()) {
await analyticsMixin.methods.initSession(); await analyticsMixin.methods.initSession();
} }
else {
updateSessionIdCookie();
}
if (getFunnelCookie()?.SuppressConceptFunnel) { if (getFunnelCookie()?.SuppressConceptFunnel) {
await navigateToHeritageFunnel(false); await navigateToHeritageFunnel(false);