Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

Commit

Permalink
feat: add posthog
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdilouraoui committed Sep 19, 2023
1 parent 6e5cc97 commit a8ae7d1
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 101 deletions.
17 changes: 9 additions & 8 deletions components/statistic/Statistic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import { FC } from 'react';
import { Page } from '../common/Page';

const statsDocs = [
{ label: 'Nombre de téléchargements', size: 20877 },
{ label: 'Volume total analysé (To)', size: 1293.1 },
{ label: 'Volume total tagué à éliminer (To)', size: 9.1 },
{ label: 'Nombre de téléchargements', size: 20877, date: '' },
{ label: 'Volume total analysé', size: '1293.1 To', date: '' },
{ label: 'Volume total tagué à éliminer', size: '9.1 To', date: '' },
{ label: 'Parcourus en avion', size: '8489 Kms', date: '' },
];

const statsMails = [
{ label: 'Nombre de téléchargements', size: 5614 },
{ label: 'Nombre de pst déposés', size: 513 },
{ label: 'Volume total analysé (en mails)', size: 1373449 },
{ label: 'Volume total tagué à éliminer (en Mo)', size: 12.5 },
{ label: 'Nombre de téléchargements', size: 5614, date: '' },
{ label: 'Nombre de pst déposés', size: 513, date: '' },
{ label: 'Volume total analysé (en mails)', size: 1373449, date: '' },
{ label: 'Volume total tagué à éliminer (en Mo)', size: 12.5, date: '' },
];

type TStat = {
label: string;
size: number;
size: number | string;
};

const Stat: FC<TStat> = ({ size, label }) => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"include-media": "^1.4.10",
"next": "12.1.6",
"next-seo": "^5.4.0",
"posthog-js": "^1.79.0",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-markdown": "^8.0.3",
Expand Down
215 changes: 122 additions & 93 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { PrismicPreview } from '@prismicio/next';
import { PrismicProvider } from '@prismicio/react';
import type { AppProps } from 'next/app';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { DefaultSeo } from 'next-seo';
import posthog from 'posthog-js';
import { PostHogProvider } from 'posthog-js/react';
import { useEffect } from 'react';
import { Footer } from '../components/common/Footer';
import { Header } from '../components/common/Header';
import { Layout } from '../components/common/Layout';
Expand All @@ -11,103 +15,128 @@ import { repositoryName } from '../prismicConfiguration';
import '../styles/index.scss';
import { linkResolver } from '../utils/prismic/helpers';

if (typeof window !== 'undefined') {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY ?? '', {
api_host:
process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://app.posthog.com',
// Enable debug mode in development
loaded: posthog => {
if (process.env.NODE_ENV === 'development') posthog.debug();
},
capture_pageview: false, // Disable automatic pageview capture, as we capture manually
});
}

