Merge pull request #522 from Safelite/feature/CSR-663
CSR-663 changes to make sure funnel has skey(session log seq num)
This commit is contained in:
commit
a7f8c3296f
7 changed files with 118 additions and 19 deletions
|
|
@ -79,6 +79,10 @@ const endpoints = {
|
||||||
url: "/analytics/api/v1/analytics/log-custom-event",
|
url: "/analytics/api/v1/analytics/log-custom-event",
|
||||||
method: "POST",
|
method: "POST",
|
||||||
},
|
},
|
||||||
|
InitializeSession:{
|
||||||
|
url: "/analytics/api/v1/analytics/initialize",
|
||||||
|
method: "POST",
|
||||||
|
},
|
||||||
GetExperimentsByUser: {
|
GetExperimentsByUser: {
|
||||||
url: "/analytics/api/v1/analytics/get-experiments",
|
url: "/analytics/api/v1/analytics/get-experiments",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ const storeActions = {
|
||||||
LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure",
|
LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure",
|
||||||
LOG_PAGE_VIEW: "logPageView",
|
LOG_PAGE_VIEW: "logPageView",
|
||||||
LOG_CUSTOM_EVENT: "logCustomEvent",
|
LOG_CUSTOM_EVENT: "logCustomEvent",
|
||||||
|
INITIALIZE_SESSION: "initializeSession",
|
||||||
GET_EXPERIMENTS_BY_USER: "GetExperimentsByUser",
|
GET_EXPERIMENTS_BY_USER: "GetExperimentsByUser",
|
||||||
UPDATE_SERVICE_LOCATION_WITH_VEHICLE_REGISTRATION: "updateServiceLocationWithVehicleRegistration",
|
UPDATE_SERVICE_LOCATION_WITH_VEHICLE_REGISTRATION: "updateServiceLocationWithVehicleRegistration",
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,14 @@ export function getSessionIdValue(){
|
||||||
return '00000000-0000-0000-0000-000000000000';
|
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 =
|
= PRIVATE FUNCTIONS =
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,17 @@
|
||||||
import { storeActions } from "@/constants/store-actions";
|
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 { 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 the user does not have a session id from the content site, do not log.
|
if (getSessionKeyValue() === 0 || getSessionIdValue() === '00000000-0000-0000-0000-000000000000') {
|
||||||
const sid = getSessionIdValue();
|
this.initSession();
|
||||||
if (sid === '00000000-0000-0000-0000-000000000000' || sid == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentPageName = getPageNameByQueryString();
|
const currentPageName = getPageNameByQueryString();
|
||||||
|
|
@ -20,38 +19,59 @@ export default {
|
||||||
userId: getDeviceIdValue(),
|
userId: getDeviceIdValue(),
|
||||||
sessionKey: getSessionKeyValue(),
|
sessionKey: getSessionKeyValue(),
|
||||||
pageName: currentPageName,
|
pageName: currentPageName,
|
||||||
sessionId: sid,
|
sessionId: getSessionIdValue(),
|
||||||
action: '',
|
action: '',
|
||||||
event: pageEvent,
|
event: pageEvent,
|
||||||
shouldUseSessionId: true,
|
shouldUseSessionId: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_PAGE_VIEW, payload, false);
|
baseMixin.methods.dispatchStoreAction(storeActions.LOG_PAGE_VIEW, payload, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
logCustomEvent(category, action, label, value) {
|
logCustomEvent(category, action, label, value) {
|
||||||
// if the user does not have a session id from the content site, do not log.
|
if (getSessionKeyValue() === 0 || getSessionIdValue() === '00000000-0000-0000-0000-000000000000') {
|
||||||
const sid = getSessionIdValue();
|
this.initSession();
|
||||||
if (sid === '00000000-0000-0000-0000-000000000000' || sid == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentPageName = getPageNameByQueryString();
|
const currentPageName = getPageNameByQueryString();
|
||||||
|
|
||||||
var payload = {
|
var payload = {
|
||||||
userId: getDeviceIdValue(),
|
userId: getDeviceIdValue(),
|
||||||
sessionKey: getSessionKeyValue(),
|
sessionKey: getSessionKeyValue(),
|
||||||
pageName: currentPageName,
|
pageName: currentPageName,
|
||||||
sessionId: sid,
|
sessionId: getSessionIdValue(),
|
||||||
category: category,
|
category: category,
|
||||||
action: action,
|
action: action,
|
||||||
label: label,
|
label: label,
|
||||||
value: value,
|
value: value,
|
||||||
shouldUseSessionId: true,
|
shouldUseSessionId: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
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 = {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import analyticsMixin from "@/mixins/analytics-mixin";
|
import analyticsMixin from "@/mixins/analytics-mixin";
|
||||||
import { setupMocksForJsFiles, setupCookies } from "@/helpers/unit-test-helper.js";
|
import { setupMocksForJsFiles, setupCookies } from "@/helpers/unit-test-helper.js";
|
||||||
import { storeActions } from "@/constants/store-actions";
|
import { storeActions } from "@/constants/store-actions";
|
||||||
|
import { analyticsPageEvents, GaCategories, GaActions, GaLabels, GaEvents } from "@/constants/analytics";
|
||||||
|
|
||||||
describe("analyticsMixin.js", () => {
|
describe("analyticsMixin.js", () => {
|
||||||
test("logPageView: calls dispatch with type and payload", () => {
|
test("logPageView: calls dispatch with type and payload", () => {
|
||||||
|
|
@ -26,9 +27,6 @@ describe("analyticsMixin.js", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test("logCustomEvent: calls dispatch with type and payload", () => {
|
test("logCustomEvent: calls dispatch with type and payload", () => {
|
||||||
const type = "";
|
|
||||||
const payload = {};
|
|
||||||
|
|
||||||
const mockData = {
|
const mockData = {
|
||||||
actionList: [{
|
actionList: [{
|
||||||
actionName: storeActions.LOG_CUSTOM_EVENT
|
actionName: storeActions.LOG_CUSTOM_EVENT
|
||||||
|
|
@ -36,7 +34,7 @@ describe("analyticsMixin.js", () => {
|
||||||
}
|
}
|
||||||
const mocks = setupMocksForJsFiles(mockData);
|
const mocks = setupMocksForJsFiles(mockData);
|
||||||
|
|
||||||
analyticsMixin.methods.logCustomEvent(type, payload);
|
analyticsMixin.methods.logCustomEvent("someCat", "someAction", "someLabel", "someVal");
|
||||||
|
|
||||||
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
@ -126,4 +124,37 @@ describe("analyticsMixin.js", () => {
|
||||||
//Assert
|
//Assert
|
||||||
expect(obj!=null);
|
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 }){
|
GetExperimentsByUser(context, { userId }){
|
||||||
return globalMethods.callHttpClient({
|
return globalMethods.callHttpClient({
|
||||||
method: endpoints.GetExperimentsByUser.method,
|
method: endpoints.GetExperimentsByUser.method,
|
||||||
|
|
|
||||||
|
|
@ -642,7 +642,7 @@ describe("Actions", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assert
|
// 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({});
|
expect(response).toEqual({});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -663,7 +663,22 @@ describe("Actions", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assert
|
// 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({});
|
expect(response).toEqual({});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue