Skip to content

Commit

Permalink
feat(tracking): add tracking page in generator
Browse files Browse the repository at this point in the history
ref: MANAGER-13929

Signed-off-by: Alex Boungnaseng <alex.boungnaseng.ext@corp.ovh.com>
  • Loading branch information
aboungnaseng-ovhcloud committed Apr 11, 2024
1 parent 7aee2a6 commit 3d2c3ce
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 4 deletions.
36 changes: 36 additions & 0 deletions packages/components/ovh-at-internet/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,40 @@ export const AT_INTERNET_LEVEL2: Record<string, string> = {
98: 'Manager-HostedPrivateCloud',
};

const UNIVERSES = [
'Dedicated',
'Focus',
'Manager',
'Web',
'Server',
'Hub',
'Creation',
'BareMetalCloud',
'HostedPrivatedCloud',
'PublicCloud',
'WebCloud',
'Telecom',
'Sunrise',
'Account-creation',
];

const SUBUNIVERSES = [
'Dedicated',
'Focus',
'Manager',
'Web',
'Server',
'Hub',
'Creation',
'BareMetalCloud',
'HostedPrivatedCloud',
'PublicCloud',
'WebCloud',
'Telecom',
'Sunrise',
'Account-creation',
];

export const AT_INTERNET_WEBSITE: Record<string, string> = {
ASIA: 'Asia',
AU: 'Australia',
Expand Down Expand Up @@ -62,6 +96,8 @@ export const PCI_PROJECT_MODE_VALUES: Record<string, string> = {
};

export default {
UNIVERSES,
SUBUNIVERSES,
AT_INTERNET_CUSTOM_PROPS,
AT_INTERNET_LEVEL2,
AT_INTERNET_WEBSITE,
Expand Down
5 changes: 4 additions & 1 deletion packages/components/ovh-at-internet/src/ovh-at-internet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { capitalize, isString, mapValues } from 'lodash-es';
import { capitalize, isString, mapValues, trimEnd } from 'lodash-es';
import { OvhAtInternetConfig } from './config';
import {
IOvhAtInternetTrack,
Expand All @@ -16,6 +16,7 @@ import { loadManagerTMS } from './manager-tms';
import { debug } from './utils';

import initMixCommander from './mix-commander';
import { toBeRequired } from '@testing-library/jest-dom/matchers';

function getPageTrackingData(
page: LegacyTrackingData,
Expand Down Expand Up @@ -107,6 +108,7 @@ export default class OvhAtInternet extends OvhAtInternetConfig {
}

canTrack(): boolean {
return true;
return this.isDefaultSet() && this.enabled && this.tag;
}

Expand All @@ -124,6 +126,7 @@ export default class OvhAtInternet extends OvhAtInternetConfig {
}

shouldUsePianoAnalytics() {
return true;
if (isTrackingDebug()) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/apps/container/src/core/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function setupDevApplication(shell: Shell) {
// if the application configuration doesn't exist in DEV mode
// then it's a new application, create a default configuration to use
if (!containerApp) {
let devConfig = {
const devConfig = {
universe: 'hub',
url: `https://www.ovh.com/manager/${devApp}/`,
publicURL: `https://www.ovh.com/manager/#/${devApp}/`,
Expand Down
21 changes: 20 additions & 1 deletion packages/manager/core/generator/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
createTranslations,
createApiQueryFilesActions,
} from '../utils/create-structure-helpers.js';
import { UNIVERSES, SUBUNIVERSES } from './universes.constant.js';

const appDirectory = dirname(fileURLToPath(import.meta.url));

Expand Down Expand Up @@ -64,6 +65,24 @@ export default (plop) => {
plop.setGenerator('app', {
description: 'Create a React app',
prompts: [
{
type: 'list',
name: 'universe',
message: 'What is the universe of the app ?',
choices: UNIVERSES.map((element) => ({
name: element,
value: element,
})),
},
{
type: 'list',
name: 'subuniverse',
message: 'What is the subuniverse of the app ?',
choices: SUBUNIVERSES.map((element) => ({
name: element,
value: element,
})),
},
{
type: 'input',
name: 'appName',
Expand Down Expand Up @@ -190,7 +209,7 @@ export default (plop) => {
{
type: 'input',
name: 'serviceKey',
message: 'What is the service key ?',
message: 'What is the service key in listing page ?',
when: (data) => {
// Add variables for templates
data.hasListing = data.templates.includes('listing');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@ import { Outlet, useLocation, useMatches } from 'react-router-dom';
import { useRouting } from '@ovh-ux/manager-react-shell-client';
import { ShellContext } from '@ovh-ux/manager-react-shell-client';

import { PAGE_PREFIX, LEVEL2 } from '@/tracking.constant';

export default function Layout() {
const location = useLocation();
const routing = useRouting();
const { shell } = useContext(ShellContext);
const matches = useMatches();
const { trackPage } = shell.tracking;

useEffect(() => {
const match = matches.slice(-1);
defineCurrentPage(`app.{{appName}}-${match[0]?.id}`);
}, [location]);

useEffect(() => {
const match = matches.slice(-1);
trackPage({
name: `${PAGE_PREFIX}::${match[0]?.id}`,
level2: LEVEL2,
});
}, [location]);

useEffect(() => {
shell.ux.hidePreloader();
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const Routes: any = [
...lazyRouteConfig(() => import('@/pages/dashboard/index')),
},
{
id: 'dashboard.tab2',
id: 'tab2',
path: 'Tab2',
...lazyRouteConfig(() => import('@/pages/dashboard/Tab2')),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const LEVEL2 = '86';
export const chapter1 = '{{universe}}';
export const chapter2 = '{{subuniverse}}';
export const chapter3 = '{{appName}}'
export const PAGE_PREFIX = [chapter1, chapter2, chapter3].join('::');
32 changes: 32 additions & 0 deletions packages/manager/core/generator/app/universes.constant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export const UNIVERSES = [
'Dedicated',
'Focus',
'Manager',
'Web',
'Server',
'Hub',
'Creation',
'BareMetalCloud',
'HostedPrivatedCloud',
'PublicCloud',
'WebCloud',
'Telecom',
'Sunrise',
'Account-creation',
];
export const SUBUNIVERSES = [
'Dedicated',
'Focus',
'Manager',
'Web',
'Server',
'Hub',
'Creation',
'BareMetalCloud',
'HostedPrivatedCloud',
'PublicCloud',
'WebCloud',
'Telecom',
'Sunrise',
'Account-creation',
];

0 comments on commit 3d2c3ce

Please sign in to comment.