const App = ({ Component, pageProps }: AppProps) => {
const router = useRouter();

useEffect(() => {
// Track page views
const handleRouteChange = () => posthog?.capture('$pageview');
router.events.on('routeChangeComplete', handleRouteChange);

return () => {
router.events.off('routeChangeComplete', handleRouteChange);
};
}, []);
return (
<PrismicProvider
linkResolver={linkResolver}
internalLinkComponent={({ href, children, ...props }) => (
<Link href={href}>
<a {...props}>{children}</a>
</Link>
)}
>
<PrismicPreview repositoryName={repositoryName}>
<Layout>
<DefaultSeo
canonical="https://archifiltre.fr"
titleTemplate="%s | Suite Archifiltre"
defaultTitle="Suite Archifiltre"
additionalLinkTags={[
{
rel: 'icon',
href: 'https://archifiltre.fr/favicon.ico',
},
{
rel: 'preload',
href: 'https://archifiltre.fr/assets/fonts/Quicksand-Bold.ttf',
as: 'font',
type: 'font/ttf',
crossOrigin: 'anonymous',
},
{
rel: 'preload',
href: 'https://archifiltre.fr/assets/fonts/Quicksand-Light.ttf',
as: 'font',
type: 'font/ttf',
crossOrigin: 'anonymous',
},
{
rel: 'preload',
href: 'https://archifiltre.fr/assets/fonts/Quicksand-Medium.ttf',
as: 'font',
type: 'font/ttf',
crossOrigin: 'anonymous',
},
{
rel: 'preload',
href: 'https://archifiltre.fr/assets/fonts/Inter-Bold.ttf',
as: 'font',
type: 'font/ttf',
crossOrigin: 'anonymous',
},
{
rel: 'preload',
href: 'https://archifiltre.fr/assets/fonts/Inter-Light.ttf',
as: 'font',
type: 'font/ttf',
crossOrigin: 'anonymous',
},
{
rel: 'preload',
href: 'https://archifiltre.fr/assets/fonts/Inter-Medium.ttf',
as: 'font',
type: 'font/ttf',
crossOrigin: 'anonymous',
},
]}
openGraph={{
title: 'Suite Archifitre',
type: 'website',
locale: 'fr_FR',
url: 'https://archifiltre.fr',
site_name: 'Archifiltre',
description:
'Aider les archivistes et les agents des administrations à appréhender et trier des arborescences de fichiers et des messageries complètes.',
images: [
<PostHogProvider>
<PrismicProvider
linkResolver={linkResolver}
internalLinkComponent={({ href, children, ...props }) => (
<Link href={href}>
<a {...props}>{children}</a>
</Link>
)}
>
<PrismicPreview repositoryName={repositoryName}>
<Layout>
<DefaultSeo
canonical="https://archifiltre.fr"
titleTemplate="%s | Suite Archifiltre"
defaultTitle="Suite Archifiltre"
additionalLinkTags={[
{
rel: 'icon',
href: 'https://archifiltre.fr/favicon.ico',
},
{
rel: 'preload',
href: 'https://archifiltre.fr/assets/fonts/Quicksand-Bold.ttf',
as: 'font',
type: 'font/ttf',
crossOrigin: 'anonymous',
},
{
rel: 'preload',
href: 'https://archifiltre.fr/assets/fonts/Quicksand-Light.ttf',
as: 'font',
type: 'font/ttf',
crossOrigin: 'anonymous',
},
{
rel: 'preload',
href: 'https://archifiltre.fr/assets/fonts/Quicksand-Medium.ttf',
as: 'font',
type: 'font/ttf',
crossOrigin: 'anonymous',
},
{
rel: 'preload',
href: 'https://archifiltre.fr/assets/fonts/Inter-Bold.ttf',
as: 'font',
type: 'font/ttf',
crossOrigin: 'anonymous',
},
{
rel: 'preload',
href: 'https://archifiltre.fr/assets/fonts/Inter-Light.ttf',
as: 'font',
type: 'font/ttf',
crossOrigin: 'anonymous',
},
{
url: 'https://archifiltre.fr/assets/team_logo.png',
secureUrl:
'https://archifiltre.fr/assets/team_logo.png',
alt: 'Team Logo',
height: 1024,
width: 1024,
rel: 'preload',
href: 'https://archifiltre.fr/assets/fonts/Inter-Medium.ttf',
as: 'font',
type: 'font/ttf',
crossOrigin: 'anonymous',
},
],
}}
twitter={{
handle: '@archifiltre',
site: '@archifiltre',
cardType: 'summary_large_image',
}}
/>
<Header />
<Main>
<Component {...pageProps} />
</Main>
<Footer />
</Layout>
</PrismicPreview>
</PrismicProvider>
]}
openGraph={{
title: 'Suite Archifitre',
type: 'website',
locale: 'fr_FR',
url: 'https://archifiltre.fr',
site_name: 'Archifiltre',
description:
'Aider les archivistes et les agents des administrations à appréhender et trier des arborescences de fichiers et des messageries complètes.',
images: [
{
url: 'https://archifiltre.fr/assets/team_logo.png',
secureUrl:
'https://archifiltre.fr/assets/team_logo.png',
alt: 'Team Logo',
height: 1024,
width: 1024,
},
],
}}
twitter={{
handle: '@archifiltre',
site: '@archifiltre',
cardType: 'summary_large_image',
}}
/>
<Header />
<Main>
<Component {...pageProps} />
</Main>
<Footer />
</Layout>
</PrismicPreview>
</PrismicProvider>
</PostHogProvider>
);
};

Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3983,6 +3983,11 @@ fd-slicer@~1.1.0:
dependencies:
pend "~1.2.0"

fflate@^0.4.1:
version "0.4.8"
resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.4.8.tgz#f90b82aefbd8ac174213abb338bd7ef848f0f5ae"
integrity sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==

file-entry-cache@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027"
Expand Down Expand Up @@ -6697,6 +6702,13 @@ postcss@^8.3.11, postcss@^8.4.14, postcss@^8.4.19:
picocolors "^1.0.0"
source-map-js "^1.0.2"

posthog-js@^1.79.0:
version "1.79.0"
resolved "https://registry.yarnpkg.com/posthog-js/-/posthog-js-1.79.0.tgz#3575c72f521ad10db4f29ac5280de877ac82e64a"
integrity sha512-NgIGAXPkbmvKYcyOTkaNJYPTLvrXQqhWztkJ/v5NkF5CFdZucorc9OOPmZbGk+SLtHfK/8ilNyz6ql6JjBkkbQ==
dependencies:
fflate "^0.4.1"

prebuild-install@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/prebuild-install/-/prebuild-install-7.1.1.tgz#de97d5b34a70a0c81334fd24641f2a1702352e45"
Expand Down

0 comments on commit a8ae7d1

Please sign in to comment.