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

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

Merged
merged 1 commit into from
May 29, 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/console/src/containers/ConsoleContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function ConsoleContent() {
const { scrollableContent } = useOutletContext<AppContentOutletContext>();
const routeObjects = useConsoleRoutes();
const routes = useRoutes(routeObjects);
usePlausiblePageview(routeObjects);

usePlausiblePageview(routeObjects, ':tenantId');
// Use this hook here to make sure console listens to user tenant scope changes.
useTenantScopeListener();

Expand Down
12 changes: 9 additions & 3 deletions packages/console/src/hooks/use-plausible-pageview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import { getRoutePattern } from '@/utils/route';

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();

useEffect(() => {
Expand All @@ -19,8 +25,8 @@ export const usePlausiblePageview = (routes: RouteObject[]) => {
// https://plausible.io/docs/custom-locations#3-specify-a-custom-location
window.plausible?.('pageview', {
u:
appendPath(new URL('https://' + plausibleDataDomain), routePattern).href +
appendPath(new URL('https://' + plausibleDataDomain), prefix, routePattern).href +
window.location.search,
});
}, [pathname, routes]);
}, [pathname, prefix, routes]);
};
2 changes: 1 addition & 1 deletion packages/console/src/onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function OnboardingApp() {
const matched = useMatch(welcomePathname);
const routes = useRoutes(routeObjects);

usePlausiblePageview(routeObjects);
usePlausiblePageview(routeObjects, 'onboarding');

useEffect(() => {
setThemeOverride(Theme.Light);
Expand Down
2 changes: 1 addition & 1 deletion packages/console/src/pages/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Profile() {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { navigate } = useTenantPathname();
const childrenRoutes = useRoutes(profile);
usePlausiblePageview(profile);
usePlausiblePageview(profile, 'profile');

const api = useStaticApi({ prefixUrl: adminTenantEndpoint, resourceIndicator: meApi.indicator });
const fetcher = useSwrFetcher<ConnectorResponse[]>(api);
Expand Down
Loading