Skip to content

Commit

Permalink
feat(configuration): add clientSideUserId management (#3317)
Browse files Browse the repository at this point in the history
ref: MANAGER-5459
Signed-off-by: Marie JONES <[email protected]>
  • Loading branch information
marie-j authored and Cyrille Bourgois committed Sep 8, 2020
1 parent 0e36693 commit 7156660
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ export const CUSTOM_VARIABLES = {
siteName: 'Manager',
};

export const USER_ID = 'clientSideUserId';

export default {
CUSTOM_VARIABLES,
USER_ID,
};
30 changes: 26 additions & 4 deletions packages/manager/modules/at-internet-configuration/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import '@ovh-ux/ng-at-internet-ui-router-plugin';
import { Environment } from '@ovh-ux/manager-config';

import provider from './provider';
import { CUSTOM_VARIABLES } from './config.constants';
import { CUSTOM_VARIABLES, USER_ID } from './config.constants';

const moduleName = 'ovhManagerAtInternetConfiguration';

const trackingEnabled = __NODE_ENV__ === 'production';

angular
.module(moduleName, [
'ngAtInternet',
Expand All @@ -24,8 +26,6 @@ angular
atInternetProvider,
atInternetUiRouterPluginProvider,
) => {
const trackingEnabled = __NODE_ENV__ === 'production';

atInternetProvider.setEnabled(trackingEnabled);
atInternetProvider.setDebug(!trackingEnabled);

Expand All @@ -42,10 +42,32 @@ angular
});
},
)
.run(
/* @ngInject */ ($cookies, atInternet) => {
const cookie = $cookies.get(USER_ID);
const tag = atInternet.getTag();
if (trackingEnabled) {
if (cookie) {
tag.clientSideUserId.set(cookie);
} else {
const value = tag.clientSideUserId.get();
tag.clientSideUserId.store();

const element = document.getElementById('manager-tms-iframe');

if (element) {
element.contentWindow.postMessage({
id: 'ClientUserId',
value,
});
}
}
}
},
)
.run(
/* @ngInject */ ($cookies, $http, atInternet, atInternetConfiguration) => {
const referrerSite = $cookies.get('OrderCloud');

$http.get('/me').then(({ data: me }) => {
atInternet.setDefaults({
...CUSTOM_VARIABLES,
Expand Down

0 comments on commit 7156660

Please sign in to comment.