Skip to content

Commit

Permalink
Mise à jour du trackeur
Browse files Browse the repository at this point in the history
  • Loading branch information
mariheck committed May 14, 2024
1 parent 0940a16 commit 63924de
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/site/app/TrackPage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use client';

import {usePathname} from 'next/navigation';
import {TrackPageView} from '@tet/ui';
import {TrackUnplannedPageView} from '@tet/ui';

const TrackPage = () => {
const pathName = usePathname();

return (
<TrackPageView
<TrackUnplannedPageView
pageName={`site${pathName === '/' ? '/accueil' : pathName}`}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/components/tracking/TrackPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function isRelativeToCollectivite(object: unknown): object is {
type TrackPageViewProps<N extends PageName> = {
pageName: N;
} & (TrackingPlan[N]['properties'] extends object
? {properties?: TrackingPlan[N]['properties']}
? {properties: TrackingPlan[N]['properties']}
: {properties?: undefined});

/**
Expand Down
21 changes: 21 additions & 0 deletions packages/ui/src/components/tracking/TrackUnplannedPageView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {useEffect} from 'react';
import {usePostHog} from 'posthog-js/react';

type Props = {
pageName: string;
};

export const TrackUnplannedPageView = ({pageName}: Props) => {
const posthog = usePostHog();

useEffect(() => {
if (posthog) {
// Envoie la pageview à PostHog
posthog.capture('$pageview', {
$current_url: pageName,
});
}
}, [posthog, pageName]);

return null;
};
1 change: 1 addition & 0 deletions packages/ui/src/components/tracking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export * from './trackingPlan';
export * from './useEventTracker';
export * from './useOngletTracker';
export * from './TrackPageView';
export * from './TrackUnplannedPageView';
export * from './TrackingProvider';
export * from './Consent';

0 comments on commit 63924de

Please sign in to comment.