Skip to content
This repository was archived by the owner on Feb 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/botPage/view/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
getToken,
} from '../../common/utils/storageManager';
import { isProduction } from '../../common/utils/tools';
import GTM from '../../common/gtm';

let realityCheckTimeout;

Expand Down Expand Up @@ -352,6 +353,7 @@ export default class View {
this.stop();
Elevio.logoutUser();
googleDrive.signOut();
GTM.setVisitorId();
removeTokens();
})
.catch(() => {});
Expand Down Expand Up @@ -569,6 +571,7 @@ export default class View {
.then(() => {
this.stop();
Elevio.logoutUser();
GTM.setVisitorId();
const activeToken = $(e.currentTarget).attr('value');
const tokenList = getTokenList();
setStorage('tokenList', '');
Expand Down
2 changes: 2 additions & 0 deletions src/botPage/view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'notifyjs-browser';
import View from './View';
import '../../common/binary-ui/dropdown';
import Elevio from '../../common/elevio';
import GTM from '../../common/gtm';

$.ajaxSetup({
cache: false,
Expand All @@ -29,6 +30,7 @@ view.initPromise.then(() => {
$('.barspinner').hide();
window.dispatchEvent(new Event('resize'));
Elevio.init();
GTM.setVisitorId();
trackJs.configure({
userId: $('.account-id')
.first()
Expand Down
2 changes: 2 additions & 0 deletions src/common/appId.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { parseQueryString, isProduction, getExtension } from '../common/utils/to
import { getLanguage } from './lang';
import AppIdMap from './appIdResolver';
import Elevio from './elevio';
import GTM from './gtm';

export const AppConstants = Object.freeze({
STORAGE_ACTIVE_TOKEN: 'activeToken',
Expand Down Expand Up @@ -133,6 +134,7 @@ export async function addTokenIfValid(token, tokenObjectList) {
} catch (e) {
removeToken(tokenObjectList[0].token);
Elevio.logoutUser();
GTM.setVisitorId();
throw e;
}
return api.disconnect();
Expand Down
31 changes: 31 additions & 0 deletions src/common/gtm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { getAppIdFallback } from './appId';
import AppIdMap from './appIdResolver';
import { getTokenList } from './utils/storageManager';

const GTM = (() => {
const isGtmApplicable = () => Object.values(AppIdMap).includes(`${getAppIdFallback()}`);

const pushDataLayer = data => {
if (isGtmApplicable()) {
// eslint-disable-next-line no-undef
dataLayer.push({
...data,
});
}
};

const setVisitorId = () => {
const tokenList = getTokenList();
if (tokenList.length > 0) {
pushDataLayer({ visitorId: tokenList[0].loginInfo.loginid });
} else {
pushDataLayer({ visitorId: undefined });
}
};

return {
setVisitorId,
};
})();

export default GTM;