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 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the client switched the account from the dropdown?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the client switched the account from the dropdown?

The token list in local storage reflects the same order as can be seen in the dropdown, so the 0 index will always be the account that's active. The setVisitorId function is called on both account switch & logout, so it would pass the correct visitorId to the data layer.

} else {
pushDataLayer({ visitorId: undefined });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if pushing undefined is necessary

Copy link
Contributor Author

@aaimio aaimio Apr 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user logs out and visitorId isn't set to undefined, it would still register clicks as the most previous logged in user.

}
};

return {
setVisitorId,
};
})();

export default GTM;