0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

refactor(console): add prefix to pv path (#5933)

This commit is contained in:
Gao Sun 2024-05-29 19:46:40 +08:00 committed by GitHub
parent d7c8130f14
commit c5099a3578
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 6 deletions

View file

@ -14,8 +14,8 @@ function ConsoleContent() {
const { scrollableContent } = useOutletContext<AppContentOutletContext>(); const { scrollableContent } = useOutletContext<AppContentOutletContext>();
const routeObjects = useConsoleRoutes(); const routeObjects = useConsoleRoutes();
const routes = useRoutes(routeObjects); const routes = useRoutes(routeObjects);
usePlausiblePageview(routeObjects);
usePlausiblePageview(routeObjects, ':tenantId');
// Use this hook here to make sure console listens to user tenant scope changes. // Use this hook here to make sure console listens to user tenant scope changes.
useTenantScopeListener(); useTenantScopeListener();

View file

@ -8,7 +8,13 @@ import { getRoutePattern } from '@/utils/route';
const log = debug('usePlausiblePageview'); const log = debug('usePlausiblePageview');
export const usePlausiblePageview = (routes: RouteObject[]) => { /**
* Track pageview with Plausible by listening to route changes.
*
* @param routes An array of route objects to match the current route against.
* @param prefix A prefix to prepend to the route pattern.
*/
export const usePlausiblePageview = (routes: RouteObject[], prefix: string) => {
const { pathname } = useLocation(); const { pathname } = useLocation();
useEffect(() => { useEffect(() => {
@ -19,8 +25,8 @@ export const usePlausiblePageview = (routes: RouteObject[]) => {
// https://plausible.io/docs/custom-locations#3-specify-a-custom-location // https://plausible.io/docs/custom-locations#3-specify-a-custom-location
window.plausible?.('pageview', { window.plausible?.('pageview', {
u: u:
appendPath(new URL('https://' + plausibleDataDomain), routePattern).href + appendPath(new URL('https://' + plausibleDataDomain), prefix, routePattern).href +
window.location.search, window.location.search,
}); });
}, [pathname, routes]); }, [pathname, prefix, routes]);
}; };

View file

@ -43,7 +43,7 @@ export function OnboardingApp() {
const matched = useMatch(welcomePathname); const matched = useMatch(welcomePathname);
const routes = useRoutes(routeObjects); const routes = useRoutes(routeObjects);
usePlausiblePageview(routeObjects); usePlausiblePageview(routeObjects, 'onboarding');
useEffect(() => { useEffect(() => {
setThemeOverride(Theme.Light); setThemeOverride(Theme.Light);

View file

@ -34,7 +34,7 @@ function Profile() {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { navigate } = useTenantPathname(); const { navigate } = useTenantPathname();
const childrenRoutes = useRoutes(profile); const childrenRoutes = useRoutes(profile);
usePlausiblePageview(profile); usePlausiblePageview(profile, 'profile');
const api = useStaticApi({ prefixUrl: adminTenantEndpoint, resourceIndicator: meApi.indicator }); const api = useStaticApi({ prefixUrl: adminTenantEndpoint, resourceIndicator: meApi.indicator });
const fetcher = useSwrFetcher<ConnectorResponse[]>(api); const fetcher = useSwrFetcher<ConnectorResponse[]>(api);