```
✨ feat(SitePerformance): Ajoute la collecte des métriques web vitales. 🐛 fix(caddy): Corrige la redirection du script Trustpilot. 📦 chore: Ajoute web-vitals comme dépendance et adapte package.json. ```
This commit is contained in:
@@ -2,6 +2,7 @@ import './reserve.scss';
|
||||
import { UtmEvent, UtmAccount } from "./tools/UtmEvent.js";
|
||||
import { CookieBanner } from "./tools/CookieBanner.js";
|
||||
import * as Turbo from "@hotwired/turbo";
|
||||
import {onLCP, onINP, onCLS} from 'web-vitals';
|
||||
|
||||
// --- DÉTECTION BOT / PERFORMANCE ---
|
||||
const isLighthouse = () => {
|
||||
@@ -53,7 +54,6 @@ const initImageLoader = () => {
|
||||
const images = mainContainer.querySelectorAll('img:not(.loaded)');
|
||||
|
||||
|
||||
console.log(images);
|
||||
images.forEach(img => {
|
||||
// Sécurité : si l'image est déjà chargée (cache), on marque et on skip
|
||||
if (img.complete) {
|
||||
@@ -195,8 +195,33 @@ const initRegisterLogic = () => {
|
||||
updateSiretVisibility();
|
||||
};
|
||||
|
||||
const sendToAnalytics = ({ name, delta, id }) => {
|
||||
// On ne veut pas polluer les stats avec les tests Lighthouse
|
||||
if (isLighthouse()) return;
|
||||
|
||||
const body = JSON.stringify({
|
||||
name, // 'LCP', 'INP', ou 'CLS'
|
||||
value: delta, // La valeur de la mesure
|
||||
id, // ID unique de la session de page (pour éviter les doublons)
|
||||
path: window.location.pathname // Pour savoir quelle page est lente
|
||||
});
|
||||
|
||||
const url = '/reservation/web-vitals';
|
||||
|
||||
// sendBeacon est idéal pour les stats car il ne bloque pas le thread principal
|
||||
if (navigator.sendBeacon) {
|
||||
navigator.sendBeacon(url, body);
|
||||
} else {
|
||||
fetch(url, { body, method: 'POST', keepalive: true });
|
||||
}
|
||||
};
|
||||
|
||||
// --- INITIALISATION GLOBALE ---
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
onLCP(sendToAnalytics);
|
||||
onINP(sendToAnalytics);
|
||||
onCLS(sendToAnalytics);
|
||||
initLoader();
|
||||
initImageLoader();
|
||||
// Enregistrement Custom Elements
|
||||
|
||||
Reference in New Issue
Block a user