feat: plugin analytics avec custom field kirbyup + Chart.js
Refactoring complet du plugin analytics : remplacement de la section avec template Vue inline par un custom field compilé avec kirbyup. Dashboard avec KPIs, line chart Chart.js et filtres par date. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7371e66ec1
commit
8a73da920f
15 changed files with 873 additions and 0 deletions
54
src/stores/analytics.js
Normal file
54
src/stores/analytics.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { defineStore } from 'pinia';
|
||||
import { ref } from 'vue';
|
||||
|
||||
export const useAnalyticsStore = defineStore('analytics', () => {
|
||||
const sessionId = ref(null);
|
||||
|
||||
function initSession() {
|
||||
// Récupérer sessionId depuis sessionStorage ou en créer un nouveau
|
||||
const storedSessionId = sessionStorage.getItem('analyticsSessionId');
|
||||
|
||||
if (storedSessionId) {
|
||||
sessionId.value = storedSessionId;
|
||||
} else {
|
||||
sessionId.value = generateSessionId();
|
||||
sessionStorage.setItem('analyticsSessionId', sessionId.value);
|
||||
}
|
||||
}
|
||||
|
||||
function generateSessionId() {
|
||||
return `session_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
||||
}
|
||||
|
||||
async function trackVisit(pageUrl, pageType, pageName = null) {
|
||||
if (!sessionId.value) {
|
||||
initSession();
|
||||
}
|
||||
|
||||
const data = {
|
||||
sessionId: sessionId.value,
|
||||
pageUrl,
|
||||
pageType,
|
||||
pageName,
|
||||
};
|
||||
|
||||
try {
|
||||
await fetch('/track-visit.json', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
} catch (error) {
|
||||
// Tracking silencieux : ne pas bloquer l'app si ça échoue
|
||||
console.debug('Analytics tracking failed:', error);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
sessionId,
|
||||
initSession,
|
||||
trackVisit,
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue