CSR-663 changes to make sure funnel as skey(session log seq num)
This commit is contained in:
parent
a49975adc1
commit
4be843e1b8
7 changed files with 118 additions and 19 deletions
|
|
@ -79,6 +79,10 @@ const endpoints = {
|
|||
url: "/analytics/api/v1/analytics/log-custom-event",
|
||||
method: "POST",
|
||||
},
|
||||
InitializeSession:{
|
||||
url: "/analytics/api/v1/analytics/initialize",
|
||||
method: "POST",
|
||||
},
|
||||
GetExperimentsByUser: {
|
||||
url: "/analytics/api/v1/analytics/get-experiments",
|
||||
method: "GET",
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ const storeActions = {
|
|||
LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure",
|
||||
LOG_PAGE_VIEW: "logPageView",
|
||||
LOG_CUSTOM_EVENT: "logCustomEvent",
|
||||
INITIALIZE_SESSION: "initializeSession",
|
||||
GET_EXPERIMENTS_BY_USER: "GetExperimentsByUser",
|
||||
UPDATE_SERVICE_LOCATION_WITH_VEHICLE_REGISTRATION: "updateServiceLocationWithVehicleRegistration",
|
||||
|
||||
|
|
|
|||
|
|
@ -104,6 +104,14 @@ export function getSessionIdValue(){
|
|||
return '00000000-0000-0000-0000-000000000000';
|
||||
}
|
||||
|
||||
export function setCookieProperties(properties) {
|
||||
if (typeof properties == "object") {
|
||||
Object.keys(properties).forEach(key => {
|
||||
document.cookie = `${key}=${properties[key]}`;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
===========================
|
||||
= PRIVATE FUNCTIONS =
|
||||
|
|
|
|||
|
|
@ -1,18 +1,17 @@
|
|||
import { storeActions } from "@/constants/store-actions";
|
||||
import { getDeviceIdValue, getSessionIdValue, getSessionKeyValue } from "@/helpers/heritage-integration/cookie-helper";
|
||||
import { setCookieProperties, getDeviceIdValue, getSessionIdValue, getSessionKeyValue } from "@/helpers/heritage-integration/cookie-helper";
|
||||
import { queryStrings } from "@/constants/query-strings";
|
||||
import { experimentSettings } from "@/constants/experiments";
|
||||
import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents } from "@/constants/analytics";
|
||||
import { cookieNames } from "@/constants/cookie-names";
|
||||
|
||||
import baseMixin from "@/mixins/base-mixin";
|
||||
|
||||
export default {
|
||||
methods: {
|
||||
logPageView(pageEvent) {
|
||||
// if the user does not have a session id from the content site, do not log.
|
||||
const sid = getSessionIdValue();
|
||||
if (sid === '00000000-0000-0000-0000-000000000000' || sid == null) {
|
||||
return;
|
||||
if (getSessionKeyValue() === 0 || getSessionIdValue() === '00000000-0000-0000-0000-000000000000') {
|
||||
this.initSession();
|
||||
}
|
||||
|
||||
const currentPageName = getPageNameByQueryString();
|
||||
|
|
@ -20,38 +19,59 @@ export default {
|
|||
userId: getDeviceIdValue(),
|
||||
sessionKey: getSessionKeyValue(),
|
||||
pageName: currentPageName,
|
||||
sessionId: sid,
|
||||
sessionId: getSessionIdValue(),
|
||||
action: '',
|
||||
event: pageEvent,
|
||||
shouldUseSessionId: true,
|
||||
shouldUseSessionId: false,
|
||||
};
|
||||
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_PAGE_VIEW, payload, false);
|
||||
},
|
||||
|
||||
logCustomEvent(category, action, label, value) {
|
||||
// if the user does not have a session id from the content site, do not log.
|
||||
const sid = getSessionIdValue();
|
||||
if (sid === '00000000-0000-0000-0000-000000000000' || sid == null) {
|
||||
return;
|
||||
if (getSessionKeyValue() === 0 || getSessionIdValue() === '00000000-0000-0000-0000-000000000000') {
|
||||
this.initSession();
|
||||
}
|
||||
|
||||
const currentPageName = getPageNameByQueryString();
|
||||
|
||||
var payload = {
|
||||
userId: getDeviceIdValue(),
|
||||
sessionKey: getSessionKeyValue(),
|
||||
pageName: currentPageName,
|
||||
sessionId: sid,
|
||||
sessionId: getSessionIdValue(),
|
||||
category: category,
|
||||
action: action,
|
||||
label: label,
|
||||
value: value,
|
||||
shouldUseSessionId: true,
|
||||
shouldUseSessionId: 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) {
|
||||
const currentPageName = getPageNameByQueryString();
|
||||
const eventToBePushed = {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import analyticsMixin from "@/mixins/analytics-mixin";
|
||||
import { setupMocksForJsFiles, setupCookies } from "@/helpers/unit-test-helper.js";
|
||||
import { storeActions } from "@/constants/store-actions";
|
||||
import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents } from "@/constants/analytics";
|
||||
|
||||
describe("analyticsMixin.js", () => {
|
||||
test("logPageView: calls dispatch with type and payload", () => {
|
||||
|
|
@ -26,9 +27,6 @@ describe("analyticsMixin.js", () => {
|
|||
});
|
||||
|
||||
test("logCustomEvent: calls dispatch with type and payload", () => {
|
||||
const type = "";
|
||||
const payload = {};
|
||||
|
||||
const mockData = {
|
||||
actionList: [{
|
||||
actionName: storeActions.LOG_CUSTOM_EVENT
|
||||
|
|
@ -36,7 +34,7 @@ describe("analyticsMixin.js", () => {
|
|||
}
|
||||
const mocks = setupMocksForJsFiles(mockData);
|
||||
|
||||
analyticsMixin.methods.logCustomEvent(type, payload);
|
||||
analyticsMixin.methods.logCustomEvent("someCat", "someAction", "someLabel", "someVal");
|
||||
|
||||
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
||||
});
|
||||
|
|
@ -126,4 +124,37 @@ describe("analyticsMixin.js", () => {
|
|||
//Assert
|
||||
expect(obj!=null);
|
||||
});
|
||||
|
||||
test("analyticsPageEvents returns constants analyticsPageEvents", () => {
|
||||
//Act
|
||||
const analyticsPE = analyticsMixin.computed.analyticsPageEvents();
|
||||
|
||||
//Assert
|
||||
expect(analyticsPE).toEqual(analyticsPageEvents);
|
||||
});
|
||||
|
||||
test("GaActions returns constants GaActions", () => {
|
||||
//Act
|
||||
const gaActions = analyticsMixin.computed.GaActions();
|
||||
|
||||
//Assert
|
||||
expect(gaActions).toEqual(GaActions);
|
||||
});
|
||||
|
||||
test("GaCategories returns constants GaCategories", () => {
|
||||
//Act
|
||||
const gaCategories = analyticsMixin.computed.GaCategories();
|
||||
|
||||
//Assert
|
||||
expect(gaCategories).toEqual(GaCategories);
|
||||
});
|
||||
|
||||
test("GaLabels returns constants GaLabels", () => {
|
||||
//Act
|
||||
const gaLabels = analyticsMixin.computed.GaLabels();
|
||||
|
||||
//Assert
|
||||
expect(gaLabels).toEqual(GaLabels);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
@ -509,6 +509,26 @@ export const actions = {
|
|||
});
|
||||
},
|
||||
|
||||
initializeSession(context, { userId, sessionId, userAgent, referrer }) {
|
||||
var payload = {
|
||||
applicationName: 'SafeliteDotCom',
|
||||
userId: userId,
|
||||
deviceId: userId,
|
||||
sessionId: sessionId,
|
||||
userAgent: userAgent,
|
||||
operatorId: "WEB",
|
||||
userName: "SafeliteConceptFunnel",
|
||||
referrer: referrer
|
||||
};
|
||||
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.InitializeSession.method,
|
||||
endpoint: endpoints.InitializeSession.url,
|
||||
payload: payload,
|
||||
logApiCall: false
|
||||
});
|
||||
},
|
||||
|
||||
GetExperimentsByUser(context, { userId }){
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.GetExperimentsByUser.method,
|
||||
|
|
|
|||
|
|
@ -642,7 +642,7 @@ describe("Actions", () => {
|
|||
});
|
||||
|
||||
// Assert
|
||||
const response = await actions.logPageView(context, { userId: "userId", sessionKey: "sessionKey", pageName: "pageName", sessionId: "sessionId", pageEvent: pageEvent, shouldUseSessionId: true });
|
||||
const response = await actions.logPageView(context, { userId: "userId", sessionKey: "sessionKey", pageName: "pageName", sessionId: "sessionId", pageEvent: pageEvent, shouldUseSessionId: false });
|
||||
expect(response).toEqual({});
|
||||
});
|
||||
|
||||
|
|
@ -663,7 +663,22 @@ describe("Actions", () => {
|
|||
});
|
||||
|
||||
// Assert
|
||||
const response = await actions.logCustomEvent(context, { userId: "userId", sessionKey: "sessionKey", pageName: "pageName", sessionId: "sessionId", customEvent: customEvent, shouldUseSessionId: true });
|
||||
const response = await actions.logCustomEvent(context, { userId: "userId", sessionKey: "sessionKey", pageName: "pageName", sessionId: "sessionId", customEvent: customEvent, shouldUseSessionId: false });
|
||||
expect(response).toEqual({});
|
||||
});
|
||||
|
||||
it("initializeSession action, should return nothing", async () => {
|
||||
|
||||
// Arrange
|
||||
const context = state;
|
||||
|
||||
// Act
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({ });
|
||||
});
|
||||
|
||||
// Assert
|
||||
const response = await actions.initializeSession(context, { userId: "userId", sessionId: "", userAgent: "", referrer: "", shouldUseSessionId: false });
|
||||
expect(response).toEqual({});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue