Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit f9c6134

Browse files
committed
fix: stats
1 parent 168a48c commit f9c6134

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ ENV GITHUB_SHA $GITHUB_SHA
2626
WORKDIR /app
2727
COPY --from=deps /app/node_modules ./node_modules
2828
COPY . .
29-
RUN yarn build:export
29+
RUN if [ -z "$PRODUCTION" ]; then \
30+
echo "Overriding .env for staging"; \
31+
cp .env.staging .env.production; \
32+
fi && \
33+
yarn build:export
3034

3135
# Production image, copy all the files and run next
3236
FROM ghcr.io/socialgouv/docker/nginx:6.70.1 AS runner

src/lib/matomo.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export type MatomoResult = {
44
nbVisits: number;
55
};
66

7-
export const fetchMatomoData = async (): Promise<Partial<MatomoResult>> => {
7+
export const fetchMatomoData = async (): Promise<MatomoResult> => {
88
const MATOMO_URL = [
99
`${process.env.NEXT_PUBLIC_MATOMO_URL}/?module=API&method=VisitsSummary.getVisits&idSite=${process.env.NEXT_PUBLIC_MATOMO_SITE_ID}&format=JSON&period=year&date=today`,
1010
`${process.env.NEXT_PUBLIC_MATOMO_URL}/?module=API&method=Actions.get&idSite=${process.env.NEXT_PUBLIC_MATOMO_SITE_ID}&format=JSON&period=year&date=today`,
@@ -18,8 +18,8 @@ export const fetchMatomoData = async (): Promise<Partial<MatomoResult>> => {
1818
);
1919
const [nbVisitData, infoData] = await Promise.all(promises);
2020
return {
21-
nbPageViews: infoData?.nb_pageviews,
22-
nbUniqPageViews: infoData?.nb_uniq_pageviews,
23-
nbVisits: nbVisitData?.value,
21+
nbPageViews: infoData?.nb_pageviews ?? 0,
22+
nbUniqPageViews: infoData?.nb_uniq_pageviews ?? 0,
23+
nbVisits: nbVisitData?.value ?? 0,
2424
};
2525
};

src/pages/stats.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { NextSeo } from "next-seo";
55
import React, { useEffect } from "react";
66

77
const Index: NextPage = () => {
8-
const [matomoData, setMatomoData] = React.useState<MatomoResult>();
8+
const [matomoData, setMatomoData] = React.useState<MatomoResult>({
9+
nbPageViews: 0,
10+
nbVisits: 0,
11+
nbUniqPageViews: 0,
12+
});
913

1014
useEffect(() => {
1115
(async () => {
@@ -30,17 +34,17 @@ const Index: NextPage = () => {
3034
<div className="fr-grid-row fr-grid-row--gutters fr-grid-row--center fr-px-3w">
3135
<StatsTile
3236
title="Nombre de visites"
33-
stats={matomoData?.nbVisits ?? 0}
37+
stats={matomoData.nbVisits}
3438
description="C'est le nombre de visites total du site sur les 12 derniers mois"
3539
/>
3640
<StatsTile
3741
title="Nombre de pages vues (total)"
38-
stats={matomoData?.nbPageViews ?? 0}
42+
stats={matomoData.nbPageViews}
3943
description="C'est le nombre de pages vues au total sur le site sur les 12 derniers mois"
4044
/>
4145
<StatsTile
4246
title="Nombre de pages vues (uniques)"
43-
stats={matomoData?.nbUniqPageViews ?? 0}
47+
stats={matomoData.nbUniqPageViews}
4448
description="C'est le nombre de pages vues uniques sur le site sur les 12 derniers mois"
4549
/>
4650
</div>

0 commit comments

Comments
 (0)