diff --git a/src/helpers/heritage-integration/cookie-helper.js b/src/helpers/heritage-integration/cookie-helper.js index 775a64fec..69d4ee4b5 100644 --- a/src/helpers/heritage-integration/cookie-helper.js +++ b/src/helpers/heritage-integration/cookie-helper.js @@ -10,7 +10,7 @@ export function updateOrCreateFunnelCookie() { const shouldSuppressConceptFunnel = getFunnelCookie()?.SuppressConceptFunnel; // Create the cookie - document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()};`; + document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()}`; // Set up cookie with all the props. setFunnelCookieProperties({ @@ -106,10 +106,17 @@ export function getSessionIdValue(){ return '00000000-0000-0000-0000-000000000000'; } -export function setCookieProperties(properties) { +/* + Updates session ID cookie with new expiration date +*/ +export function updateSessionIdCookie() { + createCookie(cookieNames.SESSION_ID, getSessionIdValue(), { maxAge: 60 * 30 }); +} + +export function setCookieProperties(properties, { useDefaultFunnelCookieAttributes = true, maxAge }) { if (typeof properties == "object") { Object.keys(properties).forEach(key => { - document.cookie = `${key}=${properties[key]}`; + createCookie(key, properties[key], { useDefaultFunnelCookieAttributes, maxAge }); }); } } @@ -135,12 +142,34 @@ function setFunnelCookieProperties(properties) { }); const cookieValueJson = JSON.stringify(cookie); - - document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}=${cookieValueJson}; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()}`; + + createCookie(cookieNames.FUNNEL_SESSION_INFO, cookieValueJson, {}); } } } +/* + Used to create a cookie. + `useDefaultFunnelCookieAttributes` will set the path and domain to our defaults +*/ +function createCookie(key, value, { useDefaultFunnelCookieAttributes = true, maxAge, isSecure = true }) { + let cookieToAdd = `${key}=${value}; `; + console.log(isSecure) + console.log(useDefaultFunnelCookieAttributes) + + if (useDefaultFunnelCookieAttributes) { + cookieToAdd += `path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()} `; + } + if (isSecure) { + cookieToAdd += `secure; `; + } + if (maxAge) { + cookieToAdd += `max-age=${maxAge};`; + } + + document.cookie = cookieToAdd; +} + /* Gets current domain without the subdomain for cookie. */ diff --git a/src/mixins/analytics-mixin.js b/src/mixins/analytics-mixin.js index e24a55e36..f5535188b 100644 --- a/src/mixins/analytics-mixin.js +++ b/src/mixins/analytics-mixin.js @@ -122,10 +122,14 @@ export default { if (response.data) { 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') { - setCookieProperties({ [cookieNames.SESSION_ID]: response.data.sessionId}); + setCookieProperties({ [cookieNames.SESSION_ID]: response.data.sessionId}, { + maxAge: 60 * 30 // 30 minutes + }); } } }, diff --git a/src/router/index.js b/src/router/index.js index 6fcd48c28..e2c1fe4d1 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -10,7 +10,7 @@ import { getDeviceIdValue } from "@/helpers/heritage-integration/cookie-helper"; // Heritage integration 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 { getPageToRouteExistingOrderTo, navigateToHeritageFunnel } from "@/helpers/heritage-integration/navigation-helper"; @@ -31,6 +31,9 @@ const routes = [ if (analyticsMixin.methods.noSession()) { await analyticsMixin.methods.initSession(); } + else { + updateSessionIdCookie(); + } if (getFunnelCookie()?.SuppressConceptFunnel) { await navigateToHeritageFunnel(false);