-
Notifications
You must be signed in to change notification settings - Fork 96
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
c74eca9
commit c9f2e21
Showing
8 changed files
with
230 additions
and
5 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/hooks/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, | ||
}); | ||
}, | ||
}; | ||
}; |
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
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('::'); |
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,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', | ||
]; |