CSR-111 Fix tests and cleanup
This commit is contained in:
parent
b526fc059f
commit
61ccfe268b
2 changed files with 21 additions and 17 deletions
|
|
@ -10,7 +10,8 @@ export function updateOrCreateFunnelCookie() {
|
||||||
const shouldSuppressConceptFunnel = getFunnelCookie()?.SuppressConceptFunnel;
|
const shouldSuppressConceptFunnel = getFunnelCookie()?.SuppressConceptFunnel;
|
||||||
|
|
||||||
// Create the cookie
|
// Create the cookie
|
||||||
document.cookie = `${cookieNames.FUNNEL_SESSION_INFO}={}; path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()}`;
|
// if (!getFunnelCookie())
|
||||||
|
// createOrUpdateCookie(cookieNames.FUNNEL_SESSION_INFO, {}, {});
|
||||||
|
|
||||||
// Set up cookie with all the props.
|
// Set up cookie with all the props.
|
||||||
setFunnelCookieProperties({
|
setFunnelCookieProperties({
|
||||||
|
|
@ -48,14 +49,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()};`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -110,13 +111,13 @@ export function getSessionIdValue(){
|
||||||
Updates session ID cookie with new expiration date
|
Updates session ID cookie with new expiration date
|
||||||
*/
|
*/
|
||||||
export function updateSessionIdCookie() {
|
export function updateSessionIdCookie() {
|
||||||
createCookie(cookieNames.SESSION_ID, getSessionIdValue(), { maxAge: 60 * 30 });
|
createOrUpdateCookie(cookieNames.SESSION_ID, getSessionIdValue(), { maxAge: 60 * 30 });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setCookieProperties(properties, { useDefaultFunnelCookieAttributes = true, maxAge }) {
|
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 => {
|
||||||
createCookie(key, properties[key], { useDefaultFunnelCookieAttributes, maxAge });
|
createOrUpdateCookie(key, properties[key], { useDefaultFunnelCookieAttributes, maxAge, isSecure });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -133,6 +134,7 @@ export function setCookieProperties(properties, { useDefaultFunnelCookieAttribut
|
||||||
Takes an object with properties to set. Will overwrite existing properties.
|
Takes an object with properties to set. Will overwrite existing properties.
|
||||||
*/
|
*/
|
||||||
function setFunnelCookieProperties(properties) {
|
function setFunnelCookieProperties(properties) {
|
||||||
|
|
||||||
if (typeof properties == "object") {
|
if (typeof properties == "object") {
|
||||||
let cookie = getFunnelCookie();
|
let cookie = getFunnelCookie();
|
||||||
|
|
||||||
|
|
@ -142,8 +144,7 @@ function setFunnelCookieProperties(properties) {
|
||||||
});
|
});
|
||||||
|
|
||||||
const cookieValueJson = JSON.stringify(cookie);
|
const cookieValueJson = JSON.stringify(cookie);
|
||||||
|
createOrUpdateCookie(cookieNames.FUNNEL_SESSION_INFO, cookieValueJson, {});
|
||||||
createCookie(cookieNames.FUNNEL_SESSION_INFO, cookieValueJson, {});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -152,18 +153,16 @@ function setFunnelCookieProperties(properties) {
|
||||||
Used to create a cookie.
|
Used to create a cookie.
|
||||||
`useDefaultFunnelCookieAttributes` will set the path and domain to our defaults
|
`useDefaultFunnelCookieAttributes` will set the path and domain to our defaults
|
||||||
*/
|
*/
|
||||||
function createCookie(key, value, { useDefaultFunnelCookieAttributes = true, maxAge, isSecure = true }) {
|
function createOrUpdateCookie(key, value = "", { useDefaultFunnelCookieAttributes = true, maxAge, isSecure = true }) {
|
||||||
let cookieToAdd = `${key}=${value}; `;
|
let cookieToAdd = `${key}=${value}; `;
|
||||||
console.log(isSecure)
|
|
||||||
console.log(useDefaultFunnelCookieAttributes)
|
|
||||||
|
|
||||||
if (useDefaultFunnelCookieAttributes) {
|
if (useDefaultFunnelCookieAttributes) {
|
||||||
cookieToAdd += `path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()} `;
|
cookieToAdd += `path=${applicationConfig.COOKIE_PATH}; ${getCookieDomainValue()} `;
|
||||||
}
|
}
|
||||||
if (isSecure) {
|
if (isSecure && !isLocalhost()) {
|
||||||
cookieToAdd += `secure; `;
|
cookieToAdd += `secure; `;
|
||||||
}
|
}
|
||||||
if (maxAge) {
|
if (!isNaN(maxAge)) {
|
||||||
cookieToAdd += `max-age=${maxAge};`;
|
cookieToAdd += `max-age=${maxAge};`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,7 +174,7 @@ function createCookie(key, value, { useDefaultFunnelCookieAttributes = true, max
|
||||||
*/
|
*/
|
||||||
function getDomainWithoutSubdomain() {
|
function getDomainWithoutSubdomain() {
|
||||||
let url = location.hostname;
|
let url = location.hostname;
|
||||||
if (url.includes("localhost")) {
|
if (isLocalhost()) {
|
||||||
return "localhost";
|
return "localhost";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -199,3 +198,7 @@ function getCookieValueByName(name) {
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isLocalhost() {
|
||||||
|
return location.hostname.includes("localhost");
|
||||||
|
}
|
||||||
|
|
@ -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,8 @@ 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 });
|
||||||
|
// document.cookie = `${key}=${cookieValue}; path=/; ${getCookieDomainValue()}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue