CSR-663 Make sure the create session only runs once move to router
This commit is contained in:
parent
4be843e1b8
commit
15ed8aad39
2 changed files with 44 additions and 35 deletions
|
|
@ -1,19 +1,14 @@
|
||||||
import { storeActions } from "@/constants/store-actions";
|
import { storeActions } from "@/constants/store-actions";
|
||||||
import { setCookieProperties, getDeviceIdValue, getSessionIdValue, getSessionKeyValue } from "@/helpers/heritage-integration/cookie-helper";
|
import { getDeviceIdValue, getSessionIdValue, getSessionKeyValue } from "@/helpers/heritage-integration/cookie-helper";
|
||||||
import { queryStrings } from "@/constants/query-strings";
|
import { queryStrings } from "@/constants/query-strings";
|
||||||
import { experimentSettings } from "@/constants/experiments";
|
import { experimentSettings } from "@/constants/experiments";
|
||||||
import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents } from "@/constants/analytics";
|
import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents } from "@/constants/analytics";
|
||||||
import { cookieNames } from "@/constants/cookie-names";
|
|
||||||
|
|
||||||
import baseMixin from "@/mixins/base-mixin";
|
import baseMixin from "@/mixins/base-mixin";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
logPageView(pageEvent) {
|
logPageView(pageEvent) {
|
||||||
if (getSessionKeyValue() === 0 || getSessionIdValue() === '00000000-0000-0000-0000-000000000000') {
|
|
||||||
this.initSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentPageName = getPageNameByQueryString();
|
const currentPageName = getPageNameByQueryString();
|
||||||
var payload = {
|
var payload = {
|
||||||
userId: getDeviceIdValue(),
|
userId: getDeviceIdValue(),
|
||||||
|
|
@ -29,10 +24,6 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
logCustomEvent(category, action, label, value) {
|
logCustomEvent(category, action, label, value) {
|
||||||
if (getSessionKeyValue() === 0 || getSessionIdValue() === '00000000-0000-0000-0000-000000000000') {
|
|
||||||
this.initSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentPageName = getPageNameByQueryString();
|
const currentPageName = getPageNameByQueryString();
|
||||||
|
|
||||||
var payload = {
|
var payload = {
|
||||||
|
|
@ -50,28 +41,6 @@ export default {
|
||||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_CUSTOM_EVENT, payload, false);
|
baseMixin.methods.dispatchStoreAction(storeActions.LOG_CUSTOM_EVENT, payload, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
async initSession() {
|
|
||||||
const sid = getSessionIdValue();
|
|
||||||
const skey = getSessionKeyValue();
|
|
||||||
var payload = {
|
|
||||||
userId: getDeviceIdValue(),
|
|
||||||
sessionId: sid,
|
|
||||||
userAgent: navigator.userAgent,
|
|
||||||
referrer: document.referrer,
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await baseMixin.methods.dispatchStoreAction(storeActions.INITIALIZE_SESSION, payload, false);
|
|
||||||
|
|
||||||
if (response.data) {
|
|
||||||
if (response.data.sessionKey && skey === 0) {
|
|
||||||
setCookieProperties({ [cookieNames.SESSION_KEY]: response.data.sessionKey});
|
|
||||||
}
|
|
||||||
if (response.data.sessionId && sid === '00000000-0000-0000-0000-000000000000') {
|
|
||||||
setCookieProperties({ [cookieNames.SESSION_ID]: response.data.sessionId});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
pushEventToGA(category, action, label, pushToLogApp = false) {
|
pushEventToGA(category, action, label, pushToLogApp = false) {
|
||||||
const currentPageName = getPageNameByQueryString();
|
const currentPageName = getPageNameByQueryString();
|
||||||
const eventToBePushed = {
|
const eventToBePushed = {
|
||||||
|
|
@ -86,9 +55,9 @@ export default {
|
||||||
pushToDataLayerIfDefined(eventToBePushed);
|
pushToDataLayerIfDefined(eventToBePushed);
|
||||||
|
|
||||||
if (pushToLogApp) {
|
if (pushToLogApp) {
|
||||||
this.logCustomEvent(category, action, label, undefined);
|
this.logCustomEvent(category, action, label, undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
pushPageViewToGA() {
|
pushPageViewToGA() {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js"
|
||||||
import { routingTable } from "@/router/router-constants/routing-table.js";
|
import { routingTable } from "@/router/router-constants/routing-table.js";
|
||||||
import { globalEvents, globalEventTypes } from "@/constants/events";
|
import { globalEvents, globalEventTypes } from "@/constants/events";
|
||||||
import { queryStrings } from "@/constants/query-strings";
|
import { queryStrings } from "@/constants/query-strings";
|
||||||
import { getDeviceIdValue } from "@/helpers/heritage-integration/cookie-helper";
|
import { setCookieProperties, getDeviceIdValue, getSessionIdValue, getSessionKeyValue } from "@/helpers/heritage-integration/cookie-helper";
|
||||||
|
import { cookieNames } from "@/constants/cookie-names";
|
||||||
|
|
||||||
// Heritage integration
|
// Heritage integration
|
||||||
import { isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper";
|
import { isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper";
|
||||||
|
|
@ -46,6 +47,10 @@ const routes = [
|
||||||
async beforeEnter(to, from, next) {
|
async beforeEnter(to, from, next) {
|
||||||
// If we have no query string, or we don't have the FmgPage query string.
|
// If we have no query string, or we don't have the FmgPage query string.
|
||||||
try {
|
try {
|
||||||
|
if (noSession()) {
|
||||||
|
await initSession();
|
||||||
|
}
|
||||||
|
|
||||||
// If the saved session has timed out, clear the session, execute 404 logic.
|
// If the saved session has timed out, clear the session, execute 404 logic.
|
||||||
if (getFunnelCookie() !== null && !isSavedSessionStillActive()) {
|
if (getFunnelCookie() !== null && !isSavedSessionStillActive()) {
|
||||||
await GoToFunnelStartOn404(next);
|
await GoToFunnelStartOn404(next);
|
||||||
|
|
@ -244,6 +249,41 @@ async function GetRouteInfoFromPageName(pageName) {
|
||||||
return routeData;
|
return routeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function initSession() {
|
||||||
|
const sid = getSessionIdValue();
|
||||||
|
const skey = getSessionKeyValue();
|
||||||
|
var payload = {
|
||||||
|
userId: getDeviceIdValue(),
|
||||||
|
sessionId: sid,
|
||||||
|
userAgent: navigator.userAgent,
|
||||||
|
referrer: document.referrer,
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await baseMixin.methods.dispatchStoreAction(storeActions.INITIALIZE_SESSION, payload, false);
|
||||||
|
|
||||||
|
if (response.data) {
|
||||||
|
if (response.data.sessionKey && skey === 0) {
|
||||||
|
setCookieProperties({ [cookieNames.SESSION_KEY]: response.data.sessionKey});
|
||||||
|
}
|
||||||
|
if (response.data.sessionId && sid === '00000000-0000-0000-0000-000000000000') {
|
||||||
|
setCookieProperties({ [cookieNames.SESSION_ID]: response.data.sessionId});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log("router:" + getSessionKeyValue());
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function noSession() {
|
||||||
|
if (getSessionKeyValue() === 0 || getSessionIdValue() === '00000000-0000-0000-0000-000000000000') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Go to our start page on a 404.
|
// Go to our start page on a 404.
|
||||||
async function GoToFunnelStartOn404(next) {
|
async function GoToFunnelStartOn404(next) {
|
||||||
const apiResponse = await store.dispatch(storeActions.GET_HOMEPAGE_NAME);
|
const apiResponse = await store.dispatch(storeActions.GET_HOMEPAGE_NAME);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue