-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tracking): add tracking page in generator
ref: MANAGER-13929 Signed-off-by: Alex Boungnaseng <alex.boungnaseng.ext@corp.ovh.com>
- Loading branch information
1 parent
3560422
commit 0205739
Showing
8 changed files
with
355 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
packages/manager/core/generator/app/templates/src/components/GuideLink/useCustomTracking.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React, { useContext } from 'react'; | ||
import { useMatches } from 'react-router-dom'; | ||
import { ShellContext } from '@ovh-ux/manager-react-shell-client'; | ||
|
||
import { PAGE_PREFIX, UNIVERSE, LEVEL2 } from '@/tracking.constant'; | ||
|
||
export enum PageType { | ||
onboarding = 'onboarding', | ||
listing = 'listing', | ||
dashboard = 'dashboard', | ||
popup = 'pop-up', | ||
bannerSuccess = 'banner-success', | ||
bannerError = 'banner-error', | ||
bannerInfo = 'banner-info', | ||
bannerWarning = 'banner-warning', | ||
funnel = 'funnel', | ||
} | ||
|
||
export enum PageLocation { | ||
page = 'page', | ||
funnel = 'funnel', | ||
banner = 'banner', | ||
popup = 'pop-up', | ||
datagrid = 'datagrid', | ||
tile = 'tile', | ||
} | ||
|
||
export enum ButtonType { | ||
button = 'button', | ||
link = 'link', | ||
select = 'select', | ||
externalLink = 'external-link', | ||
tile = 'tile', | ||
tutorial = 'tile-tutorial', | ||
tab = 'go-to-tab', | ||
} | ||
|
||
export type TrackingClickParams = { | ||
location?: PageLocation; | ||
buttonType?: ButtonType; | ||
actions?: string; | ||
actionType?: 'action' | 'navigation' | 'download' | 'exit'; | ||
}; | ||
|
||
export const usePageTracking = () => { | ||
const matches = useMatches(); | ||
const { handle } = matches[matches.length - 1]; | ||
return (handle as any)?.tracking as TrackingPageParams; | ||
}; | ||
|
||
export type TrackingPageParams = { | ||
pageType?: PageType; | ||
pageName?: string; | ||
}; | ||
|
||
export const useOvhCustomTracking = () => { | ||
const match: any = useMatches().slice(-1)[0]; | ||
const { shell } = useContext(ShellContext); | ||
|
||
const defaultParams = { | ||
page_category: match.handle?.OvhTracking.type, | ||
level2: LEVEL2, | ||
site_level2: LEVEL2, | ||
page_theme: UNIVERSE, | ||
}; | ||
|
||
return { | ||
trackPage: (params: TrackingPageParams = {}) => { | ||
shell.tracking.trackPage({ | ||
...params, | ||
...defaultParams, | ||
name: `${PAGE_PREFIX}::${match?.id}`, | ||
}); | ||
}, | ||
trackClick: (params: TrackingClickParams = {}) => { | ||
const { location, buttonType, actions, actionType } = params; | ||
shell.tracking.trackClick({ | ||
...defaultParams, | ||
name: [PAGE_PREFIX, location, buttonType, actions].join('::'), | ||
type: actionType, | ||
page: [PAGE_PREFIX, match?.id].join('::'), | ||
chapter1: UNIVERSE, | ||
}); | ||
}, | ||
}; | ||
}; |
50 changes: 50 additions & 0 deletions
50
packages/manager/core/generator/app/templates/src/pages/layout.tsx.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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 { | ||
useOvhCustomTracking, | ||
ButtonType, | ||
PageLocation, | ||
} from '@/hooks/useCustomTracking'; | ||
|
||
export default function Layout() { | ||
const location = useLocation(); | ||
const routing = useRouting(); | ||
const { shell } = useContext(ShellContext); | ||
const matches = useMatches(); | ||
const { trackClick } = useOvhCustomTracking(); | ||
|
||
useEffect(() => { | ||
const match = matches.slice(-1); | ||
defineCurrentPage(`app.{{appName}}-${match[0]?.id}`); | ||
}, [location]); | ||
|
||
useEffect(() => { | ||
trackPage(); | ||
}, [location]); | ||
|
||
useEffect(() => { | ||
const match = matches.slice(-1); | ||
trackPage({ | ||
name: `${PAGE_PREFIX}::${match[0]?.id}`, | ||
level2: LEVEL2, | ||
}); | ||
}, [location]); | ||
|
||
useEffect(() => { | ||
shell.ux.hidePreloader(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
routing.stopListenForHashChange(); | ||
}, []); | ||
|
||
useEffect(() => { | ||
routing.onHashChange(); | ||
}, [location]); | ||
|
||
return <Outlet />; | ||
} |
122 changes: 122 additions & 0 deletions
122
packages/manager/core/generator/app/templates/src/routes.tsx.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import React from 'react'; | ||
import { RouteObject } from 'react-router-dom'; | ||
import NotFound from './pages/404'; | ||
import { PageType } from './hooks/useCustomTracking'; | ||
|
||
const lazyRouteConfig = (importFn: CallableFunction): Partial<RouteObject> => { | ||
return { | ||
lazy: async () => { | ||
const { default: moduleDefault, ...moduleExports } = await importFn(); | ||
return { | ||
Component: moduleDefault, | ||
...moduleExports, | ||
}; | ||
} | ||
}; | ||
}; | ||
|
||
{{#if this.isPCI }} | ||
export const Routes: any = [ | ||
{ | ||
path: '/pci/projects/:projectId/{{this.pciName}}', | ||
...lazyRouteConfig(() => import('@/pages/layout')), | ||
children: [ | ||
{ | ||
id: 'listing', | ||
path: '', | ||
...lazyRouteConfig(() => import('@/pages/listing')), | ||
}, | ||
{ | ||
path: ':serviceName', | ||
...lazyRouteConfig(() => import('@/pages/dashboard/_layout')), | ||
children: [ | ||
{ | ||
id: 'dashboard', | ||
path: '', | ||
...lazyRouteConfig(() => import('@/pages/dashboard/index')), | ||
}, | ||
{ | ||
id: 'tab2', | ||
path: 'Tab2', | ||
...lazyRouteConfig(() => import('@/pages/dashboard/Tab2')), | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'onboarding', | ||
path: 'onboarding', | ||
...lazyRouteConfig(() => import('@/pages/onboarding')), | ||
}, | ||
], | ||
}, | ||
{ | ||
path: '*', | ||
element: <NotFound />, | ||
}, | ||
]; | ||
{{else}} | ||
export const Routes: any = [ | ||
{ | ||
path: '/', | ||
...lazyRouteConfig(() => import('@/pages/layout')), | ||
children: [ | ||
{ | ||
id: 'listing', | ||
path: '', | ||
...lazyRouteConfig(() => import('@/pages/listing')), | ||
handle: { | ||
OvhTracking: { | ||
name: 'listing', | ||
type: PageType.listing, | ||
}, | ||
}, | ||
}, | ||
{ | ||
path: ':serviceName', | ||
...lazyRouteConfig(() => import('@/pages/dashboard/_layout')), | ||
children: [ | ||
{ | ||
id: 'dashboard', | ||
path: '', | ||
...lazyRouteConfig( | ||
() => import('@/pages/dashboard/index')), | ||
handle: { | ||
OvhTracking: { | ||
name: 'dashboard', | ||
type: PageType.dashboard, | ||
}, | ||
}, | ||
}, | ||
{ | ||
id: 'dashboard.tab2', | ||
path: 'Tab2', | ||
...lazyRouteConfig( | ||
() => import('@/pages/dashboard/Tab2')), | ||
handle: { | ||
OvhTracking: { | ||
name: 'tab2', | ||
type: PageType.dashboard, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
id: 'onboarding', | ||
path: 'onboarding', | ||
...lazyRouteConfig(() => import('@/pages/onboarding')), | ||
handle: { | ||
OvhTracking: { | ||
name: 'tab2', | ||
type: PageType.onboarding, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
{ | ||
path: '*', | ||
element: <NotFound />, | ||
}, | ||
]; | ||
{{/if}} |
5 changes: 5 additions & 0 deletions
5
packages/manager/core/generator/app/templates/src/tracking.constant.ts.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const LEVEL2 = '86'; | ||
export const UNIVERSE = '{{universe}}'; | ||
export const SUBUNIVERSE = '{{subuniverse}}'; | ||
export const APP_NAME = '{{appName}}' | ||
export const PAGE_PREFIX = [UNIVERSE, SUBUNIVERSE, APP_NAME].join('::'); |
Oops, something went wrong.