Fix for invalid user seq number
This commit is contained in:
parent
c2137278ad
commit
b6b03e876a
4 changed files with 41 additions and 32 deletions
|
|
@ -7,7 +7,8 @@ import {
|
|||
regenerateUserId,
|
||||
regenerateDeviceId,
|
||||
setSessionIdIfUnset,
|
||||
setSessionKeyIfUnset
|
||||
setSessionKeyIfUnset,
|
||||
updateSessionIdCookie
|
||||
} from '@/helpers/cookie-helper';
|
||||
import applicationConfig from '@/constants/application-config';
|
||||
import queryStrings from '@/constants/query-strings';
|
||||
|
|
@ -52,12 +53,21 @@ export default {
|
|||
}
|
||||
return '';
|
||||
},
|
||||
logPageView(pageEvent) {
|
||||
validateSession() {
|
||||
|
||||
if (this.noSession()) {
|
||||
this.initSession();
|
||||
}
|
||||
|
||||
updateSessionIdCookie();
|
||||
},
|
||||
async logPageView(pageEvent) {
|
||||
const store = useMainStore();
|
||||
const currentPageName = this.getPageNameByQueryString();
|
||||
this.validateSession();
|
||||
|
||||
const payload = {
|
||||
userId: getDeviceIdValue(),
|
||||
userId: getUserIdValue(),
|
||||
sessionKey: getSessionKeyValue(),
|
||||
pageName: currentPageName,
|
||||
referralSequenceNumber: store.order.referralSequenceNumber,
|
||||
|
|
@ -69,15 +79,16 @@ export default {
|
|||
experimentsForUser: store.applicationUser.experiments
|
||||
};
|
||||
|
||||
store.logPageView(payload);
|
||||
await store.logPageView(payload);
|
||||
},
|
||||
|
||||
logCustomEvent(category, action, label, value) {
|
||||
async logCustomEvent(category, action, label, value) {
|
||||
const store = useMainStore();
|
||||
const currentPageName = this.getPageNameByQueryString();
|
||||
this.validateSession();
|
||||
|
||||
const payload = {
|
||||
userId: getDeviceIdValue(),
|
||||
userId: getUserIdValue(),
|
||||
sessionKey: getSessionKeyValue(),
|
||||
pageName: currentPageName,
|
||||
referralSequenceNumber: store.order.referralSequenceNumber,
|
||||
|
|
@ -91,9 +102,9 @@ export default {
|
|||
experimentsForUser: store.applicationUser.experiments
|
||||
};
|
||||
|
||||
store.logCustomEvent(payload);
|
||||
await store.logCustomEvent(payload);
|
||||
},
|
||||
pushEventToGA(category, action, label, pushToLogApp = false, valueToLogType = null, value = undefined) {
|
||||
async pushEventToGA(category, action, label, pushToLogApp = false, valueToLogType = null, value = undefined) {
|
||||
const currentPageName = this.getPageNameByQueryString();
|
||||
const labelToLog = getValueToLog(label, valueToLogType);
|
||||
|
||||
|
|
@ -109,14 +120,14 @@ export default {
|
|||
pushToDataLayerIfDefined(eventToBePushed);
|
||||
|
||||
if (pushToLogApp) {
|
||||
this.logCustomEvent(category, action, labelToLog, value);
|
||||
await this.logCustomEvent(category, action, labelToLog, value);
|
||||
}
|
||||
},
|
||||
pushGenericObjectToGA(object) {
|
||||
pushToDataLayerIfDefined(object);
|
||||
},
|
||||
|
||||
pushPageViewToGA() {
|
||||
async pushPageViewToGA() {
|
||||
const currentPageName = this.getPageNameByQueryString();
|
||||
const pageViewEvent = {
|
||||
event: GaEvents.PAGE_VIEW_EVENT,
|
||||
|
|
@ -126,7 +137,7 @@ export default {
|
|||
|
||||
pushToDataLayerIfDefined(pageViewEvent);
|
||||
|
||||
this.logPageView(analyticsPageEvents.ENTRY);
|
||||
await this.logPageView(analyticsPageEvents.ENTRY);
|
||||
},
|
||||
|
||||
pushOrderToDataLayer() {
|
||||
|
|
@ -532,7 +543,8 @@ export default {
|
|||
store.logIssSessionData(sessionData);
|
||||
},
|
||||
|
||||
async initSession() {
|
||||
initSession() {
|
||||
|
||||
regenerateDeviceId();
|
||||
regenerateUserId();
|
||||
|
||||
|
|
@ -549,7 +561,7 @@ export default {
|
|||
userAgent: navigator.userAgent
|
||||
};
|
||||
|
||||
const response = await useMainStore().initializeSession(payload);
|
||||
const response = useMainStore().initializeSession(payload);
|
||||
|
||||
if (response?.data) {
|
||||
if (response?.data.sessionKey) {
|
||||
|
|
|
|||
|
|
@ -8,29 +8,32 @@ import {
|
|||
ValueToLogTypes
|
||||
} from '@/constants/analytics';
|
||||
import { useMainStore } from '@/store';
|
||||
import crypto from 'crypto';
|
||||
|
||||
global.crypto = crypto;
|
||||
|
||||
describe('analyticsMixin.js', () => {
|
||||
test('logPageView: calls dispatch with type and payload', () => {
|
||||
test('logPageView: calls dispatch with type and payload', async () => {
|
||||
const payload = {};
|
||||
|
||||
const testCookieValue = {
|
||||
sid: '10000000-0000-0000-0000-000000000001'
|
||||
};
|
||||
|
||||
setupCookies({ funnelCookieValue: JSON.stringify(testCookieValue) });
|
||||
setupCookies({ ISSCookieValue: JSON.stringify(testCookieValue) });
|
||||
|
||||
useMainStore().logPageView(payload);
|
||||
await analyticsMixin.methods.logPageView(payload);
|
||||
|
||||
expect(useMainStore().logPageView).toBeCalled();
|
||||
});
|
||||
|
||||
test('logCustomEvent: calls dispatch with type and payload', () => {
|
||||
useMainStore().logCustomEvent('someCat', 'someAction', 'someLabel', 'someVal');
|
||||
test('logCustomEvent: calls dispatch with type and payload', async () => {
|
||||
await analyticsMixin.methods.logCustomEvent('someCat', 'someAction', 'someLabel', 'someVal');
|
||||
|
||||
expect(useMainStore().logCustomEvent).toBeCalled();
|
||||
});
|
||||
|
||||
test('pushEventToGA, should call dataLayer push and logCustomEvent too', () => {
|
||||
test('pushEventToGA, should call dataLayer push and logCustomEvent too', async () => {
|
||||
// Arrange
|
||||
window.dataLayer = [];
|
||||
const mockDataLayer = [];
|
||||
|
|
@ -44,13 +47,13 @@ describe('analyticsMixin.js', () => {
|
|||
});
|
||||
|
||||
// Act
|
||||
analyticsMixin.methods.pushEventToGA('category', 'action', 'label', true);
|
||||
await analyticsMixin.methods.pushEventToGA('category', 'action', 'label', true);
|
||||
|
||||
// Assert
|
||||
expect(mockDataLayer).toEqual(expect.arrayContaining(window.dataLayer));
|
||||
});
|
||||
|
||||
test('pushEventToGA, should call dataLayer push and ValueToLogTypes.LAST_5 only logs last 5 of label', () => {
|
||||
test('pushEventToGA, should call dataLayer push and ValueToLogTypes.LAST_5 only logs last 5 of label', async () => {
|
||||
// Arrange
|
||||
window.dataLayer = [];
|
||||
const expectedDataLayer = [];
|
||||
|
|
@ -64,7 +67,7 @@ describe('analyticsMixin.js', () => {
|
|||
});
|
||||
|
||||
// Act
|
||||
analyticsMixin.methods.pushEventToGA(
|
||||
await analyticsMixin.methods.pushEventToGA(
|
||||
'category',
|
||||
'action',
|
||||
'1111122222333333',
|
||||
|
|
@ -76,7 +79,7 @@ describe('analyticsMixin.js', () => {
|
|||
expect(expectedDataLayer).toEqual(expect.arrayContaining(window.dataLayer));
|
||||
});
|
||||
|
||||
test('pushEventToGA, should call dataLayer push and ValueToLogTypes.LAST_5 logs only the last 3 characters for a 3 character string', () => {
|
||||
test('pushEventToGA, should call dataLayer push and ValueToLogTypes.LAST_5 logs only the last 3 characters for a 3 character string', async () => {
|
||||
// Arrange
|
||||
window.dataLayer = [];
|
||||
const expectedDataLayer = [];
|
||||
|
|
@ -90,7 +93,7 @@ describe('analyticsMixin.js', () => {
|
|||
});
|
||||
|
||||
// Act
|
||||
analyticsMixin.methods.pushEventToGA(
|
||||
await analyticsMixin.methods.pushEventToGA(
|
||||
'category',
|
||||
'action',
|
||||
'111',
|
||||
|
|
|
|||
|
|
@ -37,12 +37,6 @@ const routes = [
|
|||
|
||||
// Do not run these for the main entry page - as it is not part of the user flow.
|
||||
if (issPageToUse !== issPageValues.ENTRY_PAGE) {
|
||||
if (analyticsMixin.methods.noSession()) {
|
||||
await analyticsMixin.methods.initSession();
|
||||
} else {
|
||||
updateSessionIdCookie();
|
||||
}
|
||||
|
||||
try {
|
||||
await runExperiments(issPageToUse);
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -2560,7 +2560,7 @@ export const useMainStore = defineStore({
|
|||
});
|
||||
}
|
||||
},
|
||||
logPageView({ userId, sessionKey, pageName, referralSequenceNumber, parentAccountNumber, sessionId, action, event, shouldUseSessionId, experimentsForUser }) {
|
||||
async logPageView({ userId, sessionKey, pageName, referralSequenceNumber, parentAccountNumber, sessionId, action, event, shouldUseSessionId, experimentsForUser }) {
|
||||
const payload = {
|
||||
userId,
|
||||
sessionKey,
|
||||
|
|
@ -2588,7 +2588,7 @@ export const useMainStore = defineStore({
|
|||
}
|
||||
);
|
||||
},
|
||||
logCustomEvent({ userId, sessionKey, pageName, sessionId, category, action, label, value, shouldUseSessionId, experimentsForUser }) {
|
||||
async logCustomEvent({ userId, sessionKey, pageName, sessionId, category, action, label, value, shouldUseSessionId, experimentsForUser }) {
|
||||
if (pageName == null || pageName.length === 0) { pageName = 'none'; }
|
||||
|
||||
const payload = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue