mirror of
https://github.com/arthur-pbty/flint.git
synced 2026-08-01 20:29:03 +02:00
feat: ajouter la prise en charge de Matomo dans le Dockerfile et docker-compose.yml
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
co-authored by
Copilot
parent
19568822fe
commit
a7b78c1660
@@ -15,7 +15,11 @@ FROM node:20-alpine AS builder
|
|||||||
WORKDIR /workspace
|
WORKDIR /workspace
|
||||||
|
|
||||||
ARG NEXT_PUBLIC_API_BASE_URL=http://localhost:4000
|
ARG NEXT_PUBLIC_API_BASE_URL=http://localhost:4000
|
||||||
|
ARG NEXT_PUBLIC_MATOMO_URL
|
||||||
|
ARG NEXT_PUBLIC_MATOMO_SITE_ID
|
||||||
ENV NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL}
|
ENV NEXT_PUBLIC_API_BASE_URL=${NEXT_PUBLIC_API_BASE_URL}
|
||||||
|
ENV NEXT_PUBLIC_MATOMO_URL=${NEXT_PUBLIC_MATOMO_URL}
|
||||||
|
ENV NEXT_PUBLIC_MATOMO_SITE_ID=${NEXT_PUBLIC_MATOMO_SITE_ID}
|
||||||
|
|
||||||
COPY --from=deps /workspace/node_modules ./node_modules
|
COPY --from=deps /workspace/node_modules ./node_modules
|
||||||
COPY package.json package-lock.json tsconfig.base.json ./
|
COPY package.json package-lock.json tsconfig.base.json ./
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect } from 'react';
|
import Script from 'next/script';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Matomo Analytics Script Component
|
* Matomo Analytics Script Component
|
||||||
@@ -11,40 +11,33 @@ import { useEffect } from 'react';
|
|||||||
* - NEXT_PUBLIC_MATOMO_SITE_ID: Site ID in Matomo (e.g., 9)
|
* - NEXT_PUBLIC_MATOMO_SITE_ID: Site ID in Matomo (e.g., 9)
|
||||||
*/
|
*/
|
||||||
export function MatomoScript() {
|
export function MatomoScript() {
|
||||||
useEffect(() => {
|
// Check if Matomo is properly configured
|
||||||
// Check if Matomo is properly configured
|
const matomoUrl = process.env.NEXT_PUBLIC_MATOMO_URL?.trim();
|
||||||
const matomoUrl = process.env.NEXT_PUBLIC_MATOMO_URL?.trim();
|
const matomoSiteId = process.env.NEXT_PUBLIC_MATOMO_SITE_ID?.trim();
|
||||||
const matomoSiteId = process.env.NEXT_PUBLIC_MATOMO_SITE_ID?.trim();
|
|
||||||
|
|
||||||
// Skip if not configured
|
// Skip if not configured
|
||||||
if (!matomoUrl || !matomoSiteId) {
|
if (!matomoUrl || !matomoSiteId) {
|
||||||
if (process.env.NODE_ENV === 'development') {
|
return null;
|
||||||
console.debug('[Matomo] Not configured. Skipping analytics.');
|
}
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize Matomo tracking array
|
// Inline script that will be executed immediately
|
||||||
(window as any)._paq = (window as any)._paq || [];
|
const matomoCode = `
|
||||||
const _paq = (window as any)._paq;
|
var _paq = window._paq = window._paq || [];
|
||||||
|
|
||||||
// Set up tracking
|
|
||||||
_paq.push(['trackPageView']);
|
_paq.push(['trackPageView']);
|
||||||
_paq.push(['enableLinkTracking']);
|
_paq.push(['enableLinkTracking']);
|
||||||
_paq.push(['setTrackerUrl', `${matomoUrl}matomo.php`]);
|
_paq.push(['setTrackerUrl', '${matomoUrl}matomo.php']);
|
||||||
_paq.push(['setSiteId', matomoSiteId]);
|
_paq.push(['setSiteId', '${matomoSiteId}']);
|
||||||
|
(function() {
|
||||||
|
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
||||||
|
g.async=true; g.src='${matomoUrl}matomo.js'; s.parentNode.insertBefore(g,s);
|
||||||
|
})();
|
||||||
|
`;
|
||||||
|
|
||||||
// Inject the Matomo script
|
return (
|
||||||
const script = document.createElement('script');
|
<Script
|
||||||
script.async = true;
|
id="matomo-analytics"
|
||||||
script.src = `${matomoUrl}matomo.js`;
|
strategy="beforeInteractive"
|
||||||
script.defer = true;
|
dangerouslySetInnerHTML={{ __html: matomoCode }}
|
||||||
|
/>
|
||||||
const firstScript = document.getElementsByTagName('script')[0];
|
);
|
||||||
if (firstScript && firstScript.parentNode) {
|
|
||||||
firstScript.parentNode.insertBefore(script, firstScript);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,12 +127,16 @@ services:
|
|||||||
dockerfile: apps/web/Dockerfile
|
dockerfile: apps/web/Dockerfile
|
||||||
args:
|
args:
|
||||||
NEXT_PUBLIC_API_BASE_URL: ${NEXT_PUBLIC_API_BASE_URL}
|
NEXT_PUBLIC_API_BASE_URL: ${NEXT_PUBLIC_API_BASE_URL}
|
||||||
|
NEXT_PUBLIC_MATOMO_URL: ${NEXT_PUBLIC_MATOMO_URL}
|
||||||
|
NEXT_PUBLIC_MATOMO_SITE_ID: ${NEXT_PUBLIC_MATOMO_SITE_ID}
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
environment:
|
environment:
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
PORT: 3000
|
PORT: 3000
|
||||||
NEXT_PUBLIC_API_BASE_URL: ${NEXT_PUBLIC_API_BASE_URL}
|
NEXT_PUBLIC_API_BASE_URL: ${NEXT_PUBLIC_API_BASE_URL}
|
||||||
|
NEXT_PUBLIC_MATOMO_URL: ${NEXT_PUBLIC_MATOMO_URL}
|
||||||
|
NEXT_PUBLIC_MATOMO_SITE_ID: ${NEXT_PUBLIC_MATOMO_SITE_ID}
|
||||||
API_BASE_URL: http://api:4000
|
API_BASE_URL: http://api:4000
|
||||||
depends_on:
|
depends_on:
|
||||||
api:
|
api:
|
||||||
|
|||||||
Reference in New Issue
Block a user