CSR-18 activity log split into lagpageview and logcustomevent
This commit is contained in:
parent
9060c3b2d0
commit
341cc02d7d
6 changed files with 93 additions and 28 deletions
|
|
@ -75,6 +75,14 @@ const endpoints = {
|
|||
url: "/analytics/api/v1/analytics/activity",
|
||||
method: "POST",
|
||||
},
|
||||
LogPageView:{
|
||||
url: "/analytics/api/v1/analytics/log-page-view",
|
||||
method: "POST",
|
||||
},
|
||||
LogCustomEvent:{
|
||||
url: "/analytics/api/v1/analytics/log-custom-event",
|
||||
method: "POST",
|
||||
},
|
||||
GetExperimentsByUserForGa: {
|
||||
url: "/analytics/api/v1/analytics/get-experiments-for-GA",
|
||||
method: "GET",
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ const storeActions = {
|
|||
SET_REFERRAL_INFORMATION: "setReferralInformation",
|
||||
VALIDATE_ZIP: "validateZip",
|
||||
LOG_EXPERIMENT_EXPOSURE: "logExperimentExposure",
|
||||
LOG_ACTIVITY: "logActivity",
|
||||
LOG_PAGE_VIEW: "logPageView",
|
||||
LOG_CUSTOM_EVENT: "logCustomEvent",
|
||||
GET_EXPERIMENTS_BY_USER_FOR_GA: "getExperimentsByUserForGa",
|
||||
|
||||
// DEPENDENCY MUTATIONS
|
||||
|
|
|
|||
|
|
@ -11,24 +11,34 @@ const currentPageName = getPageNameByQueryString();
|
|||
|
||||
export default {
|
||||
methods: {
|
||||
logEvent(pageEvent, category, action, label, value) {
|
||||
logPageView(pageEvent) {
|
||||
var payload = {
|
||||
userId: getDeviceIdValue(),
|
||||
sessionKey: getSessionKeyValue(),
|
||||
pageName: currentPageName,
|
||||
sessionId: getSessionIdValue(),
|
||||
action: '',
|
||||
event: pageEvent,
|
||||
shouldUseSessionId: true,
|
||||
};
|
||||
|
||||
if (pageEvent) {
|
||||
payload.pageEvent = { action: '', event: pageEvent };
|
||||
}
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_PAGE_VIEW, payload, false);
|
||||
},
|
||||
|
||||
if (category) {
|
||||
payload.customEvent = { category: category, action: action, label: label, value: value };
|
||||
}
|
||||
logCustomEvent(category, action, label, value) {
|
||||
var payload = {
|
||||
userId: getDeviceIdValue(),
|
||||
sessionKey: getSessionKeyValue(),
|
||||
pageName: currentPageName,
|
||||
sessionId: getSessionIdValue(),
|
||||
category: category,
|
||||
action: action,
|
||||
label: label,
|
||||
value: value,
|
||||
shouldUseSessionId: true,
|
||||
};
|
||||
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_ACTIVITY, payload, false);
|
||||
baseMixin.methods.dispatchStoreAction(storeActions.LOG_CUSTOM_EVENT, payload, false);
|
||||
},
|
||||
|
||||
pushEventToGA(category, action, label, pushToLogApp = false) {
|
||||
|
|
@ -44,7 +54,7 @@ export default {
|
|||
pushToDataLayerIfDefined(eventToBePushed);
|
||||
|
||||
if (pushToLogApp) {
|
||||
this.logEvent(undefined, category, action, label, undefined);
|
||||
this.logCustomEvent(category, action, label, undefined);
|
||||
}
|
||||
|
||||
},
|
||||
|
|
@ -58,7 +68,7 @@ export default {
|
|||
|
||||
pushToDataLayerIfDefined(pageViewEvent);
|
||||
|
||||
this.logEvent(currentPageName, analyticsPageEvents.ENTRY);
|
||||
this.logPageView(analyticsPageEvents.ENTRY);
|
||||
},
|
||||
|
||||
pushExperimentsToDataLayer(experiments) {
|
||||
|
|
|
|||
|
|
@ -3,18 +3,34 @@ import { setupMocksForJsFiles } from "@/helpers/unit-test-helper.js";
|
|||
import { storeActions } from "@/constants/store-actions";
|
||||
|
||||
describe("analyticsMixin.js", () => {
|
||||
test("logEvent: calls dispatch with type and payload", () => {
|
||||
test("logPageView: calls dispatch with type and payload", () => {
|
||||
const type = "";
|
||||
const payload = {};
|
||||
|
||||
const mockData = {
|
||||
actionList: [{
|
||||
actionName: storeActions.LOG_ACTIVITY
|
||||
actionName: storeActions.LOG_PAGE_VIEW
|
||||
}],
|
||||
}
|
||||
const mocks = setupMocksForJsFiles(mockData);
|
||||
|
||||
analyticsMixin.methods.logEvent(type, payload);
|
||||
analyticsMixin.methods.logPageView(type, payload);
|
||||
|
||||
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
||||
});
|
||||
|
||||
test("logCustomEvent: calls dispatch with type and payload", () => {
|
||||
const type = "";
|
||||
const payload = {};
|
||||
|
||||
const mockData = {
|
||||
actionList: [{
|
||||
actionName: storeActions.LOG_CUSTOM_EVENT
|
||||
}],
|
||||
}
|
||||
const mocks = setupMocksForJsFiles(mockData);
|
||||
|
||||
analyticsMixin.methods.logCustomEvent(type, payload);
|
||||
|
||||
expect(mocks.baseMixin.methods.dispatchStoreAction).toBeCalled();
|
||||
});
|
||||
|
|
@ -23,7 +39,7 @@ describe("analyticsMixin.js", () => {
|
|||
// Arrange
|
||||
const mockData = {
|
||||
actionList: [{
|
||||
actionName: storeActions.LOG_ACTIVITY
|
||||
actionName: storeActions.LOG_CUSTOM_EVENT
|
||||
}],
|
||||
}
|
||||
const mocks = setupMocksForJsFiles(mockData);
|
||||
|
|
|
|||
|
|
@ -433,27 +433,43 @@ export const actions = {
|
|||
});
|
||||
},
|
||||
|
||||
logActivity(context, { userId, sessionKey, pageName, sessionId, pageEvent, customEvent, shouldUseSessionId }) {
|
||||
logPageView(context, { userId, sessionKey, pageName, sessionId, action, event, shouldUseSessionId }) {
|
||||
var payload = {
|
||||
userId: userId,
|
||||
sessionKey: sessionKey,
|
||||
sessionId: sessionId,
|
||||
pageName: pageName,
|
||||
applicationName: 'SafeliteDotCom',
|
||||
action: action,
|
||||
event: event,
|
||||
shouldUseSessionId: shouldUseSessionId
|
||||
};
|
||||
|
||||
if (typeof pageEvent !== 'undefined') {
|
||||
payload.pageEvent = { action: pageEvent.action, event: pageEvent.event};
|
||||
}
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.LogPageView.method,
|
||||
endpoint: endpoints.LogPageView.url,
|
||||
payload: payload,
|
||||
logApiCall: false
|
||||
});
|
||||
},
|
||||
|
||||
if (typeof customEvent !== 'undefined') {
|
||||
payload.customEvents = [{category: customEvent.category, action: customEvent.action, label: customEvent.label, value: customEvent.value}];
|
||||
}
|
||||
logCustomEvent(context, { userId, sessionKey, pageName, sessionId, category, action, label, value, shouldUseSessionId }) {
|
||||
var payload = {
|
||||
userId: userId,
|
||||
sessionKey: sessionKey,
|
||||
sessionId: sessionId,
|
||||
pageName: pageName,
|
||||
applicationName: 'SafeliteDotCom',
|
||||
category: category,
|
||||
action: action,
|
||||
label: label,
|
||||
value: value,
|
||||
shouldUseSessionId: shouldUseSessionId
|
||||
};
|
||||
|
||||
return globalMethods.callHttpClient({
|
||||
method: endpoints.LogActivity.method,
|
||||
endpoint: endpoints.LogActivity.url,
|
||||
method: endpoints.LogCustomEvent.method,
|
||||
endpoint: endpoints.LogCustomEvent.url,
|
||||
payload: payload,
|
||||
logApiCall: false
|
||||
});
|
||||
|
|
|
|||
|
|
@ -617,7 +617,7 @@ describe("Actions", () => {
|
|||
expect(commit).toBeCalledWith(storeMutations.UPDATE_REFERRAL_CORRELATION_ID, "xxx-xxx-xxx");
|
||||
});
|
||||
|
||||
it("logActivity action, should return nothing", async () => {
|
||||
it("logPageView action, should return nothing", async () => {
|
||||
|
||||
// Arrange
|
||||
const context = state;
|
||||
|
|
@ -626,12 +626,26 @@ describe("Actions", () => {
|
|||
event: "ENTRY",
|
||||
}
|
||||
|
||||
var customEvent = [{
|
||||
// Act
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
return Promise.resolve({ });
|
||||
});
|
||||
|
||||
// Assert
|
||||
const response = await actions.logPageView(context, { userId: "userId", sessionKey: "sessionKey", pageName: "pageName", sessionId: "sessionId", pageEvent: pageEvent, shouldUseSessionId: true });
|
||||
expect(response).toEqual({});
|
||||
});
|
||||
|
||||
it("logCustomEvent action, should return nothing", async () => {
|
||||
|
||||
// Arrange
|
||||
const context = state;
|
||||
var customEvent = {
|
||||
category: "tstCat",
|
||||
action: "click",
|
||||
label: "damage",
|
||||
value: "psych"
|
||||
}];
|
||||
};
|
||||
|
||||
// Act
|
||||
globalMethods.callHttpClient.mockImplementation(() => {
|
||||
|
|
@ -639,7 +653,7 @@ describe("Actions", () => {
|
|||
});
|
||||
|
||||
// Assert
|
||||
const response = await actions.logActivity(context, { userId: "userId", sessionKey: "sessionKey", pageName: "pageName", sessionId: "sessionId", pageEvent: pageEvent, customEvent: customEvent, shouldUseSessionId: true });
|
||||
const response = await actions.logCustomEvent(context, { userId: "userId", sessionKey: "sessionKey", pageName: "pageName", sessionId: "sessionId", customEvent: customEvent, shouldUseSessionId: true });
|
||||
expect(response).toEqual({});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue