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

Commit

Permalink
fix: stats
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgfr committed Mar 11, 2022
1 parent 168a48c commit f9c6134
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ ENV GITHUB_SHA $GITHUB_SHA
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN yarn build:export
RUN if [ -z "$PRODUCTION" ]; then \
echo "Overriding .env for staging"; \
cp .env.staging .env.production; \
fi && \
yarn build:export

# Production image, copy all the files and run next
FROM ghcr.io/socialgouv/docker/nginx:6.70.1 AS runner
Expand Down
8 changes: 4 additions & 4 deletions src/lib/matomo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export type MatomoResult = {
nbVisits: number;
};

export const fetchMatomoData = async (): Promise<Partial<MatomoResult>> => {
export const fetchMatomoData = async (): Promise<MatomoResult> => {
const MATOMO_URL = [
`${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`,
`${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`,
Expand All @@ -18,8 +18,8 @@ export const fetchMatomoData = async (): Promise<Partial<MatomoResult>> => {
);
const [nbVisitData, infoData] = await Promise.all(promises);
return {
nbPageViews: infoData?.nb_pageviews,
nbUniqPageViews: infoData?.nb_uniq_pageviews,
nbVisits: nbVisitData?.value,
nbPageViews: infoData?.nb_pageviews ?? 0,
nbUniqPageViews: infoData?.nb_uniq_pageviews ?? 0,
nbVisits: nbVisitData?.value ?? 0,
};
};
12 changes: 8 additions & 4 deletions src/pages/stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { NextSeo } from "next-seo";
import React, { useEffect } from "react";

const Index: NextPage = () => {
const [matomoData, setMatomoData] = React.useState<MatomoResult>();
const [matomoData, setMatomoData] = React.useState<MatomoResult>({
nbPageViews: 0,
nbVisits: 0,
nbUniqPageViews: 0,
});

useEffect(() => {
(async () => {
Expand All @@ -30,17 +34,17 @@ const Index: NextPage = () => {
<div className="fr-grid-row fr-grid-row--gutters fr-grid-row--center fr-px-3w">
<StatsTile
title="Nombre de visites"
stats={matomoData?.nbVisits ?? 0}
stats={matomoData.nbVisits}
description="C'est le nombre de visites total du site sur les 12 derniers mois"
/>
<StatsTile
title="Nombre de pages vues (total)"
stats={matomoData?.nbPageViews ?? 0}
stats={matomoData.nbPageViews}
description="C'est le nombre de pages vues au total sur le site sur les 12 derniers mois"
/>
<StatsTile
title="Nombre de pages vues (uniques)"
stats={matomoData?.nbUniqPageViews ?? 0}
stats={matomoData.nbUniqPageViews}
description="C'est le nombre de pages vues uniques sur le site sur les 12 derniers mois"
/>
</div>
Expand Down

0 comments on commit f9c6134

Please sign in to comment.