Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tracking): implement tracking in uapp #11432

Merged
merged 1 commit into from
May 8, 2024
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
2 changes: 1 addition & 1 deletion packages/components/ovh-shell/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export { default as plugin } from './plugin';
export { default as Shell } from './shell/shell';
export { initShell } from './shell';
export { DirectClientMessageBus, IFrameMessageBus };

export * from './plugin/tracking/tracking';
export * from './plugin/ux/components/modal';
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type RegionsTrackingConfig = {

export interface TrackingConfig {
config: {
level1: string;
level1?: string;
level2: string;
level3?: string;
level4?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,10 @@ export default function DashboardPage() {
title: serviceName,
};

const linkProps = {
label: t('manager_dashboard_back_link'),
href: '/',
target: OdsHTMLAnchorElementTarget._blank,
type: LinkType.back,
};

const onClickReturn = (href: string) => navigate(href);

return (
<div>
<DashboardLayout
header={header}
{{#if this.isPCI}}
{{else}}
linkProps={linkProps}
onClickReturn={() => onClickReturn(linkProps.href)}
{{/if}}
tabs={
<OsdsTabs panel={panel}>
<OsdsTabBar slot="top">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { Card, OnboardingLayout } from "@ovhcloud/manager-components";
import { useGuideUtils } from '@/hooks/useGuideUtils';
import useGuideUtils from '@/hooks/useGuideUtils';
import Breadcrumb from '@/components/Breadcrumb/Breadcrumb';
import onboardingImgSrc from "./onboarding-img.png";

Expand Down
30 changes: 29 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, SUB_UNIVERSES, LEVEL2 } from './universes.constant.js';

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

Expand Down Expand Up @@ -190,7 +191,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 All @@ -201,6 +202,33 @@ export default (plop) => {
},
validate: (input) => input.length > 0,
},
{
type: 'list',
name: 'level2',
message: 'What is the level2 of the app ? (tracking)',
choices: Object.keys(LEVEL2).map((element) => ({
name: `${element} - ${LEVEL2[element]}`,
value: element,
})),
},
aboungnaseng-ovhcloud marked this conversation as resolved.
Show resolved Hide resolved
{
type: 'list',
name: 'universe',
message: 'What is the universe of the app ? (tracking)',
choices: UNIVERSES.map((element) => ({
name: element,
value: element,
})),
},
{
type: 'list',
name: 'subuniverse',
message: 'What is the subuniverse of the app ? (tracking)',
choices: SUB_UNIVERSES.map((element) => ({
name: element,
value: element,
})),
},
],
actions: ({
apiV6Endpoints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ import '@ovhcloud/ods-theme-blue-jeans/dist/index.css';
import './global.css';
import './vite-hmr';

import { UNIVERSE, SUB_UNIVERSE, APP_NAME, LEVEL2 } from './tracking.constant';

const trackingContext = {
chapter1: UNIVERSE,
chapter2: SUB_UNIVERSE,
chapter3: APP_NAME,
appName: APP_NAME,
pageTheme: UNIVERSE,
chipp972 marked this conversation as resolved.
Show resolved Hide resolved
level2Config: LEVEL2,
};

const init = async (appName: string) => {
const context = await initShellContext(appName);
const context = await initShellContext(appName, trackingContext);

await initI18n({
context,
Expand All @@ -21,6 +32,7 @@ const init = async (appName: string) => {
});

const region = context.environment.getRegion();
context.shell.tracking.setConfig(region, LEVEL2);
try {
await import(`./config-${region}.js`);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import React, { useEffect, useContext } from 'react';
import { defineCurrentPage } from '@ovh-ux/request-tagger';
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 {
useOvhTracking,
useRouteSynchro,
ShellContext,
} from '@ovh-ux/manager-react-shell-client';

export default function Layout() {
const location = useLocation();
const routing = useRouting();
const { shell } = useContext(ShellContext);
const matches = useMatches();
const { trackCurrentPage } = useOvhTracking();
useRouteSynchro();

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

useEffect(() => {
shell.ux.hidePreloader();
}, []);
trackCurrentPage();
}, [location]);

useEffect(() => {
routing.stopListenForHashChange();
shell.ux.hidePreloader();
}, []);

useEffect(() => {
routing.onHashChange();
}, [location]);

return <Outlet />;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { RouteObject } from 'react-router-dom';
import NotFound from './pages/404';
import { PageType } from '@ovh-ux/manager-react-shell-client';

const lazyRouteConfig = (importFn: CallableFunction): Partial<RouteObject> => {
return {
Expand All @@ -24,6 +25,12 @@ export const Routes: any = [
id: 'listing',
path: '',
...lazyRouteConfig(() => import('@/pages/listing')),
handle: {
tracking: {
pageName: 'listing',
pageType: PageType.listing,
},
},
},
{
path: ':serviceName',
Expand All @@ -33,18 +40,36 @@ export const Routes: any = [
id: 'dashboard',
path: '',
...lazyRouteConfig(() => import('@/pages/dashboard/index')),
handle: {
tracking: {
pageName: 'dashboard',
pageType: PageType.dashboard,
},
},
},
{
id: 'dashboard.tab2',
id: 'tab2',
path: 'Tab2',
...lazyRouteConfig(() => import('@/pages/dashboard/Tab2')),
handle: {
tracking: {
pageName: 'tab2',
pageType: PageType.dashboard,
},
},
},
],
},
{
id: 'onboarding',
path: 'onboarding',
...lazyRouteConfig(() => import('@/pages/onboarding')),
handle: {
tracking: {
pageName: 'onboarding',
pageType: PageType.onboarding,
},
},
},
],
},
Expand All @@ -63,6 +88,12 @@ export const Routes: any = [
id: 'listing',
path: '',
...lazyRouteConfig(() => import('@/pages/listing')),
handle: {
tracking: {
pageName: 'listing',
pageType: PageType.listing,
},
},
},
{
path: ':serviceName',
Expand All @@ -72,20 +103,38 @@ export const Routes: any = [
id: 'dashboard',
path: '',
...lazyRouteConfig(
() => import('@/pages/dashboard/index'))
() => import('@/pages/dashboard/index')),
handle: {
tracking: {
pageName: 'dashboard',
pageType: PageType.dashboard,
},
},
},
{
id: 'dashboard.tab2',
path: 'Tab2',
...lazyRouteConfig(
() => import('@/pages/dashboard/Tab2'))
() => import('@/pages/dashboard/Tab2')),
handle: {
tracking: {
pageName: 'tab2',
pageType: PageType.dashboard,
},
},
},
],
},
{
id: 'onboarding',
path: 'onboarding',
...lazyRouteConfig(() => import('@/pages/onboarding')),
handle: {
tracking: {
pageName: 'onboarding',
pageType: PageType.onboarding,
},
},
},
],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const LEVEL2 = {
EU: {
config: {
level2: '{{level2}}',
},
},
CA: {
config: {
level2: '{{level2}}',
},
},
US: {
config: {
level2: '{{level2}}',
},
},
};
export const UNIVERSE = '{{universe}}';
export const SUB_UNIVERSE = '{{subuniverse}}';
chipp972 marked this conversation as resolved.
Show resolved Hide resolved
export const APP_NAME = '{{appName}}'
46 changes: 46 additions & 0 deletions packages/manager/core/generator/app/universes.constant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
export const UNIVERSES = [
'Dedicated',
'Focus',
'Manager',
'Web',
'Server',
'Hub',
'Creation',
'Baremetal',
'HostedPrivatedCloud',
'PublicCloud',
'WebCloud',
'Telecom',
'Sunrise',
'Account-creation',
];
export const SUB_UNIVERSES = [
'Dedicated',
'Focus',
'Manager',
'Web',
'Server',
'Hub',
'Creation',
'Network',
'HostedPrivatedCloud',
'PublicCloud',
'WebCloud',
'Telecom',
'Sunrise',
'Account-creation',
];
export const LEVEL2 = {
0: '',
56: 'ManagerCloud',
57: 'ManagerDedicated',
67: 'Focus',
81: 'Manager',
84: 'ManagerWeb',
85: 'ManagerServer',
86: 'ManagerPublicCloud',
87: 'ManagerTelecom',
88: 'ManagerHub',
95: 'account-creation',
98: 'ManagerHostedPrivateCloud',
};
3 changes: 2 additions & 1 deletion packages/manager/core/shell-client/src/ShellContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Environment } from '@ovh-ux/manager-config';
import { ShellClientApi } from '@ovh-ux/shell';
import { ShellClientApi, RegionsTrackingConfig } from '@ovh-ux/shell';
import { createContext } from 'react';

export type TrackingContextParams = {
Expand All @@ -9,6 +9,7 @@ export type TrackingContextParams = {
pageTheme?: string;
level2?: string;
appName?: string;
level2Config?: RegionsTrackingConfig;
};

export type ShellContextType = {
Expand Down
Loading
Loading