CASH-609 - Add dataevents for Sierra/Salesforce chat
This commit is contained in:
parent
5e36d4cc99
commit
f35a2f2cdf
7 changed files with 65 additions and 16 deletions
|
|
@ -9,9 +9,11 @@ import { initializeSalesforceWebchatForQa } from "./salesforce-helper-qa";
|
||||||
import { initializeSalesforceWebchatForProd } from "./salesforce-helper-prod";
|
import { initializeSalesforceWebchatForProd } from "./salesforce-helper-prod";
|
||||||
import { applicationConfig } from "@/constants/application-config";
|
import { applicationConfig } from "@/constants/application-config";
|
||||||
import { webchatHelper } from "@/helpers/webchat-helper";
|
import { webchatHelper } from "@/helpers/webchat-helper";
|
||||||
|
import analyticsMixin from "@/mixins/analytics-mixin";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "salesforceWebchat",
|
name: "salesforceWebchat",
|
||||||
|
mixins: [analyticsMixin],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isAgentAvailable: false,
|
isAgentAvailable: false,
|
||||||
|
|
@ -94,6 +96,9 @@ export default {
|
||||||
window.embedded_svc.settings.prechatBackgroundImgURL = require("@/assets/img/salesforce-webchat/safelite_logo_webchat.png");
|
window.embedded_svc.settings.prechatBackgroundImgURL = require("@/assets/img/salesforce-webchat/safelite_logo_webchat.png");
|
||||||
window.embedded_svc.settings.smallCompanyLogoImgURL = require("@/assets/img/salesforce-webchat/minimized_chat_bubble_webchat.png");
|
window.embedded_svc.settings.smallCompanyLogoImgURL = require("@/assets/img/salesforce-webchat/minimized_chat_bubble_webchat.png");
|
||||||
window.embedded_svc.settings.displayHelpButton = false;
|
window.embedded_svc.settings.displayHelpButton = false;
|
||||||
|
window.embedded_svc.addEventHandler("onChatEstablished", () => {
|
||||||
|
this.pushEventForChatsToGA("support_chat", "chat_opened", "Live Agent", true);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
finishedLoadingCallback(data) {
|
finishedLoadingCallback(data) {
|
||||||
this.isAgentAvailable = data.isAgentAvailable;
|
this.isAgentAvailable = data.isAgentAvailable;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,28 @@
|
||||||
import { shallowMount } from "@vue/test-utils";
|
import { shallowMount } from "@vue/test-utils";
|
||||||
import SierraWebchat from "./sierra-webchat.vue";
|
import sierraWebchat from "./sierra-webchat.vue";
|
||||||
|
|
||||||
|
jest.mock("@/mixins/analytics-mixin");
|
||||||
|
// Mock router for analytics-mixin
|
||||||
|
jest.mock("@/router", () => ({
|
||||||
|
currentRoute: {
|
||||||
|
value: {
|
||||||
|
name: "mockedPageName",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: {
|
||||||
|
currentRoute: {
|
||||||
|
value: {
|
||||||
|
name: "mockedPageName",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
describe("sierraWebchat.vue", () => {
|
describe("sierraWebchat.vue", () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
wrapper = shallowMount(SierraWebchat);
|
wrapper = shallowMount(sierraWebchat);
|
||||||
// Mock global window properties
|
// Mock global window properties
|
||||||
window.sierraChat = { openChatModal: jest.fn(), closeChatModal: jest.fn() };
|
window.sierraChat = { openChatModal: jest.fn(), closeChatModal: jest.fn() };
|
||||||
window.sierra = undefined;
|
window.sierra = undefined;
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import analyticsMixin from "@/mixins/analytics-mixin";
|
||||||
export default {
|
export default {
|
||||||
name: "sierraWebchat",
|
name: "sierraWebchat",
|
||||||
|
mixins: [analyticsMixin],
|
||||||
methods: {
|
methods: {
|
||||||
openSierraChatModal() {
|
openSierraChatModal() {
|
||||||
const sierra = window.sierraChat || window.sierra || window.SierraChat;
|
const sierra = window.sierraChat || window.sierra || window.SierraChat;
|
||||||
|
|
@ -18,6 +20,7 @@ export default {
|
||||||
launchLink.click();
|
launchLink.click();
|
||||||
document.body.removeChild(launchLink);
|
document.body.removeChild(launchLink);
|
||||||
}
|
}
|
||||||
|
this.pushEventForChatsToGA("support_chat", "chat_opened", "Scarlett", true);
|
||||||
},
|
},
|
||||||
createSierraConfig() {
|
createSierraConfig() {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import { getFunnelCookie } from "@/helpers/heritage-integration/cookie-helper";
|
||||||
import { routeData } from "@/router/constants/routes";
|
import { routeData } from "@/router/constants/routes";
|
||||||
import { getQuerystringParameter } from "@/helpers/querystring-helper";
|
import { getQuerystringParameter } from "@/helpers/querystring-helper";
|
||||||
import { Variables } from "../constants/analytics";
|
import { Variables } from "../constants/analytics";
|
||||||
|
import router from "@/router";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
|
|
@ -100,7 +101,14 @@ export default {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
async pushEventToGA(category, action, label, pushToLogApp = false, valueToLogType = null) {
|
async pushEventToGA(
|
||||||
|
category,
|
||||||
|
action,
|
||||||
|
label,
|
||||||
|
pushToLogApp = false,
|
||||||
|
valueToLogType = null,
|
||||||
|
value = null
|
||||||
|
) {
|
||||||
const currentPageName = getPageNameByQueryString();
|
const currentPageName = getPageNameByQueryString();
|
||||||
const labelToLog = getValueToLog(label, valueToLogType);
|
const labelToLog = getValueToLog(label, valueToLogType);
|
||||||
|
|
||||||
|
|
@ -109,8 +117,8 @@ export default {
|
||||||
category: category,
|
category: category,
|
||||||
action: action,
|
action: action,
|
||||||
label: labelToLog,
|
label: labelToLog,
|
||||||
value: undefined,
|
value: value ?? undefined,
|
||||||
path: `/fmg/?${queryStrings.FMG_PAGE}=${currentPageName}`,
|
path: `/fmg/${currentPageName}`,
|
||||||
};
|
};
|
||||||
|
|
||||||
pushToDataLayerIfDefined(eventToBePushed);
|
pushToDataLayerIfDefined(eventToBePushed);
|
||||||
|
|
@ -120,6 +128,12 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async pushEventForChatsToGA(category, action, label, pushToLogApp = false) {
|
||||||
|
const currentPageName = getPageNameByQueryString();
|
||||||
|
const value = `2.0_${currentPageName}`;
|
||||||
|
await this.pushEventToGA(category, action, label, pushToLogApp, null, value);
|
||||||
|
},
|
||||||
|
|
||||||
async pushVariableToDataLayer(data) {
|
async pushVariableToDataLayer(data) {
|
||||||
pushToDataLayerIfDefined(data);
|
pushToDataLayerIfDefined(data);
|
||||||
},
|
},
|
||||||
|
|
@ -128,7 +142,7 @@ export default {
|
||||||
const currentPageName = getPageNameByQueryString();
|
const currentPageName = getPageNameByQueryString();
|
||||||
const pageViewEvent = {
|
const pageViewEvent = {
|
||||||
event: GaEvents.PAGE_VIEW_EVENT,
|
event: GaEvents.PAGE_VIEW_EVENT,
|
||||||
pagePath: `/fmg/?${queryStrings.FMG_PAGE}=${currentPageName}`,
|
pagePath: `/fmg/${currentPageName}`,
|
||||||
pageTitle: currentPageName,
|
pageTitle: currentPageName,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -791,12 +805,13 @@ function pushToDataLayerIfDefined(data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPageNameByQueryString() {
|
function getPageNameByQueryString() {
|
||||||
const params = new URLSearchParams(location.search);
|
if (
|
||||||
|
router &&
|
||||||
if (params.has(queryStrings.FMG_PAGE)) {
|
router.currentRoute &&
|
||||||
return params.get(queryStrings.FMG_PAGE);
|
router.currentRoute.value &&
|
||||||
} else {
|
router.currentRoute.value.name
|
||||||
return "";
|
) {
|
||||||
|
return router.currentRoute.value.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ describe("analyticsMixin.js", () => {
|
||||||
action: "action",
|
action: "action",
|
||||||
label: "label",
|
label: "label",
|
||||||
value: undefined,
|
value: undefined,
|
||||||
path: "/fmg/?fmgPage=",
|
path: "/fmg/mockedPageName",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -172,7 +172,7 @@ describe("analyticsMixin.js", () => {
|
||||||
action: "action",
|
action: "action",
|
||||||
label: "33333",
|
label: "33333",
|
||||||
value: undefined,
|
value: undefined,
|
||||||
path: "/fmg/?fmgPage=",
|
path: "/fmg/mockedPageName",
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockData = {
|
const mockData = {
|
||||||
|
|
@ -211,7 +211,7 @@ describe("analyticsMixin.js", () => {
|
||||||
action: "action",
|
action: "action",
|
||||||
label: "111",
|
label: "111",
|
||||||
value: undefined,
|
value: undefined,
|
||||||
path: "/fmg/?fmgPage=",
|
path: "/fmg/mockedPageName",
|
||||||
});
|
});
|
||||||
|
|
||||||
const mockData = {
|
const mockData = {
|
||||||
|
|
@ -1048,3 +1048,11 @@ describe("analyticsMixin.js", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
jest.mock("@/router", () => ({
|
||||||
|
currentRoute: {
|
||||||
|
value: {
|
||||||
|
name: "mockedPageName",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
|
||||||
|
|
@ -1499,7 +1499,7 @@ export const actions = {
|
||||||
parentAccountNumber,
|
parentAccountNumber,
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
if (!pageName) {
|
if (!pageName || !category) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -930,6 +930,7 @@ describe("Actions", () => {
|
||||||
pageName: "pageName",
|
pageName: "pageName",
|
||||||
sessionId: "sessionId",
|
sessionId: "sessionId",
|
||||||
customEvent: customEvent,
|
customEvent: customEvent,
|
||||||
|
category: "category",
|
||||||
shouldUseSessionId: false,
|
shouldUseSessionId: false,
|
||||||
});
|
});
|
||||||
expect(response).toEqual({});
|
expect(response).toEqual({});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue