diff --git a/packages/manager/modules/at-internet-configuration/src/config.constants.js b/packages/manager/modules/at-internet-configuration/src/config.constants.js index e76e8d703fb7..b40cc4c4b241 100644 --- a/packages/manager/modules/at-internet-configuration/src/config.constants.js +++ b/packages/manager/modules/at-internet-configuration/src/config.constants.js @@ -2,6 +2,9 @@ export const CUSTOM_VARIABLES = { siteName: 'Manager', }; +export const USER_ID = 'clientSideUserId'; + export default { CUSTOM_VARIABLES, + USER_ID, }; diff --git a/packages/manager/modules/at-internet-configuration/src/index.js b/packages/manager/modules/at-internet-configuration/src/index.js index df5a6ca3f172..e0e1346ae1e0 100644 --- a/packages/manager/modules/at-internet-configuration/src/index.js +++ b/packages/manager/modules/at-internet-configuration/src/index.js @@ -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', @@ -24,8 +26,6 @@ angular atInternetProvider, atInternetUiRouterPluginProvider, ) => { - const trackingEnabled = __NODE_ENV__ === 'production'; - atInternetProvider.setEnabled(trackingEnabled); atInternetProvider.setDebug(!trackingEnabled); @@ -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,